set -x # ask the shell to print out what is going on # This is a simple script that demonstrates ‹nc› in listening mode. # To wit: port=2222 nc -l $port > file.txt & # Now unlike most of the things we did earlier, you may not be able # to run this script. That's because port numbers are a global, # shared resource, and if one person is listening on port 2222 on # ‹aisa›, this port is no longer available for others. You may want # to try with a different port number (must be greater than 1024, # too). But since the script is brief, you might get lucky. # Now let's send something to the listening ‹nc› using another ‹nc›, # this time in client mode: echo "hello world on port $port" | nc localhost $port # ‹localhost› is a special name, reserved to mean ‘this computer’. # But we could have used ‹aisa.fi.muni.cz› just fine, too. Anyway, # let's check the content of file.txt: wait # wait for the backgrounded ‹nc -l› to finish cat file.txt # print the content of the file # Let's do another exercise: ‹2.txt›.