Nakama Socket + Godot + Docker errors

Try write a complete title that either describes:

  1. I was trying to connect to the Nakama Websocket server so i can use JoinMatchAsync
  2. I got the following error when trying to use socket.ConnectAsync:
System.Net.Sockets.SocketException (0x80004005): The operation completed successfully.

  at System.Net.Sockets.Socket..ctor (System.Net.Sockets.AddressFamily addressFamily, System.Net.Sockets.SocketType socketType, System.Net.Sockets.ProtocolType protocolType) [0x00068] in <5307bcb359e140d4b454b70b3ff646a0>:0
  at System.Net.Sockets.TcpClient.initialize () [0x00000] in <5307bcb359e140d4b454b70b3ff646a0>:0
  at System.Net.Sockets.TcpClient..ctor (System.Net.Sockets.AddressFamily family) [0x00046] in <5307bcb359e140d4b454b70b3ff646a0>:0
  at Nakama.Ninja.WebSockets.WebSocketClientFactory.GetStream (System.Guid loggingGuid, System.Boolean isSecure, System.Boolean noDelay, System.String host, System.Int32 port, System.Threading.CancellationToken cancellationToken) [0x0001b] in <91b413e2c23f427f89a924248efabf97>:0
  at Nakama.Ninja.WebSockets.WebSocketClientFactory.ConnectAsync (System.Uri uri, Nakama.Ninja.WebSockets.WebSocketClientOptions options, System.Threading.CancellationToken token) [0x000e3] in <91b413e2c23f427f89a924248efabf97>:0
  at Nakama.WebSocketAdapter.ConnectAsync (System.Uri uri, System.Int32 timeout) [0x00150] in <91b413e2c23f427f89a924248efabf97>:0
  at Login+<>c__DisplayClass9_0.<OnLoginButtonPressed>b__3 () [0x0012d] in C:\Users\J\repos\KitsumonGodot\Kitsumon\scripts\Login.cs:67
  1. Versions: NakamaClient NuGet v3.4.0
  2. TS Server modules
  3. Godot v3.4.4 Mono Client

Here is some code I am using on Godot:

_client = new Client("http", "127.0.0.1", 7350, "defaultkey");
_socket = Socket.From(_client);
userSession = await _client.AuthenticateEmailAsync(_emailInput.Text, _passwordInput.Text, _usernameInput.Text, true);    
await _socket.ConnectAsync(userSession);

Here is my docker-compose:

version: '3'
services:
  postgres:
    command: postgres -c shared_preload_libraries=pg_stat_statements -c pg_stat_statements.track=all
    environment:
      - POSTGRES_DB=nakama
      - POSTGRES_PASSWORD=localdb
    expose:
      - "8080"
      - "5432"
    image: postgres:12.2-alpine
    ports:
      - "5432:5432"
      - "8080:8080"
    volumes:
      - data:/var/lib/postgresql/data

  nakama:
    build: .
    depends_on:
      - postgres
    entrypoint:
      - "/bin/sh"
      - "-ecx"
      - >
        /nakama/nakama migrate up --database.address postgres:localdb@postgres:5432/nakama &&
        exec /nakama/nakama --config /nakama/data/local.yml --database.address postgres:localdb@postgres:5432/nakama        
    expose:
      - "7349"
      - "7350"
      - "7351"
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:7350/"]
      interval: 10s
      timeout: 5s
      retries: 5
    links:
      - "postgres:db"
    ports:
      - "7349:7349"
      - "7350:7350"
      - "7351:7351"
    restart: unless-stopped

volumes:
  data:

The server gets no requests (i see no console output when i try to connect):
Processing: image.png…

Whenever the code hits ConnectAsync it throws a error, then closes the port. So i cannot call any subsequent requests with the socket like JoinMatchAsync. I have even tried to construct the socket manually and change the port to 7349. It does not work.

Does anyone know whats going on here? The API works fine but the Websockets do not?

Hi, we are already tracking this issue here: TcpClient does not work properly on GoDot v3.4.4 Mono · Issue #106 · heroiclabs/nakama-dotnet · GitHub.

In case you’re using Godot 4 .NET it might be worth trying WebSocketStdlibAdapter which could solve your problem before the fix to the issue above.

1 Like