socket programming

Brian Quinlan BrianQ at ActiveState.com
Wed Mar 21 19:19:27 EST 2001


Hi Kevin,

The bufsize parameter in recv is the maximim size of the buffer that recv
will return, not the minimum. recv will normally return any available data
and will only block if there is none.

I assume that the only way that you can determine if the message has ended
is by detecting that the socket has been closed? You could see if setsockopt
has something to help you or you could try something like this (as usual,
not tested in any way):

message = ''
try:
	message += mysocket.recv( 1024 )
except socket.error, e:
	# e.args could be a string too, might want to check for that
	if e.args[0] != errno.ECONNRESET
		raise e

--
Brian Quinlan
Python and XSLT Developer
BrianQ at ActiveState.com

Use the power of the dragon for your programming needs.
Download Komodo, our Mozilla-based, cross-platform IDE.
      http://www.ActiveState.com/Komodo


-----Original Message-----
From: python-list-admin at python.org
[mailto:python-list-admin at python.org]On Behalf Of Kevin X Lin
Sent: Wednesday, March 21, 2001 2:47 PM
To: python-list at python.org
Subject: socket programming


Hi there, I have the following problem with socket programming:

I'm trying to setup a tcp client to talk to a tcp server sitting at a
certain port. When I issue :

mysocket.setblocking(1)
mysocket.send('something')
mysocket.recv(1024)

I was expecting I can receive all the data sent by server. Unfortunately,
this is not necessary the case. Sometimes I can't get all of data, worse,
the application protocal doesn't define end tag of the data, which prevent
me from doing a loop until I receive all data.

But if I do this:

mysocket.setblocking(1)
mysocket.send('something')
sleep(0.1)
mysocket.recv(1024)

I can get all data, yet I believe this is not a good solution which might
casusing other problems in the future.

Any suggestion?

Thanks.

Kevin




--
http://mail.python.org/mailman/listinfo/python-list





More information about the Python-list mailing list