What to do when ServerSocket throws IOException
Posted
by s5804
on Stack Overflow
See other posts from Stack Overflow
or by s5804
Published on 2010-06-12T11:46:57Z
Indexed on
2010/06/12
11:52 UTC
Read the original article
Hit count: 229
Basically I want to create a rock solid server.
while (keepRunning.get()) {
try {
Socket clientSocket = serverSocket.accept();
... spawn a new thread to handle the client ...
} catch (IOException e) {
e.printStackTrace();
// NOW WHAT?
}
}
In the IOException block, what to do? Is the Server socket at fault so it need to be recreated? For example wait a few seconds and then
serverSocket = ServerSocketFactory.getDefault().createServerSocket(MY_PORT);
However if the server socket is still OK, then it is a pity to close it and kill all previously accepted connections that are still communicating.
© Stack Overflow or respective owner