I m the network programmer on a school game project. We want to have up to 16 players at once on a LAN. I am using the Server-Client model and am creating a new thread per client that joins. However, a lot of CPU time is wasted just checking on each thread if the non-blocking port has received anything from the client.
I ve been reading "Network Programming for Microsoft Windows" by Anthony Johns and Jim Ohlund. They mention two different models for server-client apps.
1.)
- Using overlapped IO socket options
- Pass the overlapped struct and a WorkerRoutine to WSARecv
- Call WSAWaitForMultipleEvents() or SleepEX() to set thread to alertable.
- Handle Received data in the WorkerRoutines.
2.)
- Using overlapped IO socket options
- Create Io Completion Port
- Create ServerWorkerThreads (however many CUPs you have)
- Associate Completion port with Socket.
- Call GetQueuedCompletionStatus in the ServerWorkerThread and handle received data.
I wanted to know which method would best fit my circumstance. The book says the Completion Port model is great for thousands of clients but that makes me think its made for a big server not for a small LAN game. The WorkerRoutines/Event system seems simpler.