views:

255

answers:

5

According to the Sun's documentation on ServerSocket:

The maximum queue length for incoming connection indications (a request to connect) is set to 50. If a connection indication arrives when the queue is full, the connection is refused.

How can I increase the the queue length? It's my server's bottle-neck.

Thank you.

+1  A: 

Use the backlog parameter of the constructor (Javadoc). Keep in mind that you won't be able to increase the queue past the operating system limits, though. This is to prevent SYN attacks - see this article for more information.

danben
+1  A: 

Use the ServerSocket constructor with the backlog parameter.

You may also want to consider using a Thread pool (or really an ExecutorService) to dispatch incoming requests. Depending on how you architect it, this will generally lead to better throughput.

Kevin
A: 

There is another constructor for ServerSocket.

public ServerSocket(int port, int backlog)

where backlog is the connection queue size you want. The max 50 only applied to the default constructor that takes int port

Chris Kannon
A: 

i m facing the same problem as there are thousands of clients(about 5000 hits at a time) and most of the clients face the same problem of connection refuse.

then i used public ServerSocket(int port, int backlog)

but no benefit of it. i m still having the same problem. is there any better way to architect serversocket connection? will threadpooling solve my problem of connection refuse in case there are thousands of clients?

plz reply?

java2485
A: 

To limit the connection refused be sure you process all of the connect requests for each select poll before doing any of the send/receive processing for that poll.

garretty