Client for server doing dispatcher_with_send

Josiah Carlson jcarlson at
Fri Oct 8 19:48:38 CEST 2004

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

Write a better protocol.  A better protocol is easy (it can be done
better, but this is short and will do the job).

 - Josiah

from StringIO import StringIO

class my_dispatcher_with_send(asyncore.dispatcher_with_send):
    def send (self, data):
        asyncore.dispatcher_with_send(struct.pack('>L', len(data))+data)

def read(sock, length):
    s = StringIO()
    while s.tell() < length:
    return s.getvalue()

def receiver(sock):
        l = read(sock, 4)
        l = struct.unpack('>L', l)[0]
        r = read(sock, l)
        return r
    except socket.error, why:

More information about the Python-list mailing list