Taking a peek in the other end – the client
We have looked in the server extensively and have hopefully clarified all systems and learned how they come together to form a single object that services a lot of clients at once, and potentially even more aircraft! Now let's look at the other end, the client, and see how we took a jump from a single-player-only game into a fully-networked game.
Let's examine the MultiplayerGameState
constructor first:
sf::IpAddress ip; if (isHost) { mGameServer.reset(new GameServer()); ip = "127.0.0.1"; } else { ip = getAddressFromFile(); } if (mSocket.connect(ip, ServerPort, sf::seconds(5.f)) == sf::TcpSocket::Done) mConnected = true; else mFailedConnectionClock.restart(); mSocket.setBlocking(false); ...
We need to deduce which IP to communicate with, in order to successfully join a game. If we are the host, we just connect to the loopback address 127.0.0.1
, otherwise, we need to connect to a pseudo-remote server. This means that in practice...