This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

TCP call back function and packet sequence numbering

In the RL library TCP callback function, the parameters we have are:

soc - Socket number
evt - Event (enums defined in Keil's rtl.h)
*ptr - Received data frame
par - Received data frame length

What I have realised is that the callback parameters don't provide us with any information on TCP packet sequence numbering. Now, my understanding is that TCP packets aren't guaranteed to be received in order, and I also understand that there is no guarantee of a 1:1 relationship between packets transmitted, and those received. This might happen because, for example, the packet hits a network device with a lower MTU resulting in the packet being split; or perhaps two packets are concatenated at some point.

For this reason, my understanding is that TCP must be considered a stream; and that at my application level protocol, I need to implement a means of identifying - at receiving end - that a complete application protocol packet has been fully received. An obvious way of doing this would be to have a header in my application packet that contains a packet length. At the receive end, I would keep reading data in TCP_EVT_DATA of the callback and rebuild the application packet locally until I have the required message size. I would still have to do this even if I guaranteed that my packets were 'small' enough to fit into a single TCP packet at transmit end, because as stated above it's a stream; there's no way to guarantee a single packet out for every packet shoved in (even though, most of the time, it probably is 1:1).

A further requirement, in order to be very robust, is to also look at the TCP packet sequence numbering to ensure that the application packet is rebuilt without any parts in the wrong order. But as the RL-Library callback doesn't provide this, do I just have to assume that it's unlikely that TCP will not deliver packets in order? To protect against that happening, would I be best using a CRC check on my entire reassembled packet?

Or, does the Keil libary already just deal with this for me, and guarantee packets delivered to the callback in order? I'd have thought that's most unlikely, considering the resource limitations.

Any thoughts are appreciated - even if it's to tell me I'm barking up the wrong tree.

Regards

Trev