Search code examples
javasocketsniosocketchannel

Java socketChannel to detect disorderly closed connection


I know that a SocketChannel is "notified" about an orderly closed connection by receiving "-1" after calling read().

But how can it notify me about an disorderly closed connection? (as part of a whole NIO based server, working with selector and non-blocking socketChannels)


Solution

  • A write() will throw IOException: connection reset. Eventually. Due to TCP buffering it won't happen on the first write after the failure.