Is anyone aware of a way to do this?

I considered adding a while statement to the listening loop of the server to evaluate if an integer is >= a certain value, and if so to enter another loop until it's not true, and that would allow the server to accept more connections. The server would increment or decrement the integer each time a connection is opened/closed. Seems a little heavy though. Is there a method built into Sockets that can allow me to set a maximum number of connections?

Any suggestions would be greatly appreciated.

5 Years
Discussion Span
Last Post by zachattack05

There is no limit on the number of connections you can accept on a socket (baring memory limitations). I'm not sure what you are trying to accomplish. Do you want to limit the number of connections?



Yes, I do want to limit the number of connections.

It's not for "software" limitation per-se...I'm not going to have X, Y, and Z versions of the software, each with a different connection limit, I hate that. I want to allow my users the ability to control the number of connections permitted to the server. I want to do this for a few reasons:

1. extra (though small) amount of security - Unlimited (or limited by system resources) connections allow for would be trouble makers to connect to the server (or at least try to anyway) hundreds of thousands of times with the intention of slowing down or even "killing" the hosting machine.

2. to allow the server administrators the ability to control resources better - while it may seem silly, some people may not have very good hardware and some "throttling" might be in order, limiting the number of connections could help with that.

3. selling point - control (no matter how small) gives the perception of power. Lets be honest, software that has more things to "tinker" with are great selling points so long as the default values are sufficient for those who don't like to tinker.


1) Limiting connections gives 'bad actors' more power as it's easier to DDS the server by claiming all the connections.

2) You might want to look into async-socket connections. They use little resources and allow more connections than you might otherwise think that a server can handle. There is a hard limit on the number of connections imposed by the OS and I'd assume if they are using older hardware, they are using an older OS which would tend to have lower limits.

3) Of course having more options is a selling point (Now with tint control!).

If you really want to limit the connections, you'll have to count them. Easy way is add/remove them from a List<T>. You can check the number of connections by the Count property, and if you have space, add, otherwise reject with 'server full' (or whatever).

Edited by Momerath: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.