Working with the Server
Now it is time to put our hands on the actual server! We will be dissecting the GameServer
class to understand properly what is going on.
Server thread
To begin with, we decided to put the server in a separate thread. This is very useful in many ways. For once, server processing can be intensive and could hurt the frame rate on the client. On the other hand, if the server is running on a parallel thread, aside from improving its performance, it also allows it to perform blocking calls whenever necessary, and the game keeps running smoothly. Another plus in this approach is that our server does not communicate programmatically with the client, it communicates only via network; therefore, we don't even need to care about synchronization between the two. It is just like as if server is running on a different application!
As we have already introduced sf::Thread
before in Chapter 5, Diverting the Game Flow – State Stack, we will skip that topic here. It is important to notice...