Winsock 10048 error

I have a stress test application which spawns 100 threads and then communicates through TCP to a server on the same machine.

The connection code looks like:

bool CSockConnector::Connect(const CInetAddr &Addr, CSockStream &Socket)

{

Socket.SetSocket(socket(AF_INET, SOCK_STREAM, 0));

if (Socket.GetSocket() == INVALID_SOCKET)

{

// printf("Cannot create socket: %d\n", WSAGetLastError());

return false;

}

if (connect(Socket.GetSocket(), Addr.GetAddr(), Addr.GetSize()) != 0)

{

printf("Connection error: %d\n", WSAGetLastError());

return false;

}

return true;

}

As one can see the code is pretty clean. However I have the problem that some times under alot of pressure I get a WSA error 10048. Looking it up seems to be a bind problem.

Interesting observations are that I have never seen this error with VC 2005 but only VCNET 2003.

On the server side I do use REUSE_ADDR for the listen socket but it should not matter.

What could the idea behind this error be As the manual says connect() should find a new port number to work on.

Is 100 clients too much to handle I don't believe that would be the case.

Thanks.

-- Henrik



Answer this question

Winsock 10048 error

  • ihar3d

    TCP on the server-side binds to a particular port and clients would connect to that same port. Windows socket I/O is robust and can process many I/O requests.

    Describe the server-side. How are you handling incoming connections

    valikac

  • MgManoj

    I have now carefully verified the code to see if there would be any socket leaks. Even though I found a bug or two it doesn't make a big difference.

    What I realise is that the problem happens after about 4000 socket descriptors hit into the TIME_WAIT state of netstat.

    I notice that all sockets get a number from about 1000 to 5000 and then it dies with 10048.

    Is there any limit I should be aware of

    Thanks.

    -- Henrik


  • DSent

    On the client side just before connect I ensure to the server I do a dns lookup with getaddrinfo().

     

    On the server side I have the following initialization code (I have only copied relevant pieces):

    s = socket(AF_INET, SOCK_STREAM, 0)

    setsockopt(s, SOL_SOCKET, SO_REUSEADDR, ...)

    ioctlsocket(m_Socket, FIONBIO, &EnableNonBlocking)

    bind(s, ...)

    listen(s, SOMAXCONN)

    In other words I have a server which enables SO_REUSEADDR and which has a non-blocking listen socket.

    The SO_REUSEADDR part was mostly for making it work properly on solaris and other unix os.

    The listen socket is polled every 5 ms to see if it gets a connection or if the socket error is different from "WOULDBLOCK". No errors gets written to any logs on the server side though.

    In other words it's a client side problem only but might be influenced by the server though.

    I also have a UDP socket open on the same port which works similar. This is again a socket which is using SO_REUSEADDR. However to the best of my knowledge UDP should be entirely independent of TCP regardless of if the same port number is used for both, right

    I wonder why I experience this problem much more often with one compiler and not others. The code comes from the Win32 subsystem so I cannot think of a reason why this should have an effect.

    -- Henrik


  • Winsock 10048 error