0

How many socket's connections a server could hold? I explain: I'm programming a simple chat system in java, and i create everytime a client connect to the server, a socket and a ServerClient object that know the socket of the specific client, like this:

Socket socket= socketServer.accept();
clients.add(new Client(socket));

when the client disconnect to the server i delete the object. I'm thinking if i have one milion client connected to the server in this moment it's a problem, there's other way to do this or it's the correct way? Thanks for the help

liuk997
  • 29
  • 3
  • 7
  • Don't forget to search for the answer. [The answer is here](http://stackoverflow.com/questions/12981957/java-serversocket-connection-limit) – DontPanic Mar 18 '17 at 15:45
  • @DontPanic i wonder why 50 is set as limit? – Shadab Faiz Mar 18 '17 at 16:51
  • @Shadab Faiz I can't find the answer for this question. Note that it's set to 50 only if public ServerSocket(int port) constructor used. If you use for example public ServerSocket(int port, int backlog) constructor, the limit will be set to backlog. So may be 50 is some middle value. – DontPanic Mar 18 '17 at 17:24
  • @DontPanic: I thought the backlog was the number of *unserviced* connection requests, not the number of connections simultaneously active. My reading of the java docs is that once the `accept()` method succeeds that space in the queue is freed up. – President James K. Polk Mar 18 '17 at 17:31
  • @James K Polk: I read again the doc and you're right. It is the maximum queue length for incoming connection indications (a request to connect) is set to the backlog parameter. If a connection indication arrives when the queue is full, the connection is refused. So when ServerSocket(int port) constructor used the maximum connection queue is 50 – DontPanic Mar 18 '17 at 17:37

1 Answers1

1

I think it entirely depends on your system configuration(i.e. RAM, CPU etc). According to this and also, this is what I found related.

As you are implementing chat you will need to implement full-duplex communication. You can use your server memory to temporarily store messages and handle other clients during this time.

Community
  • 1
  • 1
Avinash L
  • 167
  • 2
  • 15