Search code examples
pythontcptwistedpacketchunking

Twisted Python: Max Packet Size? Flush socket?


I'm implementing a client-server solution based on Twisted for the server side and e.g. and Android phone for the client side. Because the Andoird emulator takes no TCP Packets larger then 1500b (or less?), I need to be able to chunk packets on the server side. Without flushing the socket after each "transport.write", Twisted buffers the outgoing data so the chunking would be useless without somekind of manual or automatic flushing / maxpacketsize function. How do I do this in Twisted? I'm familiar with the "reactor.doSelect(1)" function, but since I'm using the EPoll reactor (for scalability and performance reasons), I cannot use doSelect. Is it possible to change the maxPacketValue for certain connections within Twisted?

Hoping that someone can show me the light...


Solution

  • TCP packets are automatically chunked by the OS, all the application can do is give hints when to flush. Apart from that, an application can just read and write to a stream.

    The OSs of two communicating peers will automatically configure the maximum packet sizes based on the MTU on the links with Path MTU discovery. Make sure you don't block ICMP packets to get that to work.

    Since it is extremely unlikely that a wrong MTU is the problem (and an MTU of 1500 or less is often set anyway), you should re-diagnose your problem, for example with a packet tracer such as wireshark.