Run these in 2 terminals, after ncat is installed:
$ ncat -l -p 9999
And on the other one:
$ echo Hello | ncat localhost 9999
$ ncat -l -p 9999
This command tells ncat
to listen on port 9999. We could have chosen any port between 1025 and 65535 that another program isn't already listening on.
In another terminal:
$ cat ~/.bashrc | ncat localhost 9999
This command sends the contents of your ~/.bashrc
file over a TCP connection to your computer's port 9999 -- which of course your first terminal is listening on.
To view this traffic flow over the (loopback) network interface, use tcpdump
:
$ sudo tcpdump -vXxns 0 -i lo 'port 9999'
$ echo -e 'GET / HTTP/1.1\r\n\r\n' | ncat checkip.dyndns.org 80
Notice that if you visit http://checkip.dyndns.org in your browser, then right-click and View Source, you'll see that the body of the web page you visited matches the end of ncat
's output