vjk
vjk

Reputation: 2293

maximum no of sockets on serversocket

I was looking at the serversocket API and it said maximum no of allowed connections is 50. I tried testing it..

public class ClientSocketTest {

    public static void main(String[] args) throws UnknownHostException, IOException {
        int count = 10000;
        Socket[] clients = new Socket[count];
        for(int i = 0; i < count ; i++)
        {
            clients[i] = new Socket("localhost", 9090);
            System.out.println("connected to server: " + i);
        }


     }
    }

    public class ServerSocketTest {

        public static void main(String args[]) throws IOException
        {
            ServerSocket serverSocket = new ServerSocket(9090);
            int i =1;

        while(true){
            serverSocket.accept();
            System.out.println("Accepted port" + i++);
        }


    }

}

I started of with count value of 50 in the clientsockettest program. I was able to increase it to 10000 and still get the program to run without any errors.

What is the maximum no of connections allowed?

Upvotes: 0

Views: 205

Answers (2)

aex
aex

Reputation: 85

It depends on Operating system and not programming language

Upvotes: 0

user207421
user207421

Reputation: 311055

I was looking at the serversocket API and it said maximum no of allowed connections is 50.

No it didn't. It said the default backlog is 50. Completely different thing.

There is no maximum imposed by Java. There is an operating system limit on file descriptors or socket buffer space (Windows), but you are just as likely to run out of threads or thread stack space as to hit this.

Upvotes: 1

Related Questions