[Twisted-Python] Receiving large packets with TCP

Stefan Näwe naewe.s at atlas.de
Mon Jul 11 07:46:21 EDT 2005

I'm using Twisted (2.0.1) for a TCP-based receiver.
That receiver receives different telegrams sent by another process.
Those telegrams are sent on different ports (i.e. one telegram type
is sent on one port). The sizes of the telegram vary from ~16 bytes
to ~8 kB.

Everything works perfectly. I've really never been *that*

I'm having trouble receiving the whole contents of large telegrams.
For example one telegram is exactly 7452 bytes long but I only get
2920 bytes.
My twisted receiver uses the reactor to setup the different ports
to listen on and creates 'message handler' objects on connect.
Those message handler objects 'dissect' the received telegram and
print some of its contents to STDOUT.

Some parts of my code:

class MyReceiver(Protocol):

    def dataReceived(self, data):
        if __debug__: log.msg("Received %d bytes" % len(data))
            # here the message handler gets created
            m = self.factory.msg[self.port](data)
        except KeyError:
            # can this really happen ??
            log.msg("Unhandled connection from port %d" % self.port)

    def connectionMade(self):
        addr = self.transport.getHost()
        self.proto = addr.type
        self.peer = addr.host
        self.port = addr.port
        log.msg("Connection from %s" % self.transport.getPeer())

My 'main' function simply does 'reactor.listenTCP(port, MyFactory)'

So what do I need to do to get the whole telegram 'in one shot' ?
Do I need to re-assemble the telegrams myself ?

(I hope this Information is enough...Tell me, if not.)


Stefan Naewe                                     ATLAS Elektronik GmbH
                                                         Dept.: NUS T4
phone: +49-(0)421-457-3969                Sebaldsbruecker Heerstr. 235
fax:   +49-(0)421-457-3913                                28305 Bremen

More information about the Twisted-Python mailing list