Nakama .NET Client SDK 3.5.0
Nakama .NET Client SDK
No Matches
Nakama .NET


‍.NET client for Nakama server written in C#.

Nakama is an open-source server designed to power modern games and apps. Features include user accounts, chat, social, matchmaker, realtime multiplayer, and much more.

This client implements the full API and socket options with the server. It's written in C# with minimal dependencies to support Unity, Xamarin, Godot, XNA, and other engines and frameworks.

Full documentation is online -

Getting Started

You'll need to setup the server and database before you can connect with the client. The simplest way is to use Docker but have a look at the server documentation for other options.

  1. Install and run the servers. Follow these instructions.
  2. Download the client from the releases page and import it into your project. You can also build from source.
  3. Use the connection credentials to build a client object.

    // using Nakama;
    const string scheme = "http";
    const string host = "";
    const int port = 7350;
    const string serverKey = "defaultkey";
    var client = new Client(scheme, host, port, serverKey);


The client object has many methods to execute various features in the server or open realtime socket connections with the server.


There's a variety of ways to authenticate with the server. Authentication can create a user if they don't already exist with those credentials. It's also easy to authenticate with a social profile from Google Play Games, Facebook, Game Center, etc.

var email = "";
var password = "batsignal";
var session = await client.AuthenticateEmailAsync(email, password);


When authenticated the server responds with an auth token (JWT) which contains useful properties and gets deserialized into a Session object.

System.Console.WriteLine(session.AuthToken); // raw JWT token
System.Console.WriteLine(session.RefreshToken); // raw JWT token.
System.Console.WriteLine("Session has expired: {0}", session.IsExpired);
System.Console.WriteLine("Session expires at: {0}", session.ExpireTime);

It is recommended to store the auth token from the session and check at startup if it has expired. If the token has expired you must reauthenticate. The expiry time of the token can be changed as a setting in the server.

var authToken = "restored from somewhere";
var refreshToken = "restored from somewhere";
var session = Session.Restore(authToken, refreshToken);
// Check whether a session is close to expiry.
if (session.HasExpired(DateTime.UtcNow.AddDays(1)))
session = await client.SessionRefreshAsync(session);
catch (ApiResponseException e)
System.Console.WriteLine("Session can no longer be refreshed. Must reauthenticate!");

:warning: NOTE: The length of the lifetime of a session can be set on the server with the "--session.token_expiry_sec" command flag argument. The lifetime of the refresh token for a session can be set on the server with the "--session.refresh_token_expiry_sec" command flag.


The client includes lots of builtin APIs for various features of the game server. These can be accessed with the async methods. It can also call custom logic in RPC functions on the server. These can also be executed with a socket object.

All requests are sent with a session object which authorizes the client.

var account = await client.GetAccountAsync(session);

Requests can be supplied with a retry configurations in cases of transient network or server errors.

A single configuration can be used to control all request retry behavior:

var retryConfiguration = new RetryConfiguration(baseDelayMs: 1000, maxRetries: 5, delegate { System.Console.Writeline("about to retry."); });
client.GlobalRetryConfiguration = retryConfiguration;
var account = await client.GetAccountAsync(session);

Or, the configuration can be supplied on a per-request basis:

var retryConfiguration = new RetryConfiguration(baseDelayMs: 1000, maxRetries: 5, delegate { System.Console.Writeline("about to retry."); });
var account = await client.GetAccountAsync(session, retryConfiguration);

Per-request retry configurations override the global retry configuration.

Requests also can be supplied with a cancellation token if you need to cancel them mid-flight:

var canceller = new CancellationTokenSource();
var account = await client.GetAccountAsync(session, retryConfiguration: null, canceller);
await Task.Delay(25);
canceller.Cancel(); // will raise a TaskCanceledException


The client can create one or more sockets with the server. Each socket can have it's own event listeners registered for responses received from the server.

var socket = Socket.From(client);
socket.Connected += () =>
System.Console.WriteLine("Socket connected.");
socket.Closed += () =>
System.Console.WriteLine("Socket closed.");
socket.ReceivedError += e => System.Console.WriteLine(e);
await socket.ConnectAsync(session);


The development roadmap is managed as GitHub issues and pull requests are welcome. If you're interested to improve the code please open an issue to discuss the changes or drop in and discuss it in the community forum.

Source Builds

The codebase can be built with the Dotnet CLI. All dependencies are downloaded at build time with Nuget.

dotnet build src/Nakama/Nakama.csproj

For release builds use:

dotnet build -c Release /p:AssemblyVersion= Nakama/Nakama.csproj
// For Nuget packaging
dotnet pack -p:AssemblyVersion= -p:PackageVersion=2.0.0 -c Release Nakama/Nakama.csproj

Run Tests

To run tests you will need to run the server and database. Most tests are written as integration tests which execute against the server. A quick approach we use with our test workflow is to use the Docker compose file described in the documentation.

docker-compose -f ./docker-compose-postgres.yml up
dotnet test tests/Nakama.Tests/Nakama.Tests.csproj

To run a specific test, pass the fully qualified name of the method to dotnet test --filter:

dotnet test --filter "Nakama.Tests.Api.GroupTest.ShouldPromoteAndDemoteUsers"

If you'd like to attach a Visual Studio debugger to a test, set VSTEST_HOST_DEBUG to true in your shell environment and run dotnet test. Attach the debugger to the process identified by the console.

Generate Docs

nakama-dotnet API docs are generated with Doxygen and deployed to GitHub pages.

When changing the API comments, rerun Doxygen and commit the changes in docs/*.

To run Doxygen:

brew install doxygen
cd docs/


This repository also contains the Satori client for use with the Satori Liveops Server.

It follows the same authentication patterns as Nakama but is used for managing your live game via sending analytics events, updating properties, getting feature flags and experiments, and more.

In order to run tests for Satori, create sample data via the Satori console.

Then run dotnet test from this directory.


This project is licensed under the Apache-2 License.

Special Thanks

Thanks to Alex Parker (@zanders3) for the excellent json library and David Haig (@ninjasource) for Ninja.WebSockets.