Test client server
nc
can be used to rudimentarily test a client-server scenario.
In a shell, the «server» is started using
-l
to indicate the
port where the server is listening.
-q 1
tells the server to quit if it doesn't receieve any input from a client within 1 second after deliering the message (here: «hello from server):
$ echo 'hello from server' | nc -l 1234 -q 1
After the server is started, a client is started in another shell that connects to port 1234, then prints the message received from the server and then delivers another message («this is the client») to the server:
$ echo 'this is the client' | nc localhost 1234 -q 1
hello from server
Going back the the first shell, we see the server having printed the message from the client:
this is the client