Java ServerSocket prevent clients queueing

105 Views Asked by At

I am making a sockets program in java, I want to only be able to handle 1 client at a time. I also want to stop a client from from connecting to the socket if another client connected to the server. I know that by default ServerSocket allows for queuing of clients and you can limit the size of the queue by using the

public ServerSocket(int port, int backlog)

constructor. However the Javadoc says that if you set the backlog to 0 it just goes to the default queue length. I can set this to 1 but if i connect 2 clients the second will wait in the queue, and a third will not connect.

Is there anyway to disable this queuing so that a second client that tries to connect simultaneously will be not allowed to connect?

0

There are 0 best solutions below