This socket viewer allows you to interract with a server in order to better understand how protocols work. The easiest protocol example is HTTP (HyperText Transfer Protocol), the transfer protocol used between web browsers and web servers.
Suppose you want to "speak" HTTP with the web server
www.d.umn.edu
to fetch the web page whose URL is
http://www.d.umn.edu/~gshute/nettest.html
.
You would first need to connect to the server.
This is done by entering "www.d.umn.edu" into the "Host Name" field
at the top of the "Viewer" panel.
Then enter the port number 80 into the "Port" field.
This is the port used by most web servers.
Then click on the "Open" button.
You should see the message the following message.
Connected to www.d.umn.edu/131.212.109.30:80
If so, you have a connection established and you are ready to "speak" HTTP to the web server. The red to the left of the message indicates that the text was written by the Socket Viewer program itself.
After a connection is established with a web server, the server expects to receive requests of various types. The most common type of request is a "GET" request. It starts with the following line.
GET path-to-web-page HTTP/1.1
The path-to-web-page starts with a forward slash ("/")
character and is the path to the desired web page on that server.
For example, to access the page
http://www.d.umn.edu/~gshute/nettest.html
,
you would enter the following line.
GET /~gshute/nettest.html HTTP/1.1
This should be followed by a carriage return and a line feed. This is sent when you hit the "Enter" key on the keyboard. As soon as you have done this the color to the left of the line turns blue. This indicates that the line was entered by you and that it has been sent to the server.
After sending the "GET" line, you need to send request header lines that specify parameters for the request. These lines have the following form.
name: value
There is one mandatory header line that needs to be sent first: the "Host" parameter. Its value is usually the host name of the server that you are connected to. For this example, you would enter the following.
Host: www.d.umn.edu
Again, this is followed by hitting the "Enter" key. Also try entering a header line for a parameter named "Connection" with the value "close".
Now you have sent the command and its parameters. To tell the server that there are no more parameters, you just send a blank line by hitting the "Return" key. You should get a response from the server, indicated by green color to its left. The response consists of the following in order:
The status line should be the following.
HTTP/1.1 200 OK
The response header lines have the same format as request header lines. They convey information about the response to a browser. The blank line signals the end of the header lines, as it did in the request. After the response, you should also see a "Connection terminated." message in the viewer.
A web browser will normally want to keep the connection alive in case another web page will be requested from the same server. It does this by not sending the "Connection: close" header line. After it receives the full response as indicated by the "Content-Length" response header line, it sends a carriage return and a line feed to indicate that it is still connected. Then it can later send more "GET" requests. If the browser does not send the carriage return and line feed within a few seconds the server will automatically terminate the connection.