2

I have a Server Application written in C# .NET and running on Windows XP SP3.

I am using asynchronous sockets programming for handling around 500 clients.

But I got a problem to entertain more than 15 client connections.

My application got shut down when 1 more client connected after 15 clients; I am not understanding whether the problem is with my OS or is a tcp connection limitation problem in Windows XP.

Please help to solve out this issue, please suggest any solution.

Update:

Here is my piece of code.

public const int MAX_CLIENTS = 200;
public AsyncCallback pfnWorkerCallBack;

private Socket[] m_workerSocket = new Socket[MAX_CLIENTS];
    
// class for worker socket & callback method & data buffer
private SocketPacket[] m_workerSocketPkt = new SocketPacket[MAX_CLIENTS];

// page Load

m_mainSocket = new Socket(AddressFamily.InterNetwork,
                          SocketType.Stream,
                          ProtocolType.Tcp);
IPEndPoint ipLocal = new IPEndPoint(IPAddress.Any, 4321);
// Bind to local IP Address...
m_mainSocket.Bind(ipLocal);
// Start listening...
m_mainSocket.Listen(MAX_CLIENTS);

m_mainSocket.BeginAccept(new AsyncCallback(OnClientConnect), null);

// called when client is connected

public void OnClientConnect(IAsyncResult asyn)
{
    try
    {
        m_clientCount = setclient();

        SocketPacket abc = new SocketPacket();

        m_workerSocketPkt[m_clientCount] = abc; //assigning with SocketPacket class
        m_workerSocketPkt[m_clientCount].m_currentSocket =
                m_mainSocket.EndAccept(asyn);   //transferring connection to other thread
        m_workerSocketPkt[m_clientCount].m_clientCount = m_clientCount;

        m_workerSocketPkt[m_clientCount].templist = abcde; //assigning Amj (list) class
        m_workerSocket[m_clientCount] = m_workerSocketPkt[m_clientCount].m_currentSocket;

        pfnWorkerCallBack = new AsyncCallback(m_workerSocketPkt[m_clientCount].OnDataReceived); //defining AsynCallBack function for the accepted socket

        m_workerSocketPkt[m_clientCount].oldpfnWorkerCallBack = pfnWorkerCallBack;

        m_workerSocketPkt[m_clientCount].data_rec = false;
        m_workerSocketPkt[m_clientCount].data_sent = false;

        m_workerSocketPkt[m_clientCount].m_currentSocket.BeginReceive(
            m_workerSocketPkt[m_clientCount].dataBuffer,        //assigning data buffer for receiving for the socket
            0,                                                  //assigning data buffer offset for receiving for the socket
            m_workerSocketPkt[m_clientCount].dataBuffer.Length, //assigning maximum data length for receiving for the socket
            SocketFlags.None,                                   //socket flags
            pfnWorkerCallBack,                                  //AysnCallBack delegate
            m_workerSocketPkt[m_clientCount].m_currentSocket    //state
        );

        m_mainSocket.BeginAccept(new AsyncCallback(OnClientConnect), null); //start invitation for other new sockets
    }

The Max Client Value is here 200 and worker sockets also, so it should handle 200 clients but I think it's creating a problem in receiving data from more than 15 clients because every client that is connected is continuously connected and sends data to the server.

Community
  • 1
  • 1
amit jain
  • 21
  • 3
  • The error message? You may have hit the license limit for half-open connections and need to upgrade to Windows Server. Read this question for more details: http://serverfault.com/questions/51597/how-to-fix-tcp-ip-has-reached-the-security-limit-event-message – Steve-o Jan 05 '11 at 08:08
  • 1
    Steve - unlikely IMHO. The half open connection limit is for outbound connections, not inbound and the issue occurs due to the RATE of new outbound connections being attempted, not the total number. – Len Holgate Jan 05 '11 at 08:41
  • As Peter says, it's most likely a bug in your server code; can you show us some code around the point where the server accepts new connections? – Len Holgate Jan 05 '11 at 08:42

2 Answers2

1

Increase the m_workerSocketPkt array (or m_workerSocket) to more than 15 or convert it to a List<>. (I'm guessing since you did not show it's declaration)

jgauffin
  • 99,844
  • 45
  • 235
  • 372
  • I was going to suggest "search your code for the number 15 and replace it" but I thought that was a bit harsh. Essentially, I agree that something in his app is limited to 15. – Neil Barnwell Jan 21 '11 at 12:19
0

Your even the most basic Windows XP system should be able to handle 1000 connections. TCP is allows thousands of connection per client machine. (I wouldn't suggest more than 100K per server)

If your program is failing its likely to be a bug in your code. Is possible it producing an error your are ignoring? What is the error your program gets?

Peter Lawrey
  • 525,659
  • 79
  • 751
  • 1,130