473,386 Members | 1,699 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

socket programming

hi!

on my client side, i have a socket that sends and then receives
the code is
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((PDA_ADDRESS, PDA_PORT))
s.send("persona=")
s.send(persona)
s.send("\n")
str = s.recv(1024)
data=""
while len(str) != 0:
data += str
str = s.recv(1024)
print data

on my server side i create the serversocket, listen, get the client socket
and the client socket receives the data as follows
(clientsocket, address) = serversocket.accept()
str = clientsocket.recv(256)
data=""
while len(str) != 0:
data += str
str = clientsocket.recv(256)

the problem is when my client finished sending and waits to receive, on the
server side, it still stays in the while loop waiting to receive more data.

how do i stop that?

thanks


----------------------------------------------------------------
This message was sent using IMP, the Internet Messaging Program.
Jul 18 '05 #1
3 1961
Ajay:
the problem is when my client finished sending and waits to receive, on the
server side, it still stays in the while loop waiting to receive more data.

how do i stop that?


You need to define a protocol for the communication between client and
server, and implement the server in such a way that it sends what it's
expected to send, when it has received what it expected to receive. In
your current code, the server is expecting an infinite amount of data,
while the client is sending only a few bytes.

--
René Pijlman
Jul 18 '05 #2
Rene Pijlman wrote:
You need to define a protocol for the communication between client and
server, and implement the server in such a way that it sends what it's
expected to send, when it has received what it expected to receive. In
your current code, the server is expecting an infinite amount of data,
while the client is sending only a few bytes.


You could define a special char that indicated the end of the transmission.
Jul 18 '05 #3
Ajay wrote:
[...]
the code is
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) [...] the problem is when my client finished sending and waits to receive, on the
server side, it still stays in the while loop waiting to receive more data.


SOCK_STREAM sockets have no concept record-boundary. If you
need to convey the end of one message, but keep the connection
open, then you need to define or find a protocol that builds
distinct messages on top of the byte stream.

If the client is truly done sending on that socket, it can call
s.shutdown(1). Then, after the server has received all the sent
data, (the socket will select as readable and) the server's next
recv will return, but the size of the read will be zero bytes.

Remote shutdown of sending is the only case in which recv will
succeed with a zero size. If remote side has not shut down, and
there is no data available, a recv on a blocking sockets will
block, and non-blocking sockets will raise/return EWOULDBLOCK.
--
--Bryan
Jul 18 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: pyguy2 | last post by:
Issues of socket programming can be wierd, so I'm looking for some comments. In my python books I find exclusive use of socket.close(). From my other readings, I know about a "partial close...
5
by: John Sheppard | last post by:
Hi all, I am not sure that I am posting this in the right group but here it goes anyway. I am new to socket programming and I have been searching on the internet to the questions I am about to pose...
1
by: John Sheppard | last post by:
Thanks to everyone that responded to my previous Socket Programming question. Now I have run into some behavior that I don't quite understand. Programming environment. VS.NET 2003, C#, Windows...
5
by: mscirri | last post by:
The code below is what I am using to asynchronously get data from a PocketPC device. The data comes in fine in blocks of 1024 bytes but even when I send no data from the PocketPC constant blocks of...
2
by: djc | last post by:
I read a network programming book (based on framework 1.1) which indicated that you should 'never' use the RecieveTimeout or the SendTimeout 'socket options' on TCP sockets or you may loose data. I...
10
by: Uma - Chellasoft | last post by:
Hai, I am new to VB.Net programming, directly doing socket programming. In C, I will be able to map the message arrived in a socket directly to a structure. Is this possible in VB.Net. Can...
11
by: atlaste | last post by:
Hi, In an attempt to create a full-blown webcrawler I've found myself writing a wrapper around the Socket class in an attempt to make it completely async, supporting timeouts and some scheduling...
0
by: shonen | last post by:
I'm currently attempting to connect to a shoutcast server pull down the information from here and then I'll parse it. I got this working with the httplib, which was great, the problem is I want...
8
by: =?Utf-8?B?Sm9obg==?= | last post by:
Hi all, I am new to .net technologies. ASP.NET supports socket programming like send/receive in c or c++? I am developing web-site application in asp.net and code behind is Visual C#. In...
3
by: Stuart | last post by:
I am in the process of teaching myself socket programming. I am "playing around" with some simple echo server-client programs for m the book TCP/IP Sockets in C. The Server program is: ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.