问题
What happens to client Sockets when I close a ServerSocket? Will all connections made with serverSocket.accept() be closed as well?
回答1:
Closing a ServerSocket
will prevent new connections from being created, but it won't shut down existing connections.
ServerSocket
is the listening socket involved only in creating a connection. The data communication is handled distinctly in the Socket
returned by ServerSocket.accept();
.
来源:https://stackoverflow.com/questions/36979335/what-happens-on-closing-serversocket