Twisted Python: Max Packet Size? Flush Socket?
Solution 1:
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.
Solution 2:
TCP is a stream-oriented protocol, not a packet-oriented protocol. When you call transport.write
, that data gets appended to the TCP stream and may be sent out in any number of packets; it might be broken up, or glued together with the next or previous call to write
. This is a fairly frequently asked question about Twisted, but everyone who asks it asks it slightly differently.
You want to use a protocol construction kit like AMP, or, more basically, LineReceiver, to delimit the messages within your protocol, rather than relying upon the random nature of packet boundaries.
Post a Comment for "Twisted Python: Max Packet Size? Flush Socket?"