Hi, I am currently trying to write some kind of game server which gets and sends tcp packets from and to the client.
So I am aiming for a server that should be able to easily handle 1000+ connected clients.
I already implemented a testing code to make the processing code for the recieving data but this works only for one client.
It is possible for other clients to join too but since I dont have much network experience I tried to help myself with multiple threads, a new thread for every connected client.
However since I dont have much experience with threads either (at least with the critical sections and that stuff), problems show up once the server recieves packets from two (or more) clients at the approximate same time.
I dont even really exactly know what is happening, all I know is that for some reason one client gets the packet the other one is supposed to get and he also gets the one he is supposed to get.
So the one client gets nothing and the other one gets one packet he doesnt expect which means both get disconnected (one immediately and the other one some time later because of various reasons).
Now I am trying to find a reliable connection method that is able to handle multiple clients at any time (even if 30 packets from different clients are recieved at the same time) and I found two promising methods, however I am unsure which one I should take.
- I/O Completion Ports:
http://msdn.microsoft.com/en-us/library/aa365198%28VS.85%29.aspx
(example I found ->
http://www.winsocketdotnetworkprogramming.com/winsock2programming/winsock2advancedscalableapp6b.html
, is this the way it is generally done?
- boost::asio:
http://www.boost.org/doc/libs/1_43_0/doc/html/boost_asio/overview.html
tbh I havent done much research on this one, for now I tried to focus myself on iocp
What are the benefits for each and how easy are they to implement/understand?
I dont need a detailed description of each, just a short explanation of how the socket(s) get set up and whats happening afterwards when a client connects and sends packets. And how they are sent back.
For example the way I am currently doing is, is creating a thread for a listening socket (with a defined port).
Then I check for new incoming connections with accept(...) until the socket cloese for some reason.
And with every new connection, a new thread is created where I pass the socket of the client to the thread so I can constantly check for incoming packets within the thread (with recv(...).
If a packet comes in, I read out the data, process it and send it back to the original client in the same thread (with send(...)).
I am using Windows and the functions are from Winsock.h.
Also it would be nice if I could use OpenSSL for the packets I get and send (which I am currently using with SSL_read and SSL_write).
So yeah, what "socket methods" would you recommend/decline and why?