I am working on a project for like 1 year now.
Most of it works well.
But somehow my socketenvironment craps out sometimes...
For a totally unknown reason a socket crashes with 10054, connection refused.
That socket usually processes easy packets with size being under 50, its a characterserver -> loginserver connection.
Well, I found out it crashes after some time when the send() command got used.
Before the "crashing" send() the app executed many other send()s, which are even the same functionspot, passing successfully.
The odd thing is that only the server socket crashes, the socket at the client stays alive, which of course is being checked frame-by-frame by recv().
Sadly, this "poison" goes over to another socket of the same DLL and makes it "crash", too, the client->characterserver connection.
Now I tell you about my "socketsystem".
The core application has a simple loop which looks like that:
Expand|Select|Wrap|Line Numbers
- while(IsActive())
- {
- FOR_EACH_SERVER
- {
- ServerDLLFrame();
- CheckNewConnections();
- HandleAllClients();
- }
- Sleep(1);
- }
Multithreaded looks similiar.
CheckNewConnections() is a "accept" for my unencrypted and encrypted sockets.
If accept() returns number above 0 I add this number as a socket to my list.
HandleAllClients() is a read-and-execute function.
It checks all clients in a loop if they have anything to send to me or just disconnected, without a Sleep() seperating recv() calls.
If recv() returns 0, client disconnected.
If recv() returns -1, error occurred or no data in buffer (WSAEWOULDBLOCK ?).
And if recv() got some number above 0 it has put something into buffer and I process this.
Yea. All sockets are non-block.
And the last thing, which I think surely wont matter:
All servers are being run on the same application, 3 in total.
But what now? I really dont know how to fix this "little" bug :/
Do I need to let the app sleep 1msec after every recv() if I need to call a recv() afterwards?
Is it needed to sleep 1msec before using send() after recv()?
Is it okay to send 24kb data in one packet?
Thanks for any help incoming :)
TheGTA