I'm on a debian-based Linux distro and currently testing and learning about some networking stuff.
So I have 3 terminal open, the first 2 I will run this command to set up 2 netcat servers on port 12345 (based on my research this is possible without getting any error in some systems)
nc -lp 12345
And the 3rd terminal I run this command to connect to the netcat servers
nc localhost 12345
In the 3rd terminal after I ran the command, I typed some random string there and observed the other 2 terminals. Only the terminal that run the netcat server first will receives the text that I typed, the other one will just hang there and didn't output anything.
I tried googling to find out why is this the case but most of the results are about how/why setting applications to run on the same port is possible, but not about the order of receiving request data in this situation
I also tried ask ChatGPT about this one, and it mentioned "Bind in a "weird" passive state but not actually receive traffic (depends on implementation)" to the 2nd netcat servers, which is quite of vague
I also used the this command to print out networking data in my machine and both servers actually occupy the port 12345 for 0.0.0.0
$ netstat -tuldp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:12345 0.0.0.0:* LISTEN 58958/nc
tcp 0 0 0.0.0.0:12345 0.0.0.0:* LISTEN 58941/nc
Can someone explains why there is an order despite both occupying the same hostname and port