Search code examples
socketsconnectionlisten

C# Socket.Listen(MAX_CONNECTIONS);


i need some help with socket.listen.

my max_connections is set to 1. but even after a client is connected if another client tries to connect, on the client side it says it has connected although the server does not report anything new.

my app is between one server and one client. and if any other client tries to connect while there is already a connection i want that connect to be refused.

please help with some ideas.

thank you very much.


Solution

  • You didn't supply any code, but the title of your post references Socket.Listen. The parameter given to Socket.Listen is not the maximum number of connections, rather it is the size of the "backlog" of incoming connections.

    What that means is that when someone tries to connect, but your server hasn't Accept()ed the connection yet, those clients are in the "backlog" queue. You've set the size to 1, so only 1 client can be waiting to connect at a time.

    This parameter does not have an effect on the total number of connections allowed to your application.