Client for server doing dispatcher_with_send

Victor Norman vic.norman at marconi.com
Fri Oct 8 09:42:33 EDT 2004


Hi all,

I have a server that uses the asyncore stuff with dispatcher_with_send in
order to send a bunch of pickled bytes to a client.  The length of the
message is generally about 3000 bytes.

My problem is that I don't know how to write the client elegantly.  I'm not
using asyncore or anything for the client -- just the socket module.

Currently, my code is working, but is inelegant, I think.  here it is:

data = ""
newData = ""
while True:
    newData = sock.recv(8192)
    data += newData
    if len(newData) < 512:
        break
sock.close()

This works because the dispatcher_with_send() sends packets with 512 bytes
in them, unless there is less than 512 bytes to send.

Is there a more elegant way to write this?  How can I determine that nothing
more is being sent?

Vic





More information about the Python-list mailing list