On Wed, 16 Jan 2008 11:16:25 -0800, Greg <gc*****@gmail.comwrote:
I'm creating a tcp socket connection from the thread in the c#
threadpool. Since the default workers thread is 500, sometimes my
program tries to open up 500 different tcp socket connections and the
connection fails after it reaches certain number of opened tcp
connection. I guess it reached the max number of tcp connection
available in the operating system. I have Professional Windows XP
2000. So what is the max simultaneous tcp connection in this
operating system? Or how can I find out the how many tcp connections
are available?
I may be wrong, but I wasn't aware of any arbitrary maximum number of
connections possible, even on a non-server version of Windows.
Your message _seems_ to be saying that you are using a thread pool thread
to create each connection. If by that you mean that each connection has
its own thread pool thread, then it seems likely to me that you're
actually running out of threads, not connections.
If you want to host a large number of multiple connections, you need to
avoid a "one thread per connection" implementation. That technique will
always unnecessarily limit the number of connections you can have at once,
and performance will suffer even before you reach that limit.
Instead, look at the asynchronous API on the Socket class (or TcpClient
and Stream if that's what you're using), where you call methods with
"Begin" and "End" as part of the names. For example,
Socket.BeginConnect() and Socket.BeginRead(). These methods provide a
much more scalable and efficient way of managing multiple connections with
the same parallelism that multiple threads would give you, but without the
limitations. (In fact they do use threads themselves, but in a much more
efficient way than dedicating one to each connection).
If I've misunderstood your architecture, then you should probably post a
concise-but-complete example of code that illustrates what you _are_
doing. It's too easy to misunderstand a human language description of an
implementation, but code is code. :)
Pete