[Twisted-Python] Packet Fragmentation

Nima Ghanavatian nimag at rogers.com
Wed Oct 8 18:51:57 EDT 2008


I'm using TCP to pass large files back and fourth.  So far I've follow and expanded on the twisted code examples for a simple server/client.  
Everything works fine for me until the packets get large enough that fragmentation kicks in.

>From one side, I'm sending packets like so:

class EchoClient(protocol.Protocol):
    def connectionMade(self):
        data = ""
        while len(data) < 10000:

and on the receiving end:

def dataReceived(self, data):
    print data

I noticed after multiple iterations the data buffer fills up to the total 10000 bytes, but this takes 3 iterations of dataReceived().  Common sense suggests to have a simple "if len(data) == totalPacketSize" to solve my problem, but I have different sized packets coming in all the time, and can't hardcode this part.

I was wondering if there's any way in Twisted/Python to handle packet fragmentation.  Can I access the last fragment flag in the TCP packet somehow? Or is there a total packet size sent with the packet automatically?
If not, what would be the best way to solve this?


-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://twistedmatrix.com/pipermail/twisted-python/attachments/20081008/fde32246/attachment.htm 

More information about the Twisted-Python mailing list