charlie
charlie

Reputation: 309

When I use TCP to send data how do I know if data has arrived or not?

When i use TCP to send data, the write() function just ensures data has been copied to the TCP send buffer, but if TCP doesn't send data successfully, how do I know? Is there a signal? or what?

Upvotes: 1

Views: 192

Answers (1)

Martin Cowie
Martin Cowie

Reputation: 2601

Short Answer: you don't. Conventionally the remote TCP peer sends a response, acknowledging your data. This is the 1st step toward building an application level protocol, atop TCP, your transport level protocol.

Longer Answer: This problem is the prime motivation for higher level protocols such as HTTP, STOMP, IMAP, etc.

but if TCP doesn't send data successfully, how do I know?

The write() system call can return -1 and set errno to indicate an error, however you cannot know how much data has been received by the remote peer, and how much was not. That question is best answered by the remote peer.

M.

Upvotes: 2

Related Questions