Working with thousands of connections is not a difficult task if you use only asynchronous APIs. The concept of “one thread per connection” is not only not scaled, but (in the general case of the protocol) is erroneous. Note that asynchronous APIs are different from using ThreadPool .
Asynchronous programming takes a little time to catch, but it is not so difficult. You will have to manually track more states than with synchronous programming.
Make sure protocol classes can handle partial accepts of any size (which requires extra state) and that you have one protocol instance for each connection.
Any socket errors should result in closing the connection and clearing the state.
And a magazine. Everything. TraceSource is your friend; Learn how to use .NET tracing, which you can enable (even during production) by editing app.config.
source share