Browser webgl Client cannot connect to dedicated server but all other types of app can

Hi,

I have setup a Netcode for Gameobjects project in which the Unity server instance is on a custom linux server. I am able to connect to my custom linux server from the unity editor and locally deployed built apps (mac apps in my case).

However, when i deploy a webgl build, all checks and balances seem to work out (i.e. cert exchange seems ok) but after the NetworkManager.Singleton.StartClient() is called I get an error in my console inspector for my browser that I cannot connect to my server located at “wss:// etc. etc.”

I have been trying to work this out for a few days now but nothing seems to work. The most annoying thing is I can get a connection from built apps (mac) and the editor but webgl is no good. Is this a bug with Webgl and Netcode for Gameobjects right now?

I am using websockets and encryption in UnityTransport and my certificatees are Letsencrypt based and up to date so no idea what could be the issue.

Any insight or advice from anyone that has had experience with this would be massively appreciated.

Cheers!

Is websockets enabled for BOTH the webgl client and the server? Otherwise it won‘t work. If you intend to support cross platform play with webgl, all participants need to use websockets.

For connection type you have to use „wss“ not „dtls“.

Those are the two main differences for allowing web client connections.

1 Like

Yes, enabled websockets for all platofrms and server and clients.

I found out what it is though. It turns out the issue is if you call NetworkManager.Singleton.StartClient() in a web build before the server is active, the webgl instance will hang and throw an error. This is not the case for editor and mac/windows/linux apps which seem to have no issue calling StartClient() and then waiting for the server to call NetworkManager.Singleton.StartServer().

The problem now is, how do I catch the error in my Webgl build and handle it gracefully? StartClient() still returns a true “success” value even if it does not connect to the server instance. The error is then thrown after the StartClient() call and I don’t know where to catch it before it hangs my game?

Are any of the events called, like connection and start/stop events?