Unity-Technologies / multiplayer-community-contributions

Community contributions to Unity Multiplayer Networking products and services.
MIT License
429 stars 161 forks source link

transport.websocket (wss) JSWebSocketClient.Connect() opening handshake is timing out #111

Open JasonKappes opened 2 years ago

JasonKappes commented 2 years ago

Related Unity Thread: https://forum.unity.com/threads/webgl-websocket-troubleshooting.1185469/

I'm having trouble getting HTTPS (wss) connections to work, HTTP (ws) works fine.

It looks like after JSWebSocketClient.Connect() is called, it never completes the handshake. I'm running a Windows instance of the application (host), and I'm also running a WebGL instance of the application on a site as the client. I enter in the port and IP for the client to connect too and the handshake times out. If I untick the secure connection, it works. Are there certain certificates that I'm missing? I can provide more information if needed.

LukeStampfli commented 2 years ago

@quantumsheep would you happen to know what's not working?

quantumsheep commented 2 years ago

Secure Connection checkbox only enables WSS for the client. The server do not generate SSL certificates needed for WSS. To have a WSS server you need to setup a proxy between the users and the game server (E.g. Nginx, Apache?, Caddy).

karstenpt commented 2 years ago

Even with a setup proxy it does timeout -> connection isnt etablished when using the javascript/webgl part I made it connect secure thru proxied ws server via nginx in editor which is using NativeWebsocketClient this is an important issue and needs to be priorized. Edit: To clarify more , what @quantumsheep is saying is true but with that it does also not work in WebGL/Webassembly

karstenpt commented 2 years ago

I also found out so far (by using wscat and much energy) that in WebGL/Webassembly build the connection drops after 10 seconds, if you use the --slash option in wscat and send a /ping a pong gets replied but the connection drops anyway

Also interesting: the "OnClientConnected" event never gets fired if the javaclient/webgl is connecting to the server

all configuration tries and tips for fixes found on the web using DuckDuckGo hard in the last few days didnt change it. A secure connection from within the Editor seams to work so far. Can we please search all after where this bug is? or if someone made sucessfully a WebGL build and ran it on Firefox/Chrome with this transport PLEASE respond. Also @quantumsheep , would you please so kind and tell us all what proxy you used if it worked for you somehow and how the config was ?

karstenpt commented 2 years ago

as it seams we need to implement something called "ping/pong" rules
as far as I understand the websocket specs say the server has to send a "ping" to the client(s) and as far as i can see the websocket-sharp does that not automatically by standard settings, this would also explain why a "NativeWebsocketClient" does not drop the connection because it does not wait for the "ping" from the server