Write a program or function that listens for incoming TCP traffic on port N. It offers a simple service: it calculates sum of IP address fields of incoming connection and returns.
Program or function reads integer N from arguments or stdin. It listens to incoming TCP connections on port N. When someone connects to that port, the program calculates sum of its IP address fields and sends it back to the client with trailing newline and closes connection.
- Port number N is a valid port, and 210 < N < 215
- Trailing newline can be either
- You can use either IPv4 or IPv6. Since IPv6 addresses are written in hexadecimal form, you must also provide result in same format, for example
2001:0db8:0000:0042:0000:8a2e:0370:7334 => 12ecd.
This is code-golf. Standard rules and loopholes apply.
You run your server with
./server 1234. The server is now running and waiting for connections on port 1234. Then a client from
127.0.0.1 connects to your server. Your server performs a simple calculation:
127+0+0+1 => 128 and sends the result to the client (with trailing newline):
128\n. Then server closes connection and waits for next client.