RFC 867 defines the very simple daytime protocol. This protocol reports the current time, and is generally considered obsolete. The current way to fetch time over the net is using the NTP (RFC 5905), which is far more precise, and definitely not a hello-world level networking client. However, there are a few somewhat change-resistant parties which still operate RFC 867 servers, including myself and the government of the United States. This assignment is to create a simple client for that protocol. Your client should take the name of the server and print the time it reports, for instance:
RFC 867 is very simple: When a client connects on port 13, the server sends a string containing the date and time, then disconnects. It ignores anything sent by the client. As you might guess from the above example, the RFC does not specify the format of this string.
The assignment is pretty simple, because all you actually need to do is connect to port 13, read and print whatever the server sends, then close and exit. Use the Cleansocks library to create your simple command-line client. You can steal most of the code from this example. (So the biggest issue is actually making the library work.)
Your program should:
You can test your program with any service running the daytime protocol. The NIST server at time.nist.gov is available as shown above. I have noticed that sometimes the government server will close your connection without sending anything. You might need to run it a couple of times to be sure.
The server on Sandbox works fine, but it seems to only be reachable from the on-campus wired network. One way is to simply work on Sandbox itself. Excellent connectivity there. Another way, if you have ssh installed, and an account on Sandbox, is create a temporary tunnel. Open an extra command window, and run this command as root:
If you have a Linux setup, you can run your own daytime service by installing the xinetd package and enabling the service in /etc/xinet.d/daytime-stream. Then use systemctl start xinetd.service to start it. You should be able to access this via host name localhost.
If you're curious about the format of the NIST time string, It's here.