Go Realtime Client API

I’m developing a cli in Go for interacting with a nakama game.

I have the non-realtime component working using apigrpc.NakamaClient. The game also uses streams, and it’s not clear how to implement these client-side in Go.

I’d like to implement the Socket functionality found in the javascript client socket.ts in Go.

In particular, I need to implement MatchData and StreamData handlers (and possibly others later). I would also prefer using gRPC as the network transport, but websockets are fine if gRPC is not possible.

This issue golang client availability #346 alludes to using github.com/nakama-common/rtapi for real-time functionality, but I can’t find any examples of how to actually use it.

Can I get some help implementing an simple client that can send/receive MatchData and StreamData? Thanks.

Hi @marcusscorpius welcome :wave:

In particular, I need to implement MatchData and StreamData handlers (and possibly others later). I would also prefer using gRPC as the network transport, but websockets are fine if gRPC is not possible.

It’s not possible to use the gRPC protocol with the realtime socket features in Nakama because gRPC is not fast enough (at the network level) to implement multiplayer or our streams gameplay APIs. Instead we designed our socket layer to support different network transports.

Can I get some help implementing an simple client that can send / receive MatchData and StreamData ? Thanks.

Sure. We don’t have any documentation on how to implement the socket portion of the Nakama API (except for the client sdks which are all open-source) but I can guide you through how it works:

  • The /ws?token="session token" endpoint in the server expects a WebSocket protocol upgrade message which will convert the HTTP request into an open socket connection.
  • The socket expects every message to have an envelope which is this protobuf message.
  • The socket can accept messages in binary or text mode but you cannot switch between one and the other.
  • The envelope message contains the marker for the content of the inner message to be consumed. This allows chat, multiplayer, status events, and other realtime messages to be multiplexed over a single socket.
  • For the realtime multiplayer messages you need to look at: Match, MatchCreate, MatchData, MatchDataSend, MatchJoin, MatchLeave, MatchPresenceEvent, MatchmakerAdd, MatchmakerMatched, MatchmakerRemove, and MatchmakerTicket.
  • For stream messages you need to look at: StreamData, and StreamPresenceEvent.

Hope this helps. We’d like to have an official Go client implementation maintained in the source tree for the codebase at some point. All contributions are welcome.