Reputation: 7277
I'm trying to implement a simple instant messenger server and came up with the following problem:
How can I implement a protocol with a acknowledge packet?
I think it could be implemented like this:
>> client sends packet with ACKID and waits for ACKID to arrive
<< server receives packet and sends the same ACKID back
now the client knows the packet was fully delivered.
But in this concept, the client would block until the ACKID was sent back, and if another packet interrupts this process then the client would block forever (or until timeout occurs).
Upvotes: 0
Views: 142
Reputation: 171246
I assume you are sending data like this at the moment:
Send("mydata");
Now, do this:
Send("mydata");
auto ack = Receive();
assert(ack == "data acknowledged");
(In pseudo-code).
Use a timeout for both operations. Only when the Receive completes without error you know that the data was received.
The same principle can be translated to async IO APIs. This is immaterial to the question.
(Stop talking about "packets" in the context of TCP. TCP does not know what that is.)
Upvotes: 1