Search code examples
javatcpnio

Does SocketChannel.write waits for TCP ACK?


We use java NIO on client side to communicate with a server. What happens in case of TCP retransmission:

will we hang on write operation till we get ACK or will we return immediately?

(I understant that IO is async and we are getting responses asynchronously, but what about ACKs)


Solution

  • It does not wait for the ACK.

    A TCP write is complete from the API's point of view when the data has been completely transferred into the sender's socket send buffer. What happens after that is completely asynchronous to, and undetectable by, the sending application, other than via close() with a positive LINGER timeout in blocking mode.