Search code examples
javasocketsnetwork-programmingnioserversocket

number of clients queued by server and if a client is queued or not


How to check if a client is backlogged by server ? and check how many clients are backlogged?

i have a server with SocketServer initialized and i have a client trying to connect. the server side code would be

  ServerSocket sock = new ServerSocket(9000,1);
  Socket so=sock.accept();

and the client side will be

  Socket soc = new Socket("localhost",9000);

Solution

  • How to check if a client is backlogged by server?

    With a Selector.

    and check how many clients are backlogged?

    With Selector.selectedKeySet().size().

    This assumes you are only selecting for OP_ACCEPT of course.