Search code examples
visual-studio-codesshportforwardingssh-tunnel

How does VS Code automatically detect port allocated by the command and start port forwarding it when working remotely?


I know that this question look similar to VSCode [Remote Development] [Forward Port] work? but it isn't.

When I launch a command which starts a web server on a random port (and prints out the url to access it),

VS Code auto detects the newly allocated port and starts port forwarding that port to my host machine.

How does this happen? Does VS Code check for newly allocated port by the current command ? If so, how does the shell script for this look like ?


Solution

  • This has been answered by VSCode developer on github here.

    To summarize, VSCode will actively look into the proc file system ie. /proc directory and detect the port that was allocated and then start auto portforwarding it.