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

5
  • Don't forget to search for the answer. The answer is here Commented Mar 18, 2017 at 15:45
  • @DontPanic i wonder why 50 is set as limit? Commented Mar 18, 2017 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. Commented Mar 18, 2017 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. Commented Mar 18, 2017 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 Commented Mar 18, 2017 at 17:37

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.