tags:

views:

345

answers:

3

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.

+3  A: 

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.

nos
But this is java and it should give me a unified view of all operating systems!
Shayan
And it does. It just doesn't expose TCP acks. And neither do the native socket APIs.
nos
But it should tell me when it sends an ack in order to help me preserve Data Integrity.
Shayan
It wouldn't make any difference to Data Integrity because one end cannot tell if an ACK has been *received* by the other end. Besides, what gets notified to the application level is entirely beyond Java's control.
Stephen C
A: 

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.

Thirler
But when sending data finishes? when the other side application read it or when the underlying layers put the data in the applications buffer?
Shayan
+2  A: 

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.

sibidiba