'Netcat localhost command not working on WSL 2.0 Ubuntu

I'm using netcat to practise my network lessons' exercises. I need to access to my localhost port 7777 using the following command on the prompt:

nc localhost 7777

I'm using wsl 2.0 on Windows 11, idk if that is the problem because as far as I know, it worked properly after upgrading to W11. When I put the command, the usual is that I can see what is happening on that port, but now it's like it closes immediately and doesn't allow me to hear on that port. Do you know how to solve it? Thanks in advance



Solution 1:[1]

You need to listen from one end. So you have to issue two commands :

nc -l localhost 7777

and in another terminal session

nc  localhost 7777

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 frhack