0
votes

When transferring data in TCP, and given all the incoming and outcoming packets, how will one know if the packet received is the last of the data?

TCP packets are fragmented into smaller parts. I'm transferring over the HTTP protocol.

3

3 Answers

1
votes

When the FIN flag is set by one end of the connection, it indicates that that end will not be sending anymore data.

If the connection is not being closed after the last of the data, then there must be an application-layer method of determining it. For HTTP, the rules are reasonably complicated.

0
votes

I'm assuming you're using some sort of socket library. You can tell a TCP connection is finished because a read() on the socket will return 0. This will happen when the other side closes the connection (which it never has to do).

0
votes

You might use PSH flag of TCP protocol. It should be set to 1 in last packet.

To confirm this just start tracing, make HTTP GET and filter session. You will find that last packet for each response on your HTTP GET is marked by this flag.