CPSC 441, Fall 2002
Lab 2: Client/Server and Application-level Protocols



BY THE END OF THIS LAB, you will be familiar with the idea of clients and servers.

Exercises: Many of the activities on this lab will not be graded. The only thing that you need to turn in in writing is the protocols assignment, which was handed out in class. In addition to this, you should (1) show me during lab that you can access the web server on your user mode linux virtual machine, and (2) access the SMTP server on math.hws.edu to send an email to eck@math.hws.edu that looks like it came from Elvis Presley (don't forget to put your name in the email, so I know who it really came from).


Basic Client/Server

The folder /home/cs441/Sockets contains two programs, chat and threaded_chat, that can be used for chatting over a network. Later, they will be examples of programming with sockets. For now, you will just use threaded_chat as a program.

You should open a console window and change to the directory /home/cs441/Sockets. There are two ways to run threaded_chat, as a server or as a client. The command

            threaded_chat  -s

will run the program as a server that listens for a connection on port number 4588. (You can specify a different port on the command line.) It will continue to listen until it gets a connection request, presumably from a copy of threaded_chat running as a client. To run the program as a client, use a command of the form

            threaded_chat  server-ip

where server-ip is the IP address where the server is running. (This uses port 4588, but if the server is running on a different port, you can specify a different port on the command line.)

Once a connection has been opened, the window is divided in half. Each side can type characters. The characters typed by the local user are displayed in one half of the window, while the characters typed by the remote user are displayed in the other half. The connection is closed when either user types the character "~".

You should use threaded_chat to communicate with one of the other people in the lab. Make sure that you understand how to start the program as a client or as a server, and what this means.

(Bonus activity: Start threaded_chat as a server. Open a Web browser and connect to that server with a URL of the form "http://localhost:4588". You should see the browser's response in the chat window. Try to send a response back to the browser, by typing in the chat window, and have something appear in the Web browser. Unfortunately, the backspace key won't work properly. You have to end your response by typing a "~" and pressing return. I don't know why you need the return. If you want to send HTML code to the browser, you should start with these three lines (with no errors or backspaces):

            HTTP/1.0 200 OK
            Content-type: text/html
                                         <--- blank line

It's hard to type without errors. Hint: You can usually cut-and-paste in Linux by hiliting some text in one widow and then clicking somewhere else with the middle mouse button -- or the wheel on a wheel mouse.)


Telnet, the Universal Client

The telnet program can be used a client to connect to many services that use TCP and a text-based application-layer protocol. In class, we looked at HTTP as an example of this. (If you have not already experimented with telnet and HTTP, you might want to try it now!)

Anther protocol that can be used by hand, through telnet, is SMTP. This is the basic protocol for transmission of email over the Internet. Hosts that can receive email run an SMTP server daemon that constantly listens for connections. Clients connect to the server to transmit email messages that should be delivered to users that the server knows about. SMTP has very little security -- the client says who the mail is from, and the server simply believes the client. So it's easy to forge email...

I'd like you to telnet to the SMTP server on math.hws.edu and send an email message with a forged sender. You should send an email message to eck@math.hws.edu that looks like it comes from Elvis Presley. Humor will be appreciated. Use the command:

            telnet  math.hws.edu  smtp

to contact the server. The book has an example of an exchange between a client and an SMTP server on page 111. Basically, the commands that you must use have the following form:

            HELO domain.name
            
            MAIL FROM: sender-email-address
            
            RCPT TO: receiver-email-address
            
            DATA
            
            QUIT

You have to use upper case and colons, as shown. The first command must be HELO (not HELLO). Each command gets a response from the server. After the DATA command, you get to type in the email message (with some headers). You have to end the message with a period (".") on a line by itself. The SMTP server on math.hws.edu will accept mail for delivery to any email address, not just to an address on math.hws.edu, so you can try sending yourself an email to see whether it works.

The body of the email message should ordinarily include some headers. You should at least include "From:", "To:", and "Subject:" headers. An example from page 113 of the text:

            From: alice@crepes.fr
            To: bob@hamburger.edu
            Subject: Searching for the meaning of life.
                                                           <--- blank line
            (message body here)
            .                                              <--- ends the message

You can try sending yourself an email message without these headers, if you want to see what happens. The email message that you send to me should include the headers.

Warning: It is a bad idea, and probably illegal, to send an email message that looks like it comes from someone else, if there is any possibility that the recipient might be fooled.


More Fun with User Mode Linux

I would like you to set up some server daemons on your UML virtual machine. Before that, you might want to do some configuration that will let you avoid doing the basic network setup (with ifconfig and route) every time you start the virtual machine. This version of linux (Debian 3.0) uses a configuation file /etc/network/interfaces to specify the network configuration at start-up. If you edit this file, you will see the following outline of a configuration for eth0. The #'s at the beginning of each line means that the lines are currently commented out:

   # An example ethernet card setup: (broadcast and gateway are optional)
   #
   # iface eth0 inet static
   #     address 192.168.0.42
   #     network 192.168.0.0
   #     netmask 255.255.255.0
   #     broadcast 192.168.0.255
   #     gateway 192.168.0.1

You should edit this to read as follows, replacing 172.30.217.?? with your own IP address:

   # An example ethernet card setup: (broadcast and gateway are optional)
   #
   auto eth0
   iface eth0 inet static
       address 172.30.217.??
       network 172.30.0.0
       netmask 255.255.0.0
       broadcast 172.30.255.255
       gateway 172.30.0.200

Note the addition of the line auto eth0. Without this line, the new configuration will not be used automatically at start-up. If you have this file set up correctly, you won't need the ifconfig and route commands after you start your virtual machine in the future.


As we discussed in class, standard network services run as "daemons." There are very few daemons installed on your machine. Fortunately, Debian Linux makes it easy to install new software over the network. Debian software comes in "packages", and a package can be installed with the command:

            apt-get install package-name(s)

Networking must be functional for this to work, and you need to know the name of the package that you want.

As a first example, you should install the talk client program and the talkd server daemon. These provide functionality similar to the threaded_chat program. These are provided in packages named talk and talkd. That is, you should use the command:

            apt-get install talk talkd

This should retrieve the packages over the network, install them, and configure them. Apt-get is usually pretty good about configuration, so the talk daemon should already be running. To test it:

Log on to another virtual terminal as username guest with password guest. Give the command

            mesg y

This command is necessary to say that you are willing to receive messages, such as incoming talk requests. Now, in a window where you are logged on as root, give the command:

            talk guest@localhost

and see what happens in both windows. (If you manage to open a connection, you can close it with CTRL-C in either window.) You should be able to use talk across the Internet, so you might want to try setting up a conversation between two virtual machines. Use a command of the form talk user@172.30.217.?? to contact a given user at a given IP address. (Note that the talk daemon does not participate in the connection. It only accepts connection requests, and sets up connections between two users.)

You might want to install telnet and ftp daemons on your virtual machine. Do it with the commands:

           apt-get install ftpd
           apt-get install telnetd

When I did this, there was some configuration error on the second command, but repeating the command "apt-get install telnetd" fixed the problem. (Don't ask me why.) Once you have telnet installed, you should be able to telnet to your virtual machine's IP address.


As a final example, you are going to install a web server on your virtual machine. It would be possible to install the apache web server, but we will stick to a simpler web daemon called thttpd. When you install the relevant packages, you'll find that the system requires 11 other package that thttpd depends on. Apt-get is smart enough to figure this out.

When I tried to do the installation the first time, it failed because it couldn't find a DNS name for the virtual computer. Of course, your virtual computer is not in the campus DNS. However, we can fudge this... The virtual machine thinks that its name is "usermode." (This is OK, since no one outside your machine knows the name anyway. The domain name of your machine is specified in the file /etc/domainname.) To simulate DNS lookup for your machine, add the following line to the file /etc/hosts (with your own IP address):

            172.30.217.??    usermode

The hosts file can provide IP-address/domain-name associations that are not in the DNS. Note that it already contains a definition of "localhost," which is a name that is generally defined to mean the machine you are logged into.)

Once this is done, you can install the thttpd Web server with the command

            apt-get install thttpd

This will download, install, and configure twelve packages. At one point during the installation, you will have to choose a mail configuration. You can select option 5, "no configuration," since you won't be using mail on your virtual machine.

Once thtppd is installed, you have a Web server running on your virtual machine. You can use a Web browser to contact it at an address of the form

            http://172.30.217.??

using your own IP address, not "??". Your Web server doesn't have any files to serve up, so all you will see is a simple directory listing. The thtppd Web server is looking for files in the directory /var/www. If you put an index.html file in this directory, it will be the default home page for your server.

I want to see a web browser connected to a web server on your virtual machine before you leave the lab.


If you want to browse a list of available packages for Debian Linux, take a look at http://packages.debian.org/stable/. There is a link at the bottom of this page to a search page that you can use to look for specific programs. Before you start installing a lot of packages, you should keep in mind that you only have a limited amount of space in your virtual machine, because of limits on the machine's file system and the even stricter limits on the amount of disk space that you can use in your account.

If you have extra time in the lab, you can use it to work on your protocol assignment.


David Eck, 20 August 2002