Documentation ¶
Overview ¶
This program extends part 4.
It listens on an available public IP and port, and for each incoming connection it decodes JSON-encoded messages and writes them to standard output. It simultaneously makes a connection to the host and port specified by -peer, reads lines from standard input, and writes JSON-encoded messages to the network connection. The messages include the listen address. For example:
{"Addr": "127.0.0.1:41232", "Body": "Hello"!}
You can test this program by listening with the dump program:
$ dump -listen=localhost:8000
In another terminal, running this program:
$ part5 -peer=localhost:8000
And in a third terminal, running part2 with the address printed by part5:
$ part2 -dial=192.168.1.200:54312
Lines typed in the third terminal should appear in the second, and those typed in the second window should appear in the first.