WebSocket (WSS) Through Cloudflare Tunnel
Hi, I'm trying to host a Unity dedicated server for my game to a domain I own. Unity uses WebSockets for the multiplayer framework I'm using, so the clients talk to the host through
wss://localhost:7777
I made a quick python script to test this: It sends a standard client hello to the endpoint and expects the server response. It works fine for localhost
.
So I tried setting up a cloudflared tunnel to provide the WebSocket service at wss://localhost:7777 to api.mydomain.com, with the path /socket.
The ingress rule is set up as
I then ran the Python script, attempting to connect to "wss://api.mydomain.com/socket"
. However, i received an exception
I'm unsure if I'm missing any steps to setup the tunnel with WebSockets or if it's a certification issue: I'm using a self-signed certificate but with noTLSVerify
I thought that it wouldn't matter
Any help would be great, I can provide any additional info if needed about network traffic, headers, etc
Thanks1 Reply
Since I'm using WSS, I'm also unsure if there's something else I need to forward apart from 7777: I heard WSS also uses port 443 since it has something to do with HTTPS? I don't know anything at all about networking so I wasn't really sure
Small update: Trying with the service
tcp://localhost:7777
does have my Unity server acknowledge the connection, stating the TLS handshake failed at step 1 (so the client hello probably wasnt even accepted, which is strange)
The Python socket script now gives the error
So I may be on the right track but I'm still missing something since with the exact same script but instead sending to wss://localhost:7777
, I receive a valid response from the server so the issue isn't with the data I'm sending
(could be headers, not sure how to proceed with that theory)
Hm it seems like its rather that the server is sending a server hello, but the ws isn't bidirectional
Is there an issue with my configuration that allows the socket to be created but not for outgoing messages to be sent to connected listeners?
Some more info when running cloudflared
with `--loglevel debug
Cancelled by local would indicate a Unitiy issue, but again if the same script just opens the socket and sends the payload to localhost:7777
instead of my domain it works
Nvm, just had to use HTTPS as my service and remove the path