Using Client

The client application is responsible for handling interactions and communication with the game server. It acts as the interface through which players can connect to and interact with the game. The client application is a crucial component of any multiplayer game as it enables players to send and receive data, perform in-game actions, and receive real-time updates from the game server.

This material describes the usage of the preconfigured client, which will connect to the running Transport Server, send a few messages, and receive the response back. In case you haven’t configured the server yet, we recommend referring to the corresponding Transport Server Guide, where you can find exhaustive information on the server configuration and how to run the server application.

Retrieving the Client

Clone into the Game Carrier Examples repository:

git clone https://github.com/gamecarrier/examples

The examples repository contains the preconfigured client application which will be built and used further in this material. The client is located in the spammer folder.

Building The Client Application

This material is centered around building the preconfigured client application retrieved from the examples repository. But you can also follow the same steps to build your custom application.

Open the examples directory where the cloned files are stored:

cd /home/user/examples
cd “C:\Path\To\Git\examples”
cd /Users/user/git/examples

Configure the build: cmake -S . -B build -DCMAKE_BUILD_TYPE=Release

  • -S .: Specifies the source directory where the CMakeLists.txt file is located. In this case, it’s the current directory represented by ..
  • -B build: Specifies the build directory where CMake will generate the build files and store the build artifacts. In this case, the build directory is named “build”.
  • -DCMAKE_BUILD_TYPE=Release: Sets the build type to “Release”. This affects the build configuration, enabling optimizations and disabling debug symbols, which results in an optimized binary.

Build the project: cmake --build build --config Release

Running the Client

Make sure that the Transport Server is running. To run the example client application, open the command prompt and navigate to the following directory:

cd /home/user/examples/build/bin/clients/Release/spammer
cd “C:\Path\To\Git\examples\build\bin\clients\Release\spammer.exe”
cd /Users/user/git/examples/build/bin/clients/Release/spammer

Then, execute the command:

spammer -h wss://localhost:7681/minimal_app 3
spammer.exe -h wss://localhost:7681/minimal_app 3
spammer -h wss://localhost:7681/minimal_app 3

The number 3 at the end of the command indicates the number of messages that will be sent to the server. The example client application is designed to use the following options:

$ build/bin/clients/spammer --help
Usage: build/bin/clients/spammer [options] [uri1 [xN1] [uri2 [xN2] ... ]]
Options:
  -p  --passive   Run client in passive mode.
  -a   --active   Run client in active mode.
  -h   --hybrid   Run client in hybrid mode.
  -v  --verbose   Verbose level of logging.
         --help   Print help message and exit.
  -k   --kbytes   Base message len in kb.
  -s    --sleep   Sleep time in ms between gc_clients_service().
  -r    --relax   Relax time in ms.

After running the command, the client application will send three messages to the server, retrieve the response back and log all actions to the output. The client application will quit upon retrieving the last response.