views:

36

answers:

2

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.

+1  A: 

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.

caf
A: 

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).

jdizzle