Search This Blog

Friday, May 24, 2013

Sucessfull Java Socket Send with Broken Connection


With Java sockets it's possible that the socket write method is successful even if the network is down.

When Java issues socket write   the request is passed forward to the Windows socket send function. The documentation of send says that
The successful completion of a send function does not indicate that the data was successfully delivered and received to the recipient. This function only indicates the data was successfully sent
and an older version also says
If data for which the peer protocol has buffer space cannot be successfully transmitted within a reasonable length of time, the connection is considered broken and subsequent calls will fail with the error code set to WSAETIMEDOUT.
For some operating systems  "successfully delivered" just means that the data was passed into a buffer in the network stack, which will handle the transfer.

TCP connection is open unless it's closed or terminated:
  • application calls socket close
  • application crashes and OS closes the socket
  • OS closes the socket due to an event (e.g restart)

So if the network becomes disconnected the connection remains open if there's no data sent; there's no way to detect network hiccups just by listening to incoming connections.

TCP usually provides keep-alive messages to detect network failures.

References:




No comments:

Post a Comment