ngrok with websocket does not work, Sec-WebSocket-Accept not found

537 views Asked by At

I have a webserver that sits behind .ngrok.io that works when i connect to it through ws://.ngrok.io/ws/ with websocket.org

I also have a device that can connect to either my webserver or the echo.websocket.org server.

Why is it that when i connect my device to ws://****.ngrok.io/ws/ I get a "TRANSPORT_WS: Sec-WebSocket-Accept not found", but this does not happen when i use echo.websocket.org. I've changed nothing to my device (embedded board using ESP-IDF) other than the address.

is there a setting missing in my ngrok? my cmdline is ./ngrok http http://0.0.0.0:8000 In the ngrok terminal, it doesn't look like it even detected a GET /ws/ connection, it remains blank.

interestingly, if i remove my /ws/ path in my device, ngrok is able to see a connection but it is routed wrong (because my server uses /ws/ path for websocket)

1

There are 1 answers

1
Golden thrust On

If you want to use ngrok for WebSocket, you should use the 'tcp' parameter because WebSocket operates on TCP, not HTTP.

ngrok tcp http://0.0.0.0:8000

Use the generated URL and replace 'tcp://' with 'ws://'. WebSocket functions as a server and is not accessed through HTTP.