Talking to a Web serverTopReading from a URLHow client/server systems work

How client/server systems work

Now, let's talk a bit about how networking programs work. When we write a networking program like the HTMLLinkFinder or the SpamFilter from lab, our program is communicating with another program over the network. Our program is a client. The other program is a server. In the case of HTMLLinkFinder, we are communicating with a Web server. In the case of the SpamFilter, we are communicating with a POP (Post Office Protocol) server which is one type of server that can be used to read mail.

Let's talk about how a Web client/server pair works a bit more. First, we'll look at URLs and understand what they mean better. A simple URL may look like:

http://www.pomona.edu

A more complicated URL is:

http://www.pomona.edu:80/events/news/home.shtml

What are all these pieces?

http
This specifies the protocol that will be used in communication. "http" means HyperText Transfer Protocol. This is the protocol used by Web servers. More on protocols later.

www.pomona.edu
This identifies the name of the machine where the Web server is running.

80
This is the port number the Web server is running on. Think of this as your SU Box number. One machine may run several servers, so we identify the specific server we want by identifying its port. Common servers, like Web servers, have default port numbers. The default port number for a Web server is 80. If a server is running at its default port, we can omit the port number in the URL.

everything else
The rest is information that is passed to the Web server to identify the Web page we want to view.

To connect to a server, we need to identify the machine and the port to use. Once connected, the protocol defines a set of commands that we can use to talk to the server. The protocol also specifies the arguments that the command requires and the return values that it produces.

The HTTP protocol is very simple. It supports one command:

GET
The GET command takes an argument which is the name of the content we want the Web server to return. It returns a long string, which is the Web page content.

For example, if I am connected to portal.dci.pomona.edu, I can get my home page by sending the string "GET /~kim/" to the Web server.

The easiest way to get a feeling for protocols is to run a program called telnet from a command line (like a UNIX or DOS shell, or Mac Terminal). [Unfortunately, many computers no longer respond to telnet commands for security reasons.] With telnet, we can send commands like the GET line above to the server just by typing them on the keyboard and hitting return. The responses made by the server appear on the terminal.

Here is a sample session using telnet to download a page from a Web server:

First we connect to the Web server. Using telnet we must explicitly state what the port number is.

-> telnet portal.cs.pomona.edu 80

The Web server responds:

Trying 134.173.66.157...
Connected to portal.cs.pomona.edu.
Escape character is '^]'.

Now we request the home page for cs134:

GET /~cs134/f03/

The server responds with the Web page:

<html>
<head>
<TITLE>Home page for Kim B. Bruce</TITLE>
</head>
<body bgcolor="#eeffff">
<table>
    
    <tr>
    <td>
    
<applet archive="objectdraw.jar" code=DrawBanner.class width="1000"
height="200" >
<img alt="" src="Banner2.jpg">
</applet>

</td>
    </tr>
    
</table>

<TABLE WIDTH="100<TD COLSPAN="1">

<H2>Kim B. Bruce</H2>

<H3>Reuben C. and Eleanor Winslow Professor of Computer Science <br>
and Department Chair<br>
<a href="http://www.cs.pomona.edu/">Department of Computer Science</a><BR>
<a href="http://www.pomona.edu/">Pomona College</a>
</H3>

<address><a href="mailto:kim@cs.pomona.edu">kim@cs.pomona.edu</a> 
</address>
</TD>
<TD COLSPAN="1" ALIGN="LEFT">
<IMG SRC="KimWeb.jpg">
</TD>
<!TD COLSPAN="1" ALIGN="RIGHT">
<!object  data="pclogosm.gif" type="image/gif"  > 
<!image  src="pclogosm.gif" > 
<!/TD>
</TR>
</TABLE>

<p>
<!img src="line2.gif">
<hr>

...
</body>
</html>
Connection closed by foreign host.

The HTTP protocol automatically closes the connection after returning the Web page. If I wanted another Web page, I would need to create another connection to get the second page.


Talking to a Web serverTopReading from a URLHow client/server systems work