Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Exploring Internet Communication Protocols: SMTP and POP using Java and TCPCapture, Lab Reports of Computer Science

In this lab, students will explore the operation of communications services provided through the internet by using existing applications and a short java program. The focus will be on smtp (simple mail transfer protocol) and pop (post office protocol), two widely used protocols for sending and receiving email. Students will use bluej, the ide, to enter and run a simple java program and intercept packets using tcpcapture to inspect messages exchanged between the apple mail program and the email server.

Typology: Lab Reports

Pre 2010

Uploaded on 08/16/2009

koofers-user-6s4
koofers-user-6s4 🇺🇸

10 documents

1 / 14

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Lab 1: Exploring Internet Email Protocols and BlueJ
Due: Friday, 9/5
In most of our labs this semester, you will be writing Java programs that explore the operation of commu-
nications services provided through the Internet. This lab, however, will be a bit different. You will still
be exploring Internet communication mechanisms and Java programs, but you will do it using existing
applications and a short Java program we will provide rather than by writing a program of your own.
In this lab you will learn about two important Internet email protocols by experimenting with their opera-
tion in various ways. The protocols we want you to explore are SMTP (Simple Mail Transfer Protocol),
which is the standard protocol used to send email messages, and POP (Post Office Protocol), which is one
of two protocols that are widely used by mail clients when you are reading your email.
You will also use BlueJ, the IDE (Integrated Development Environment) we will be using in labs
throughout the semester, to enter and run a simple Java program. The goal of this exercise will be to give
you some concrete experience with the mechanics of entering and running a program so that you can bet-
ter appreciate the introduction to Java we will present in class.
There are several things you should do to prepare for this lab. First, however, we want to tell you some-
thing you do not have to do before lab. You do not have to read the entire lab handout. You only have to
read the first page. For most of the other labs in this course, carefully reading the entire lab handout be-
fore coming to lab will be an extremely important part of your preparation for lab. This week’s lab hand-
out, however, is designed to function as a tutorial. As you read through most of the handout, you will be
expected to perform the operations it describes using one of the computers in our lab. You may want to
skim the handout a bit before you come to lab but don’t waste time reading beyond the first page.
On the other hand, this lab will assume that you are familiar with the readings assigned from the course
reading packet. The readings for this lab are Chapter 1 and the first section of Chapter 4 of “Program-
ming with Java, Swing and Squint” before coming to lab.
Finally, there is something very simple you can do to make the lab go smoothly. Special accounts for
each of you have been created on our department’s server. During lab, you will be using the account to
send and read email messages. Before starting the lab, you should send a few email messages using your
usual university email account (via whatever web interface you like) to this account. The addresses for
the account look like
cs150_01@cauchy.richmond.edu.
Eighteen such accounts have been created (with names cs150-01 through cs150-18). We will assign each
of you an individual account at the beginning of the lab.
If you want some variety, feel free to have some friends send some mail to this account as well. Be sure,
however, that you don’t send too many messages to this account. The main reason we are using accounts
on our server rather than having you use your standard UR email account is to avoid having to process too
many messages. During the lab, you will be monitoring conversations between a mail program and our
mail server. If you have too many messages sent to your account, the number of packets you intercept
when you monitor the conversation between the Mail program and our mail server will be overwhelming.
Having somewhere between 4 and 8 messages sent to your cauchy.richmond.edu account before lab
would be great.
CS 150 Fall 2008
1
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe

Partial preview of the text

Download Exploring Internet Communication Protocols: SMTP and POP using Java and TCPCapture and more Lab Reports Computer Science in PDF only on Docsity!

Lab 1: Exploring Internet Email Protocols and BlueJ

Due: Friday, 9/ In most of our labs this semester, you will be writing Java programs that explore the operation of commu- nications services provided through the Internet. This lab, however, will be a bit different. You will still be exploring Internet communication mechanisms and Java programs, but you will do it using existing applications and a short Java program we will provide rather than by writing a program of your own. In this lab you will learn about two important Internet email protocols by experimenting with their opera- tion in various ways. The protocols we want you to explore are SMTP (Simple Mail Transfer Protocol), which is the standard protocol used to send email messages, and POP (Post Office Protocol), which is one of two protocols that are widely used by mail clients when you are reading your email. You will also use BlueJ, the IDE (Integrated Development Environment) we will be using in labs throughout the semester, to enter and run a simple Java program. The goal of this exercise will be to give you some concrete experience with the mechanics of entering and running a program so that you can bet- ter appreciate the introduction to Java we will present in class. There are several things you should do to prepare for this lab. First, however, we want to tell you some- thing you do not have to do before lab. You do not have to read the entire lab handout. You only have to read the first page. For most of the other labs in this course, carefully reading the entire lab handout be- fore coming to lab will be an extremely important part of your preparation for lab. This week’s lab hand- out, however, is designed to function as a tutorial. As you read through most of the handout, you will be expected to perform the operations it describes using one of the computers in our lab. You may want to skim the handout a bit before you come to lab but don’t waste time reading beyond the first page. On the other hand, this lab will assume that you are familiar with the readings assigned from the course reading packet. The readings for this lab are Chapter 1 and the first section of Chapter 4 of “Program- ming with Java, Swing and Squint” before coming to lab. Finally, there is something very simple you can do to make the lab go smoothly. Special accounts for each of you have been created on our department’s server. During lab, you will be using the account to send and read email messages. Before starting the lab, you should send a few email messages using your usual university email account (via whatever web interface you like) to this account. The addresses for the account look like cs150_01@cauchy.richmond.edu. Eighteen such accounts have been created (with names cs150-01 through cs150-18). We will assign each of you an individual account at the beginning of the lab. If you want some variety, feel free to have some friends send some mail to this account as well. Be sure, however, that you don’t send too many messages to this account. The main reason we are using accounts on our server rather than having you use your standard UR email account is to avoid having to process too many messages. During the lab, you will be monitoring conversations between a mail program and our mail server. If you have too many messages sent to your account, the number of packets you intercept when you monitor the conversation between the Mail program and our mail server will be overwhelming. Having somewhere between 4 and 8 messages sent to your cauchy.richmond.edu account before lab would be great.

Part I: Exploring Email Protocols

You will use three programs to explore how some of the mail protocols used within the Internet function: Mail: The standard mail client provided with Apple’s Macintosh operating system. You will use this program to send and read some email messages using the mail account we have created for you on our department’s server. TCPCapture: This is a program we have constructed which allows you to intercept and inspect messages sent from your machine through the Internet. You will use it to determine exactly what messages are exchanged between the Apple Mail program and our email server when you send messages and check your mail. You may have noticed a bit of a vocabulary problem here. In order to send an email message, a client program sends several messages of its own. It is confusing to use the word “message” for both sorts of communications. So in the rest of this handout we will use the word “message” only when talking about actual email messages. We will use the term “packet” to refer to the smaller, individual communications sent between clients and servers. NetTap: This is a program we have constructed that allows you to exchange packets directly with a re- mote server rather than depending on a client program like a mail program or a web browser. Af- ter having seen the packets the Apple Mail program uses to communicate with a mail server, you will use this program to communicate with the mail server directly.

Configuring Your Account

The first step you need to complete for this lab is to configure the preferences for the Mail to allow it to connect to the mail server. We will lead you through this process in some detail in recognition of the fact that some of you may not have previous experience with the Macintosh interface. We will expect you to become comfortable with this interface quickly because we will not provide the same level of step-by- step instructions in future labs. First, log in to one of the machines in our lab by entering your usual university user name and password. Once you have logged in, your computer display should look something like the image shown below.

We want to configure the Apple Mail program to use your account on our mail server. We want to do this without letting the program actually go and fetch your mail. We want to keep it from doing this until we are ready to run the TCPCapture program so that we can watch the conversation between the Mail client program and our server. So, as you follow the steps to configure your account we will instruct you not to enter your password at one point when the configuration process asks for it. This will keep the program from being able to contact the server until you want it to. So, in the first configuration step (the window above) you should enter “ur” in the “Full Name” field, and the email address you have been assigned for this lab in the “Email Address” field. Leave the password blank and press “Continue”.When the Mail application opens, it should first display a window informing you that it wants to guide you through the process of setting up your mail account. Click “Continue.” The next box you get looks like this: Choose account type “POP” (which stands for “post office protocol”) in the “Account Type” field. Enter “cauchy.richmond.edu” (this is case sensitive) as the incoming mail server, and your assigned user name as the username. Leave the password field blank. Press Continue. Because you have not entered a pass- word, you will receive an error message (shown below). Ignore this by pressing Continue.

Next, Mail will display a window asking questions about incoming mail security (shown below). Make sure that “Use Secure Sockets Layer” is UNCHECKED and press Continue. You now need to configure the outgoing mail server. Enter “cauchy.richmond.edu” as the outgoing mail server, and be sure the “Use only this server” is checked.

The last thing you need to do to get Mail set up is to change the port number that Mail uses. To do this, click on the Mail -> Preferences menu item (be sure that Mail has the focus when you do this). Click on “Accounts” and then the “Advanced” tab to get a window like the one shown below. Enter the number 25 in the port field, then click on the red dot in the upper left hand corner of the window and save the changes you made (Mail prompts you with a window). Mail is now set to use the special lab accounts.

Using TCPCapture

Our next step is to start running the TCPCapture program. This is not a standard application pro- gram. In fact, it makes some people nervous to have it around at all since it has the potential to snoop on network traffic. To start TCPCapture, go to the Applications folder in the Finder window, and scroll down until you see TCPCapture. Click- ing on it will open the application. Immediately after you launch TCPCapture an odd looking window containing some messages that talk about your last login will appear. Ignore this (In fact, once the actual program is running you might want to close this window by clicking once in the red circle in its upper left corner). Moments later, a window like the one shown on the right should appear. This is the TCPCapture program’s window.

Near the top of the window is a menu that will initially display “HTTP.” These are the initials for “Hy- pertext Transfer Protocol,” the protocol used to talk to web servers. The program is capable of intercept- ing packets sent using five different protocols, but it is designed to only work with one protocol at a time. This menu controls which one. We want to look at the packets sent when the SMTP protocol is used to send outgoing mail. So, you should change the setting of this menu to “SMTP.” Once you have done this, click the “Start” button. The program will now display any SMTP packets sent to or from your ma- chine. The little cow icon at the top of the program’s window will start running to indicate that it is ac- tively monitoring network traffic. Click on the icon for the Mail program in the dock to bring the program’s window to the top of your desk- top. Let’s send a mail message. If you want, send one to your own account at cauchy.richmond.edu. If you are feeling friendly, send it to the cauchy.richmond.edu account for the person sitting next to you. It is easy to do. Just click on the “New” button in the Mail program’s window. Fill in the “To” field (make sure the address you use ends with “@cauchy.richmond.edu”) and add any message or subject you would like (keep it short). Then press “Send.” Once this is complete, bring the TCPCapture win- dow back to the top of your desktop (if it has be- come buried under other windows you can just click once on its icon in the dock). It should now look something like the image shown on the left. The program’s window is now filled with a series of cryptic lines of text. Each of these lines corresponds to a packet sent between the mail client program and our department’s email server. The lines that start with “cauchy.richmond.edu -> CLIENT” correspond to packets that travelled from our server to your ma- chine. Lines that start with “CLIENT -> ...” corre- spond to lines your machine sent to our server. Ob- viously, sending just a single email message in- volves sending many smaller packets through the network. The remaining text on each line of the display pre- sented by TCPCapture shows the contents of the packet that was actually sent. For example, the first packet sent from the client to the server was: EHLO lh205123.richmond.edu which might translate into english roughly as “Hello, I’m lh205123.richmond.edu”. Some of the packets sent between the client and server are too long to fit on one line of the screen. They are truncated in the summary display, but there is a way to see the entire contents of such packets. If you click once on the summary line for a packet, its complete contents will be displayed in the region at the bottom the the TCPCapture window. For example, near the end of the exchange between the client and server there should be a packet containing the text 354 Enter mail, end with “.” on a line by itself If you click on the line immediately below this packet, the program’s window should display something that looks like a standard email message. (It probably isn’t surprising that one of the packets exchanged between a client and a server when sending an email message actually contains the email itself!)

To illustrate this fact, we have constructed a simple program that isn’t a mail client but can be used to send packets to an SMTP server. The program is named NetTap.jar. Like TCPCapture, it can be found in the Utilities folder within the Application folder on each of the machines in the lab. Find NetTap and double-click on its icon to launch the program. A win- dow like the one shown on the right should appear once the program has started. Near the top of the program there is a text field labeled “Server name:” You should type the name of the server to which we want to send packets, cauchy.richmond.edu, into this field. When a packet arrives at a server machine, the machine needs some way to figure out which program should be expected to process and respond to the packet. A single ma- chine might be running several dif- ferent server programs at the same time. For example, cauchy.richmond.edu is constantly running a POP server program, an SMTP server program and an HTTP (web) server. When this machine receives a packet it needs a way to decide which of these three pro- grams is the intended destination for the packet. This is accomplished by associating a standard “port number” with each protocol. A port number is a bit like a telephone extension number. When a packet is sent it is addressed not just to a machine but to a particular port on that machine. The port number associated with the SMTP protocol is

  1. By default, NetTap assumes this is the port number to which you would like to send packets. Later, when you experiment with the POP protocol, you will have to enter its port number (110) so that the packets sent by the program will be delivered to the POP server program. There is one last step before you can start exchanging packets with the server. You need to “connect” to the server. A good analogy is the way you have to dial and wait until your call is connected before you can start talking on a telephone. Once the server name and port information has been provided, you can connect NetTap to the indicated server by simply pressing the “Connect” button. If you look back at the TCPCapture window in which you intercepted the packets sent between the Apple Mail program and our mail server, you will notice that the first packet was sent from the server to the cli- ent. The packet sent started with the code 220 indicating the server was ready. If you wait just a bit, you will notice that a similar packet is now sent from the SMTP server to the NetTap program. Once it ar- rives, the program will display the packet received in its window preceded by a “<-” to indicate that it is an incoming packet. After sending the “ready” packet, the server waits to receive an “EHLO” packet from the client. You can send the expected packet using NetTap by typing the text of the packet into the field to the right of the “SEND” button and then pressing “SEND.” Feel free to cheat and copy the text of the packet from the dialogue you recorded using the TCPCapture program. Do this by highlighting an individual line and copying and pasting using the text that appears in the lower window pane. The packet will be sent to the

server and displayed in the NetTap window preceded by the symbols “-> “. If you typed the packet cor- rectly, a series of “250” response packets should be received from the server. Continue to mimic the dialogue you recorded using TCPCapture in this way until you have sent the “DATA” command. Make sure that you receive a 250 response to each line you enter (except the DATA command) before moving on to the next line. After receiving the DATA command, the server expects you to send the body of the email message you want delivered. The Apple Mail program (and most other real email clients) include many things in addi- tion to the text of the message including a subject line and the date the message was sent. You don’t need to mimic all this. Just enter the message you want to send line-by-line and enter a line containing a single period when you are done. That’s it. You have just sent an email message without the help of an email program! Later on in the lab, we will check to make sure it was actually delivered by using the Apple Mail program to check all the mail that has been sent to your CS mail account. For now, either press the “Disconnect” button or send the server a “QUIT” command to terminate your conversation. If you left TCPCapture running while you were using NetTap (you probably were since we never told you to stop it), you might want to take a look at the packets it captured while you were using NetTap.

Experimenting with POP

We can also use TCPCapture and NetTap to explore the function of one of the protocols used to retrieve email, the POP protocol. This time, we will approach the process in the opposite order. First, you will learn about the types of packets that can be sent to a POP server by entering them yourself using NetTap. Then, you will use TCPCapture to see how the Apple Mail program actually uses this protocol (and be- fore doing so, you will need to reset the port number to 110 using the same Mail preferences steps that you used above). Like SMTP, the POP protocol requires that the client start each packet it sends to the server with a four letter command name. The commands you will need to use in this lab and their functions are discussed below. As with SMTP, if you wish to learn more, you might either read the Wikipedia discussion of POP: http://en.wikipedia.org/wiki/Post_Office_Protocol or read the official description: http://www.ietf.org/rfc/rfc1939.txt In this case, the official description is actually short enough that you may find it readable. The first two commands you will need are used to identify the account whose mail is to be accessed: USER - The first packet sent to the server should be composed of the code “USER” followed by a user name (such as cs150_01). PASS - The second packet sent to the server should be composed of the word “PASS” followed by the account password. (This is why we warned you that your password might appear on your com- puter’s screen during this lab.) When your are all done you will enter a very simple command: QUIT - This command requires no additional information.

We would like you to use TCPCapture to explore two questions about how the Apple Mail program uses the POP protocol. As your “report” for this lab, we ask that you turn in before class on Wednesday, a brief, typed paper including your answers to the following questions:

  • First, when you look at the TCPCapture window you will notice that the Mail program uses two com- mands we have not discussed, “UIDL” and “LIST”. How and why does Mail use these commands? You should base your answer on a combination of the information you can glean from the references we provided above and from experimenting with Mail and TCPCapture. In particular, it may help if you send yourself some more messages (or delete some messages), quit and restart the Mail application, and use TCPCapture to see what messages are exchanged when you tell Mail to get your new mail again
  • Second, what does the Mail program do when you tell it to delete a message? Again, use a combination of the references we suggested and your ability to experiment with TCPCapture to answer this question.

Part II: Exploring Email Protocols

In all of our remaining labs, you will be writing and running Java programs of your own. As a first step, today we would like you to become familiar with the process of entering and running a Java program us- ing the program discussed in Chapter 1 of the reading “Programming with Java, Swing and Squint.” Just in case you didn’t bring the course reading packet with you today, the text of the program is reproduced below: import squint.; import javax.swing.; public class TouchyButton extends GUIManager { private final int WINDOW_WIDTH = 150; private final int WINDOW_HEIGHT = 300; public TouchyButton() { this.createWindow( WINDOW_WIDTH, WINDOW_HEIGHT ); contentPane.add( new JButton( "Click Here" ) ); } public void buttonClicked() { contentPane.add( new JLabel( "I'm Touched" ) ); } } Using BlueJ to Enter and Run a Program Begin by launching the BlueJ application (just click on its icon in the dock – it’s the one with the Blue Jay on it). Once BlueJ is running:

  1. Select “New Project” from the BlueJ Project menu and use the dialog box that appears to navigate to the “Documents’’ folder in your account directory.
  2. Name your project. If your name happens to be Sally Floyd, then FloydLab1 would be a great project name. Make sure that your project folder name ALWAYS includes your name and NEVER contains blanks or special characters. Enter this name in the field labeled “File:” at the top of the dialog box.
  3. BlueJ should now display a project window with your project name in its title bar. Click the “New Class...” button in this window.
  1. BlueJ will display another dialog box asking you to name your class and to tell it what kind of class it is. Select “Class’’ for the type of the class. Name your class “TouchyWindow”.
  2. At this point, an icon with the name you picked for your class will appear in the project window. Double-click on this icon to display a window displaying the text of your class.
  3. Use the mouse and keyboard in the usual ways to place the text of the TouchyWindow program into this window. Because you told BlueJ that your class would be a GUIManager extension, its text will initially con- sist of a template that includes skeletal definitions of the constructor, a buttonClicked method, and other methods. It may save you a little typing to use the skeletal constructor and buttonClicked method provided in the template, but you can just delete all of the other method templates. When you have finished typing in the program’s text, you can tell BlueJ to execute your code as follows:
  4. Click on “Compile” in the top left corner of the the editor window.
  5. Point the mouse at the icon for the TouchyWindow class in the project window, depress the “ctrl” (control) key, and then depress the mouse button to make a menu appear.
  6. Select the first item in the menu. It should look like “new TouchyWindow()”. This tells BlueJ to cre- ate an instance of your class and to execute the instructions you placed in its constructor. Just use the default name for your instance provided by BlueJ. After continuing, a red icon for this new instance will appear in the bottom of the project window. A window will appear on the screen and any GUI components your code creates should appear within the window. You should now be able to interact with your program. Click the mouse on the “Click Here” button a few times. Each time you click, a copy of the phrase “I’m Touched” should be added to the window. When the excitement wears off, select “Quit” from the “BlueJ Virtual Machine” menu to terminate your pro- gram. DO NOT just close the window by clicking on the red button in the upper-left corner. Actually quit instead. What if the program doesn’t work? While you are working on this lab, a disturbing thing may happen. Your program may not do what you expect. Even slight typing mistakes can completely bewilder BlueJ, and in retaliation it will display an error message that is likely to leave you fairly confused. Therefore, if something goes wrong, just ask one your lab instructor or one of the teaching assistants to help you understand and correct the mistake. Submission Instructions Once the program appears to be working correclty, quit BlueJ, return to the Finder, and look in your “Documents” folder. You should find the folder that BlueJ created for your project. Its name should be the one you picked for your project (something like FloydLab1).
  • Click on the Desktop, then click on the “Users” icon. Drop your folder in the b/blawson/inbox folder.
  • Log off of the computer before you leave. Finishing up When you are all done quit all the applications you have been using during the lab and select the “Log Out” item from the menu displayed when you press the mouse on the apple icon at the upper left corner of the screen to log out.