What to do when ServerSocket throws IOException and keeping server running

前端 未结 4 2060
一整个雨季
一整个雨季 2021-02-10 08:21

Basically I want to create a rock solid server.

while (keepRunning.get()) {
    try {
        Socket clientSocket = serverSocket.accept();

        ... spawn a n         


        
4条回答
  •  耶瑟儿~
    2021-02-10 09:09

    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.

    Please note that closing the server socket will NOT close previously accepted connections. As soon as a connection has been accepted it lives a separate, joyful life at a different port.

提交回复
热议问题