We have the declaration
public ServerSocket(int port,
int backlog)
throws IOException
Where backlog is identified as the maximum queue length for incoming
connection. If a connection indication arrives when the queue is full,
the connection is refused.
Lets say backlog is set to 10.
Does this mean ServerSocket will accept no more then 10 clients?
Followed by:
while (serverShouldStillBeRunning) {
Socket sock = clientSocket.accept();
js.new Worker(sock).start();
}
Backlog number will go down only when sock.close(). Is this correct?
Is there a way to know how many open connection a socket is currently handling (in other words, how close it is to the point when it gives up and start rejecting new connections)
backlog represents a queue of connections waiting to be processed.
When you
.accept(), one of those connections has been processed, and is no longer in the queue, so the backlog is reduced by one.