The Word From Abroad
This is a get-started assignment for using the
Cleansocks
library. You are to create a simple program which is a client for
Quote of the Day protocol, defined in
RFC 865.
This is testing service, and there's not much too it:
When the client connects to a qotd service, the server sends it a
short message, then disconnects. Such a server is running on
sandbox.mc.edu.
The quote service runs on port 17,
so, if you have
nc installed, you can do this:
[tom@tomslap ~]$ nc sandbox.mc.edu 17
Parents often talk about the younger generation as if they didn't have
much of anything to do with it.
[tom@tomslap ~]$
This exercise is to
build a program using the
Cleansocks
API which will connect using TCP to port
17 on the indicated server, read the quotation, and print it out, with
the small modification of adding two dashes and a space at the front
of each line.
[tom@localhost qotd]$ ./qcli5 sandbox.mc.edu
-- Some people carve careers, others chisel them.
[tom@localhost qotd]$ ./qcli5 sandbox.mc.edu
-- If opportunity came disguised as temptation, one knock would be enough.
[tom@localhost qotd]$ ./qcli5 sandbox.mc.edu
-- Any clod can have the facts, but having opinions is an art.
-- -- Charles McCabe
[tom@localhost qotd]$ ./qcli5 sandbox.mc.edu
-- "There was a boy called Eustace Clarence Scrubb, and he almost deserved it."
-- -- C. S. Lewis, "The Chronicles of Narnia"
[tom@localhost qotd]$ ./qcli5 sandbox.mc.edu
-- Envy, n.:
-- Wishing you'd been born with an unfair advantage,
-- instead of having to try and acquire one.
[tom@localhost qotd]$ ./qcli5 sandbox.mc.edu
-- Whitehead's Law:
-- The obvious answer is always overlooked.
[tom@localhost qotd]$ ./qcli5 sandbox.mc.edu
-- George Orwell was an optimist.
[tom@localhost qotd]$ ./qcli5 sandbox.mc.edu
-- If you are good, you will be assigned all the work. If you are real
-- good, you will get out of it.
Some quotes are witty, and there are definitely some of the other kind.
Your program should meet the following requirements:
Hints
- Feel free to start with one of
the
posted
examples
and modify it. (Probably not the server.)
- The lookup_service call will accept either the number
or the name.
- The RFC does not specify how line breaks are coded in the text
the server sends you. The server on Sandbox always separates lines
with \r\n, but plain \r or plain \n is also possible.
make sure your code is flexible.
- You may read the data with recv or recvln or a combination,
as you see fit.
- The posted textbook examples simply die with the uncaught exception
when an cleansocks call fails.
You should catch the exceptions and print an error message including
the text of the what() method from the exception.
- Make sure to read from the server in a loop. There is no guarantee
that the entire message will arrive in a single recv. You will need to
put recv in a loop and read until you reach the end of the message.
- Finally, note that data recovered from recv or recvln does
not have a plain C string terminator at the end of it, so it is not
a legal plain C string. You can either arrange to add a terminator,
construct a C++ string using the explicit length, or handle the data as
an array instead of a string.
- As noted, sandbox runs a qotd service which you may use for testing.
Googling “public qotd server” turns up a few others, which
should also respond to your client.
Submission
When your program is working, nicely commented and properly indented,
submit it using the form
here.