9.2 Investigating Protocols with Telnet
In this chapter, you'll see
that use sockets to communicate with a number of well-known Internet services such as HTTP, echo, and more. The sockets
are simple enough; however, the protocols to communicate with different servers make life complex.
To get a feel for how a protocol operates, you can use Telnet to connect to a server, type different commands to it, and watch its responses. By default, Telnet attempts to connect to port 23. To connect to servers on different ports, specify the port you want to connect to like this:
telnet localhost 25
This example assumes that you're using a Unix system. However, Telnet clients are available for all common operating systems, and they are all pretty similar; for example, on Windows, you might have to type the hostname and the port into a dialog box rather than on the command-line, but
, the clients work the same.
a connection to port 25, the SMTP port, on the local machine; SMTP is the protocol used to transfer email between servers or between a mail client and a server. If you know the commands to interact with an SMTP server, you can send email without going through a mail program. This trick can be used to
email. For example, a few
ago, the summer students at the National Solar Observatory in Sunspot, New Mexico, made it appear that the party one of the scientists was throwing after the annual volleyball match between the staff and the students was in fact a victory party for the students. (Of course, the author of this book had
nothing to do with such despicable behavior. ;-) ) The interaction with the SMTP server went something like this; input the
types is shown in bold (the
have been changed to protect the gullible):
telnet localhost 25
Trying 127.0.0.1 ...
Connected to localhost.sunspot.noao.edu.
Escape character is '^]'.
220 flare.sunspot.noao.edu Sendmail 4.1/SMI-4.1 ready at
Fri, 5 Jul 93 13:13:01 MDT
250 flare.sunspot.noao.edu Hello localhost [127.0.0.1], pleased to meet you
MAIL FROM: bart
250 bart... Sender ok
RCPT TO: email@example.com
250 firstname.lastname@example.org... Recipient ok
354 Enter mail, end with "." on a line by itself
In a pitiful attempt to reingratiate myself with the students
after their inevitable defeat of the staff on the volleyball
court at 4:00 P.M., July 24, I will be throwing a victory
party for the students at my house that evening at 7:00.
Everyone is invited.
Beer and Ben-Gay will be provided so the staff may drown
their sorrows and assuage their aching muscles after their
250 Mail accepted
221 flare.sunspot.noao.edu delivering mail
Connection closed by foreign host.
of the staff asked Bart why he, a staff member, was throwing a victory party for the students. The moral of this story is that you should never trust email,
patently ridiculous email like this, without independent verification. The other moral of this story is that you can use Telnet to simulate a client, see how the client and the server interact, and thus learn what your Java program needs to do. Although this session doesn't
all the features of the SMTP protocol, it's sufficient to enable you to deduce how a simple email client talks to a server.