Shayan
Shayan

Reputation: 2828

When does a Java socket send an ack?

My question is that when a socket at the receiver-side sends an ack? At the time the application read the socket data or when the underlying layers get the data and put it in the buffer?

I want this because I want both side applications know whether the other side took the packet or not.

Upvotes: 1

Views: 9198

Answers (3)

sibidiba
sibidiba

Reputation: 6370

TCP ACKs are meant to acknowledge the TCP packets on the transmission layer not the application layer. Only your application can signal explicitly that it also has processed the data from the buffers.

Upvotes: 4

Thirler
Thirler

Reputation: 20760

TCP/IP (and therefor java sockets) will guarantee that you either successfully send the data OR get an error (exception in the case of java) eventually.

Upvotes: 0

nos
nos

Reputation: 229304

It's up to the operating system TCP stack when this happens, since TCP provides a stream to the application there's no guarenteed 1:1 correlation between the application doing read/writes and the packets sent on the wire and the TCP acks.

If you need to be assured the other side have received/processed your data, you need to build that into your application protocol - e.g. send a reply stating the data was received.

Upvotes: 7

Related Questions