Unable to matchmake

Hey everyone,

I’m new to Nakama and have been following the “Nakama in Unity” playlist. I managed to get the Nakama server running with Docker and I’m now stuck at the Matchmaking tutorial.

I pressed the “Find Match” button on both instances of the game but I do not get the printed message that happens at 8:22 of the eighth tutorial. I checked the server console and it did register 2 matchmaking tickets. Below is my script so far:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Nakama;

public class NakamaConnection : MonoBehaviour
{
    string scheme = "http";
    string host = "localhost";
    int port = 7350;
    string serverKey = "defaultkey";

    IClient client;
    ISession session;
    ISocket socket;
    string ticket;

    async void Start()
    {
        client = new Client(scheme, host, port, serverKey, UnityWebRequestAdapter.Instance);
        session = await client.AuthenticateDeviceAsync(SystemInfo.deviceUniqueIdentifier);
        Debug.LogFormat("New user: {0}, {1}", session.Created, session);
        socket = client.NewSocket(true);
        socket.ReceivedMatchmakerMatched += OnReceivedMatchkamerMatched;
        await socket.ConnectAsync(session, true);
        
        Debug.Log(socket);
    }

    public async void FindMatch()
    {
        Debug.Log("Finding match");
        var matchmakingTicket = await socket.AddMatchmakerAsync("*", 2, 2);
        ticket = matchmakingTicket.Ticket;
    }

    async void OnReceivedMatchkamerMatched(IMatchmakerMatched MatchmakerMatched)
    {
        Debug.Log("Joining match....");
        var match = await socket.JoinMatchAsync(MatchmakerMatched);
        Debug.Log("Our sessions ID: " + match.Self.SessionId);

        foreach(var user in match.Presences)
        {
            Debug.Log("Connected User Session ID: " + user.SessionId);
        }

    }
}

The only other thing I noticed that was different from the video was when it printed my session, the Created property was false instead of true like the video.

New user: False, Session(AuthToken='eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1aWQiOiJlZjIyNTVmZS1iZGVjLTRhZWQtOWMwNC0zY2U4MmZhMmNkM2UiLCJ1c24iOiJ4Y0dLU3BYUG9UIiwiZXhwIjoxNjQ0NjUwMDMwfQ.cGBSI8aeUTJv5WLsc9cPXYK0AtNyFQTXT87wvybr81k', 
Created=False, 
CreateTime=50, 
ExpireTime=1644650030, RefreshToken=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1aWQiOiJlZjIyNTVmZS1iZGVjLTRhZWQtOWMwNC0zY2U4MmZhMmNkM2UiLCJ1c24iOiJ4Y0dLU3BYUG9UIiwiZXhwIjoxNjQ0NjQ2NDMwfQ.Ke-kWDZYp1eSfw2Q2saLK77YbwJyQWQWQUYWR311NKM, 
RefreshExpireTime=1644646430, 
Variables={}, Username='xcGKSpXPoT', UserId='ef2255fe-bdec-4aed-9c04-3ce82fa2cd3e')

So I tried testing the matchmaking with the fish-game project and it works! I am also able to do the matchmaking on my own game now using the server that was created from the fish-game project. So there must be something off about my docker-compose.yml. This is mine:

version: '3'
services:
  cockroachdb:
    image: cockroachdb/cockroach:latest-v20.2
    command: start-single-node --insecure --store=attrs=ssd,path=/var/lib/cockroach/
    restart: "no"
    volumes:
      - data:/var/lib/cockroach
    expose:
      - "8080"
      - "26257"
    ports:
      - "26257:26257"
      - "8080:8080"
  nakama:
    image: heroiclabs/nakama:3.9.0
    entrypoint:
      - "/bin/sh"
      - "-ecx"
      - >
        /nakama/nakama migrate up --database.address root@cockroachdb:26257 &&
        exec /nakama/nakama --name nakama1 --database.address root@cockroachdb:26257 --logger.level DEBUG --session.token_expiry_sec 7200 --metrics.prometheus_port 9100
    restart: "no"
    links:
      - "cockroachdb:db"
    depends_on:
      - cockroachdb
      - prometheus
    volumes:
      - /c/Users/Tym/projects/docker:/nakama/data
    expose:
      - "7349"
      - "7350"
      - "7351"
      - "9100"
    ports:
      - "7349:7349"
      - "7350:7350"
      - "7351:7351"
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:7350/"]
      interval: 10s
      timeout: 5s
      retries: 5
  prometheus:
    image: prom/prometheus
    entrypoint: /bin/sh -c
    command: |
      'sh -s <<EOF
        cat > ./prometheus.yml <<EON
      global:
        scrape_interval:     15s
        evaluation_interval: 15s
      scrape_configs:
        - job_name: prometheus
          static_configs:
          - targets: ['localhost:9090']
        - job_name: nakama
          metrics_path: /
          static_configs:
          - targets: ['nakama:9100']
      EON
      prometheus --config.file=./prometheus.yml
      EOF'
    ports:
      - '9090:9090'
volumes:
  data:

This is the one from fish-project:

version: '3'
services:
  cockroachdb:
    container_name: cockroachdb
    image: cockroachdb/cockroach:v19.2.5
    command: start --insecure --store=attrs=ssd,path=/var/lib/cockroach/
    restart: always
    volumes:
      - data:/var/lib/cockroach
    expose:
      - "8080"
      - "26257"
    ports:
      - "26257:26257"
      - "8080:8080"
  nakama:
    container_name: nakama
    image: heroiclabs/nakama:2.12.0
    entrypoint:
      - "/bin/sh"
      - "-ecx"
      - >
          /nakama/nakama migrate up --database.address root@cockroachdb:26257 &&
          exec /nakama/nakama --name nakama1 --database.address root@cockroachdb:26257
    restart: always
    links:
      - "cockroachdb:db"
    depends_on:
      - cockroachdb
    volumes:
      - ./nakama/data:/nakama/data
    expose:
      - "7349"
      - "7350"
      - "7351"
    ports:
      - "7349:7349"
      - "7350:7350"
      - "7351:7351"
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:7350/"]
      interval: 10s
      timeout: 5s
      retries: 5
volumes:
  data:

I’ll work using the fish-game’s server in the meantime.

Containers seem to use different configuration files from different file locations. Can you try to find out if there is some major difference between them?

Are you referring to the nakama:volumes: path?

Yes. Server will probably try to look for config.yml or something similar in mapped directory. You can see which config file is used on first log row after server start.

{"level":"info","ts":"2022-02-16T08:20:09.956Z","caller":"main.go:104","msg":"Data directory","path":"/nakama/data"}

Is this it?

If so, both of the server logs has the same path. However, the folder where I have the docker-compose.yml file doesn’t have a nakama folder, it only has a modules folder. Could that be the cause of the problem?

@ProgramPlotam Can you please update to Nakama 3.10.0 and test again? If I recall correctly there was a matchmaker issue specific to the 3.9.0 release that was fixed in the very next release.

@zyro Hey thanks for the suggestion. I can finally connect using my own docker-compose. Everything looks to be working fine and I’ll be continuing the tutorial. Thank you very much!