jerams
jerams

Reputation: 113

how to know which is the last TCP segment received by the server when data is transferring?

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.

Upvotes: 0

Views: 2383

Answers (3)

Yuriy Vasylenko
Yuriy Vasylenko

Reputation: 3151

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.

Upvotes: 2

jdizzle
jdizzle

Reputation: 4154

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

Upvotes: 1

caf
caf

Reputation: 239011

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.

Upvotes: 1

Related Questions