Having just solved the thorny issue of port communication between WSL 2 and Windows, I felt it was time to take a good look at the past year or two of love and hate using WSL for my future review. Also convenient predestined person steps on a few pit less.

Search for related articles by “WSL” or “front-end WSL”. From my intuition, it seems that they are basically just starting to install a development environment. Or more on the back end? In the spirit of fidgeting, THIS time I’m going to share my own experience, which should be updated here (hopefully)

WSL installation

There are plenty of articles on WSL installation, but here’s a look at the section on WSL2 as a productivity tool, focusing on enabling and configuring WSL2. After the system is installed, there are several points to note:

  • Windows Terminal is quite recommended
  • Failed to pass silently because VS Code was installed on a non-system diskcodeCommand startup to start the project in WSL, again it is recommended to install VS Code on system disk
  • It is recommended to use NVM to manage node versions

Why not use WSL 1?

I’ve been using WSL 1 since before WSL 2 was officially released, and one of the creepy issues I had was that renaming files or folders would give me an error during development. My stupid solution was to delete the previous file or folder and then copy and paste it…

When I learned WSL 2 solved this disgusting problem, I didn’t hesitate to migrate to WSL 2. For more on the comparison, of course, read the official note.

WSL communicates with Windows

Preliminary through

[WSL 2] WSL 2 cannot access Windows Service via localhost:port because the proxy service is running on Windows, So there was a need for WSL to use services on Windows, and it took a long time to figure out a solution like Winhost, with scripts and administrator privileges.

The funny thing is that some time ago, a big guy shared a simple and direct hostname. Local :port scheme, so I quickly abandoned winhost so difficult to use the scheme. Just when I thought everything was going well, something happened.

Windows cannot access some WSL ports

This is the question that haunts me tonight! The plan was to get familiar with the Remix framework tonight, but Hello World was awkward: modifying the code on the Windows browser when accessing the page triggered recompilation but did not trigger Live Reload.

Have no clue in the Issues of Remix, suddenly a port monitor error prompt let a person be overjoyed, hurriedly look, the result code is not a problem, a basin of cold water come is really fast, happy not a few seconds _(:з “Angle)_ but noticed that the console prompt WebSocket connection failure. This leads to another heart-piercing question: why is there no problem accessing the page through port 3000 on Windows, but hanging up when connecting to WebSocket through port 8002?

Port usage:

  • Windows: netstat -ano | findstr ${port}
  • WSL/Ubuntu:
    • netstat -ap | grep ${port}
    • lsof -i:${port}

Flag: Do study one seriously when you have timenetstatlsofCommand)

It is confirmed that port 3000 and port 8002 are occupied in WSL, but only port 3000 is occupied in Windows. Again, it’s the magic of WSL. Host can access partial ports wsl2 Single wsl2 localhost port can’t be email exchange with factcheck.org from Windows Side. One person gave me a deeper insight into WSL:

  • netsh int ipv4 show excludedportrange protocol=tcpView ports reserved by Windows
  • netsh int ipv4 show dynamicport tcpView Windows port boot range

I found 8002 was reserved by Windows, changed a port 8113 was not reserved, page hot reload!! (Laughing and angry, “fuck”, while hitting the table with an iron fist)

In addition, the previous Vite development through http://localhost:8000/ access to the service, this time also found that it is in the Windows reserved port, it seems that WSL and Windows communication related issues can be a small front end of my understanding? A guess, not a certainty

conclusion

When I first heard about WSL, I had an idea to try it out. I had the same energy as when I was young (in high school) and struggled with android. Now WSL has become the core system for my work and study, and now I have the opportunity to learn Linux seriously. In addition, I used a MacBook for development in my last job, but I still couldn’t get used to it (bad use, especially key mapping) for more than a year. I can only say Windows, YYDS! (Don’t spray if you don’t like it

A noteworthy problem. I tried to develop electron application through WSL 1 before, and found an article that wanted to configure WSL to tune up the visual interface service, but it failed for a long time and was temporarily shelved. So maybe the next challenge is WSL 2 developing eletron applications?