Relayed match connections on WebGL


Thank you for developing this framework!

I’m trying to use relayed mode and manually spawn a headless Unity instance as an authoritative server. Clients will be built with WebGL, so their connection is websocket. Each headless instance creates a Nakama match and will declare its identity to rest clients in relayed mode.
The headless Unity instance and Nakama will both be running in docker on a server.

My question is, how does the connection between clients in relayed mode work?
If I send state messages between the headless instance and other WebGL clients, do these messages go through Nakama?
Or am I supposed to expose the port of the headless instance in docker?

And please let me know if there are better ways to handle headless authoritative servers in Nakama that I’m not aware of! Thanks in advance!

@teamclouday yes the messages from each client, including the headless one, would go through Nakama.

Out of curiosity, why are you using headless instances instead of a more traditional client-server model?

1 Like

Hey @lugehorsam thanks for your reply!

The reason I use headless instance is because my game potentially requires physics simulations. As far as I know, the client-server provided in Nakama does not support Unity instance as server module yet so I need to write a custom runtime module in other languages (e.g. Typescript in my case).

And in my case it is hard to simulate game in the runtime module, for two reasons:

  1. I don’t want to implement physics simulation from scratch.
  2. The data I send from client side is the encoded string of byte arrays, instead of JSON format. And it is difficult and slow to decode on server side, since the only numeric type in Typescript is number.

So instead I was thinking of using relayed mode, except that one of the clients will always be an authoritative server (headless instance) that is automatically spawned for each match.

@teamclouday your approach makes sense to me.

1 Like