This sample demonstrates a gaming presence service in which a game server (represented by the LoadGenerator application) sends periodic heartbeats to a cloud service (represented by the PresenceService application) containing the status of a game which it is hosting. Inside the service, a corresponding PresenceGrain
is responsible for unpacking the heartbeat message and reflecting the state of the game in the PlayerGrain
and GameGrain
grains. The effects of this can be seen on a client application (PlayerWatcher), which polls the player for the current game session. Each time a new game session is returned, the client creates a new LoggerGameObserver
which subscribes to the game grain so that status updates are pushed to it using the IGameObserver
interface.
This sample is written in C# and targets .NET 6.0. It requires the .NET 6.0 SDK.
To download and run the sample, follow these steps:
- Download and unzip the sample.
- In Visual Studio (2022 or later):
- On the menu bar, choose File > Open > Project/Solution.
- Navigate to the folder that holds the unzipped sample code, and open the C# project (.csproj) file.
- Choose the F5 key to run with debugging, or Ctrl+F5 keys to run the project without debugging.
- From the command line:
- Navigate to the folder that holds the unzipped sample code.
- At the command line, type
dotnet run
.
To build and run the sample step-by-step on the command line, use the following commands:
Build the solution using the .NET CLI:
dotnet build
Launch the server process:
dotnet run --project ./src/PresenceService
In a separate terminal window, launch the player watcher:
dotnet run --project ./src/PlayerWatcher
In a separate terminal window, launch the load generator:
dotnet run --project ./src/LoadGenerator