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
- hostname: api.mydomain.com
    path: /socket
    service: wss://localhost:7777
    originRequest:
      websocket: true
      noTLSVerify: true
      connectTimeout: 30s


I then ran the Python script, attempting to connect to "wss://api.mydomain.com/socket". However, i received an exception

websockets.exceptions.InvalidMessage: did not receive a valid HTTP response


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
Thanks
Was this page helpful?