views:

372

answers:

3

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.

A: 

You can use the IsConnected property on your TCPClient to check if a connection already exists and decide upon that.

Tony
A: 

I propose you to accept new client connection but acquire the semaphor immediately before access to wrapped server and release it immediately after access. This approach allows you to control how many clients are using wrapped server concurrently.

Andrey Shvydky
+2  A: 

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.

SoapBox
ok. that makes sense. i thought i have the wrong idea regarding Listen.once i have made a connection i can just shut the listening socket down and that ought to take care of it, i thinks..
iEisenhower