Connecting too fast?

Started by
13 comments, last by LordShade 18 years, 5 months ago
Hi all, I'm testing my server and I've created an app that simply connects to the server then close the connection and repeats. The problem if that unless I include a Sleep(40) call after the socket closed, I get all kind of error on the client side. As soon as I place the sleep, i can keep connecting and disconnecting for hours without problems. I'm not even sending data, I just connect and disconnect. I checked and there's no memory leak, the client app uses ~524 KB steadily. I tried to connect to my Apache web server instead of my game server (without sending data), and the same things happen. Any ideas? --Eric
Advertisement
If I were to answer my own post, I would most certainly tell me to look at the SO_LINGER socket option.

:)

--Eric
Perhaps if you told us what kind of errors you get on the client side, people could help you better.

Mark
The fact that SO_LINGER was not set to zero meant that closesocket() would not immediately get rid of the connection, so when creating 200+ sockets per second on my tests I was getting all kind of errors, including 10048.

By setting the linger to zero, the connection is closed immediately, though not gracefully, and I can make tons of connections for testing my server.

--Eric
I'd say you need to close and shutdown socket operations. I am working on a multi-client chat application right now, and I encountered this error with both the client and server.

I'm using MFC though, but I still had to make sure I call "Close" and "ShutDown" on the socket when it disconnected. =)
:==-_ Why don't the voices just leave me alone?! _-==:
Another reason for the 10048 error is the fact that if you're making 200+ connections per seconds, you will run out of local ports unless you tweak Window's registry.

In the case I mentionned above, I was hitting the upper bound of port 5000.

I still have problems on the client side when trying to connect really fast, even when using shutdown and close. At around 200 connections per seconds everything works correctly, but faster than that and the client chokes on either the connect() or send() function.

Any ideas? As for the server it's operating at around 10% cpu under 1000 connections per second.

The only thing I can think of that cause clients to get those errors is that the server cannot accept the connections fast enough, but even when I use multiple threads that accept connection (like the Apache web server) and most of them are idle the problem with the client still occurs...

I'm pretty much stumpted...

--Eric


maybe explain why you are trying to make 1000 connections a second?
I'm trying to test my server. I have several computers on a network, but I am unable to push the server very far because my clients cannot connect fast enough.

What I want to find out is why the clients fail to connect. I assume it's because I'm trying to connect too fast (200+ connections per seconds) but I am not sure.

Is there an OS limit on the number of connections per second a winsock2 client can make?

--Eric
well basically yes, as you fill ports up at a rapid rate you run out of ports =P So your connection is limited by how many connections / second / active connections you have. Basically what you need to realise is for 1000's of connections / second you would have multiple servers and balance the load of those servers.
give me the specs on the server and i'll find out what I can =P
os/machine/language/etc anything you can throw out =P

This topic is closed to new replies.

Advertisement