aukxn aukxn - 6 months ago 19
Java Question

If socket created by ServerSocket.accept() is closed but the socket on client side isn't, will ServerSocket.accept() accept it again?

Let say

A
is Server and
B
is Client.
B
create a socket
b
to Server
A
and
ServerSocket.accept()
create a corresponding socket
a
for the client
B
now if
a
is closed by Server
A
but client
B
haven't closed its socket
b
and
ServerSocket.accept()
still running then will
ServerSocket.accept()
create another socket
c
for client B again?

Answer

No

When either the Server A or Client B closes the connection, the connection is closed for the sockets on both. The client will need to initialize a new connection in order for a new socket c to be created. ServerSocket.accept() will only return when the client explicitly requests a new connection.

Comments