In man addrinfo
there is example code for an UDP server.
I compiled that code, and run it on a terminal using a.out 9001
.
On a second terminal I run netcat 127.0.0.1 9001
, hoping that that will open an interactive session with the local server.
And one of the times I tried it did right that, and I could write messages that would be echoed by the server, through in the first terminal the server would not print the received messages as I expected.
But all other times the netcat command just executes and nothing happens. No error message nor output.
This is what there is in the terminal:
jsevillamol@jsevillamol-N551JK:~/Documentos/C$ netcat 127.0.0.1 9000
jsevillamol@jsevillamol-N551JK:~/Documentos/C$ netcat 127.0.0.1 8000
hola
hola
hola
hola
test
test
do not copy me
do not copy me
^Z
[4]+ Detenido netcat 127.0.0.1 8000
jsevillamol@jsevillamol-N551JK:~/Documentos/C$ netcat 127.0.0.1 9001
jsevillamol@jsevillamol-N551JK:~/Documentos/C$ netcat 127.0.0.1 9002
When I bond to 8000 is when the interactive session seemed to be working.
Also, after stopping the server I cannot run the program again using the same port.
What is going on?