0

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)

slashms
  • 928
  • 9
  • 26

1 Answers1

1

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

user207421
  • 305,947
  • 44
  • 307
  • 483
  • Thanks @EJP, but that is the only way? what if I only expect to read as a server? – slashms May 04 '17 at 14:10
  • Also, What will happen if after it is disorderly closed I will call socket.close()? will it block because it might wait for the OS tcp connection closure? – slashms May 04 '17 at 14:31
  • 1
    You may or may not get the reset if you only read. `close()` never waits, unless you're in blocking mode and have done silly things to SO_LINGER. – user207421 May 05 '17 at 03:47