Search code examples
javasocketsioioexceptionserversocket

I caught an IOException while accepting client connections on server socket.Now what?


What does an IOException indicate when it is thrown from ServerSocket#accept?
What I mean is: if I have a loop accepting connection it will be blocked here:

Socket client = serverSocket.accept();

If I catch an IOException during accept does this mean that I should close the server socket i.e. it is something severe or I e.g. log the exception and go back accepting connections in serverSocket.accept() like nothing happened?I.e. the server socket is full functional.


Solution

  • You can get these from running out of file descriptors. Another possibility is SocketTimeoutException, if you have set a timeout and it expires. Another is that the server socket got closed asynchronously. Only the last of these is necessarily fatal.