views:

1738

answers:

2

I am creating a Windows Service in .NET to which N number of client can connect. The service starts a TCP listener and accepts the client connections. The problem I am facing is that I can only open 10 connections to this service. The listener::AcceptTcpClient() method accepts only 10 connection and throws an exception for 11th one. The client application uses the System.Net.Sockets.TcpClient class and the service is using System.Net.Sockets.TcpListener class.

This is the exception that I am getting when I try to make a number of connections in a for loop to this service (after the 10th connection is made):

"Unable to read data from Transport connection: An exsting connection was forcibly closed by remote host"

+3  A: 

This sounds like you're running into the well-known 10-connection limit of half-open TCP connections on Windows XP. This limit is hard-coded as of XP SP 2, and there is no way to override it short of patching your system, which may technically violate your end-user license agreement (IANAL). XP is, alas, not intended to be a server system.

For Windows XP Professional, the maximum number of other computers that are permitted to simultaneously connect over the network is ten. This limit includes all transports and resource sharing protocols combined. For Windows XP Home Edition, the maximum number of other computers that are permitted to simultaneously connect over the network is five. This limit is the number of simultaneous sessions from other computers the system is permitted to host. This limit does not apply to the use of administrative tools that attach from a remote computer.

John Feminella
What if I use a server operating system such as Windows Server 2003?
A9S6
The limit shouldn't be present on a server operating system. Server operating systems are designed to (and should) accept many connections.
John Feminella
But I am getting the same error when I run my service on Windows Server 2003 and try connecting to it.
A9S6
@Abhimanyu: if the client is on XP, then it will have the outbound limit applied, even if the server can accept more connections.
Richard
This limit only applies to certain MS application protocols that use TCP (mail, shares, etc). This is not a general limit to TCP connections at the socket level. Perhaps the .NET TcpClient class also applies this limit...a reason to use a different set of libraries? I know this is not the case as I often test with non-.NET programs under XP and now Windows 7 Home/Ultimate where the limit is 20 but my server and client apps have been able to make 100's of connections to/from the same host.
Kevin Brock
@Richard: why would there be a limit on outbound connections? XP is a client OS so should be allowed to make as many socket connections to a server as needed. Now, MS did create a limit for half-open TCP connections which is also limited to 10 (they apparently have stopped this policy in Vista SP2 and later http://www.windowsbbs.com/general-discussions/84686-half-open-outbound-tcp-connections-limit-removed-windows-7-vista-sp2.html) but that is different than limiting established connections. Perhaps then the server in the OP was not completing accept on the connections quickly enough.
Kevin Brock
@Kevin: There is nothing in the question to indicate the server is not on XP (or other client). But it appears I did misstate my comment (should have said "if the *server* is...").
Richard
A: 

I don't think the answer that was given before is valid. I did some research and there doesn't appear to be a reason that TcpClient has any strict limit imposed. The other answer suggested a limit of 10 active TCP connections in Windows XP for a server service, but this is only true for specific application protocols (such as sharing, mail) provided by Microsoft.

I did find though that Microsoft added some restrictions in XP SP2 and continued through Vista SP1 to limit half-open TCP connections to 10. They also limited the number of new connections to 10 within a single second. These were both attempts to reduce the impact of virus software. Apparently these have not been very successful so Microsoft has finally decided to remove these in Vista SP2 and later.

This may have been the OP's actual issue - perhaps you are trying to create those connections too quickly in the client?

As I mentioned in my comments on the previously accepted answer, I personally write client/server software and have not had problems with a limit of 10. When I do tests, using Windows XP in the past and now with Windows 7 (the application limit is now at 20 connections), I am able to easily exceed this limit. I just retested and was able to create >140 active/established connections between one host (Windows 7 Home Premium) and another host (Windows 7 Enterprise); both client operating systems. This is using Java but there really should be no difference with .NET (which I've also tested in the past).

Kevin Brock