I'm still new to Java and sockets. I have a program which listens to connections and if one comes in, it sends it to a class that handles the connection and uses ExecutorService
to start the processing thread.
I want to limit the number of connections, so I found that a socket has a parameter for that. This is the main code:
public static void main(String[] args) throws IOException {
ServerSocket server = new ServerSocket(123, 1);
try {
ConnectionListener listener = new ConnectionListener(server);
listener.run();
}
catch (Exception exception) {
exception.printStackTrace();
}
}
In this example I wanted to limit the connections to 1. I tried to bombard it with a lot of parallel executions of a python script that sends data to this port. But I never get a "connection refused" or an apparent delay of the connection, as if the limit is not obeyed.
What am I doing wrong?