Python / Twisted - TCP packet fragmentation?

In Twisted, when implementing the dataReceived method, it seems that there are no examples that relate to packet fragments. In any other language, this is what you manually apply, so I'm just wondering if this is already done for you in twisted or what? If so, do I need a prefix for my packages with a length header? Or do I need to do this manually? If so, what will it be?

+5
source share
3 answers

In the dataReceived method, you return the data as a string of indefinite length, which means that it can be a complete message in your protocol or it can only be part of the message that some "client" sent to you. You will need to check the data to see if it contains the whole message in your protocol.

I am currently using Twisted in one of my projects to implement the protocol and decided to use a structural module to pack / unpack my data. The protocol that I implement has a fixed header size, so I do not create any messages until I read at least HEADER_SIZE the number of bytes. The total message size is declared in this part of the header data.

, , . , , , /. FIX SOH . , , ( ).

+6

TCP "". TCP - - . , , , . , , , ..

+6

You can also use the LineReceiver protocol.

+2
source

All Articles