socket programming in windows to send data freezes for sometime and getting delayed for sometime?
<p>I am able to send data successfully with a static class through socket programming, it works fine for small amount of data but in production environment it is freezing for sometime and again it is starting to send data, i am unable to figure out what is the problem? can you please help. Code is as below.</p>

<pre><code>            DWORD BytesCount;  
    WSABUF Buffer[1];
    DWORD Flag = 0;

    Buffer[0].len = SendLength;
    Buffer[0].buf = SendData;
    if (WSASend(*socket, Buffer, 1, &amp;BytesCount, Flag, NULL, NULL) != SOCKET_ERROR)
    {
        if (BytesCount != SendLength )
            Result = -2;
        else
        {
            if (ReturnAnswer)
            {
                int Res = 0, recBufStart;
                DWORD RecvCount = 0, AllRecv = 0;

                Buffer[0].len = ReceiveLength;
                Buffer[0].buf = ReceiveData;
                recBufStart = 0;
                saAction = saReceive;

                // We need to Receive until we get all the data. When WSARecv call might only return zero bytes
                bool Stop = true; // true as we dont need to recieve anything from the server.
                while (!Stop)
                {
                    Res = WSARecv(*socket, &amp;Buffer[recBufStart], (recBufStart == 0 ? 1 : 0), &amp;RecvCount, &amp;Flag, NULL, NULL);
                    if (Res == SOCKET_ERROR)
                        Stop = true;
                    else
                    {
                        AllRecv = AllRecv + RecvCount;
                        if (AllRecv == ReceiveLength || RecvCount == 0)
                            Stop = true;    // Stop
                        else
                        {
                            Buffer[0].buf = &amp;ReceiveData[AllRecv];
                            Buffer[0].len = ReceiveLength - (AllRecv);
                            recBufStart = 0;
                        }
                    }
                }

                if (Res == SOCKET_ERROR)
                    Result = WSAGetLastError();                 
            }
        }
    }
    else
        Result = WSAGetLastError();     
</code></pre>
