C++ Examples
In this section we discuss the C++ examples distributed as a dedicated package on the SmartFoxServer 3 download page.
They build and run on Windows, macOS and Linux.
Package structure
SFS3_CppExamples/
├── SFS3_API_Cpp/ the C++ client API (source code and documentation)
├── ConsoleClient/ a console program that connects and logs in
├── TicTacToe/ a two-player game with a lobby, spectators and chat
└── TicTacToeExtension/ the server side code for the game
Each example folder has two build scripts: build.bat for Windows and build.sh for macOS and Linux. The script builds the API from SFS3_API_Cpp/ together with the example's code, so you don't have to build the API first. Keep the SFS3_API_Cpp folder next to the examples, with this exact name.
Requirements
- CMake 3.16 or higher
- A C++17 compiler
Windows
Install Visual Studio 2019 or higher (the free Community edition is fine), with the Desktop development with C++ workload. It includes CMake. Run the build script from a Developer Command Prompt for Visual Studio.
macOS
Install the Xcode Command Line Tools with xcode-select --install, and CMake, for example with brew install cmake.
Linux
Install a compiler and CMake. On Debian/Ubuntu: sudo apt install build-essential cmake.
Build
Open a terminal in the example folder and run its build script. For example:
Windows
cd TicTacToe
build.bat
macOS and Linux
cd TicTacToe
./build.sh
The first build takes longer, because it also compiles the API. The program goes into the bin/ folder of the example.
The default build type is Release. For a Debug build, give its name to the script: build.bat Debug or ./build.sh Debug. Crash reports from a Debug build show function names and line numbers, so please use one if you report a problem. A Debug build needs about ~500 MB of disk space for each example.
Run
Windows
bin\TicTacToe.exe
macOS and Linux
bin/TicTacToe
The same applies for the other example(s).