3 Building a Game Server

 

This chapter covers

  • Create an async webserver using Rust
  • Design an application protocol
  • Share data fast and safe
  • Spawning simultaneous running services

Now that we have a game client to play with we will move our attention to building the foundation for a backend to connect to.

In order for multiple clients to interact with one another we are going to build a server-client topology - unlike in peer to peer setups all clients will connect to one server so that we can control how two clients will communicate with each other. This topology is depicted in the following schema:

Figure 3.1. Client-Server Topology

The server S is a single instance right now and the clients C connect all to one - this is not going to scale well so we will extend this in later chapters.

For now our backend is going to allow us: connecting to it, sending our player state to it and receiving the states of other players.

In order to make this digestible we want to subdivide the task into smaller pieces of work. The steps will be the following:

  1. Setup and Connection handling
  2. Establishing a protocol
  3. Welcome Message
  4. Broadcast a Goodbye Message
  5. State update message

In Step 1 we will set up a new server project and build a running server that accepts incoming connections and nothing more. This allows us to build on.

In the next section we will talk about the protocol we define for the two parties (client and server) to communicate with.

3.1 Setup and Connection Handling

 
 
 

3.2 Defining a Protocol

 
 

3.3 Welcome Message

 

3.4 Broadcasting Messages

 
 

3.5 State Update Message

 
 

3.6 Summary

 
 
sitemap

Unable to load book!

The book could not be loaded.

(try again in a couple of minutes)

manning.com homepage
test yourself with a liveTest