WebSocket Cannot Be Established Due to Proxy
I’ve been working on building a visual studio code extension for a better-developing experience on ESP32, MicroPython. But without any basic knowledge of front-end development, this process is quite tough for me.
To establish a wireless connection, the first thing that came to my mind is that I should check the official tools. So I checked the source code of project webrepl, a WebREPL terminal client, which also has a coarse front-end written in Javascript.
Problem
It seemed to be simple to connect to the webrepl server running on the board, as the code in webrepl.html showed. But when I was using the npm package ws
or websocket
in Typescript to connect to it, the connection was simply cannot be established. The error in the serial connection illustrated that
1 | Traceback (most recent call last): |
At first, I thought it was just like ordinary problems, parameters, policies, etc. So I applied WireShark to check the difference between the packets sent by webrepl and the Typescript extension written by myself.
Using the ws
package to connect:
Using Javascript WebSocket
to connect to the board:
Having no idea which options to alter, I referred to the MicroPython project to find out. But the code shows that’s nothing to do with the options.
1 | webkey = None |
But how can webkey == None
happen? The two packets both have Sec-WebSocket-Key
in their fields.
Solution
Fortunately, one of my teammates found that the client was assigned with Go-client
, and it was our proxy server Clash For Windows that modified our packet. And turning off the proxy worked.