I want to write a server application on C++ using sockets. This applications is a game server. Server accepts connections from clients and keeps these connections during the whole session. Both server and client send data to each other. The connection may be kept for the long time. Server does lots of data processing besides sending and receiving data. Also server saves data to hard drive.
Could you tell me please what is the best way to organise all this? Is it good to create a thread for each client connection? Can I use somehow async sockets? What articles are good to read on this subject (gameserver development, server development)?
Thanks!
You don't say which OS you're writing for, but the most scalable approach on Windows would be to use overlapped I/O with I/O completion ports. This allows you to easily scale to many thousands of connections with only a small number of threads.
I've written some articles about how to use IOCP and these include C++ code for some simple server designs. These may be helpful to you to get a feel for what the technology can do.