You are on page 1of 8

COMP2330

Data Communications and Networking


Dr. Chu Xiaowen
Laboratory 1

Simple Network Applications: HTTP & SMTP

Objectives:

1. To understand HTTP and SMTP.

2. To use telnet to connect to HTTP and SMTP servers.

Outline:

0. Protocol, Syntax, and Semantics

1. HTTP

2. SMTP

0. Protocol, Syntax, and Semantics


Before learning HTTP and SMTP protocols, lets first take a look at what protocol is.

0.1 What is Protocol?

In computing, a protocol is a convention or standard that controls or enables the connection,


communication, and data transfer between two computing endpoints.

In its simplest form, a protocol can be defined as the rules governing the syntax, semantics, and
synchronization of communication.

0.2 What are Syntax and Semantics?

Syntax stands for the grammatical structure of a language. (Language includes both natural language
and programming language).

Semantic stands for the meaning of vocabulary symbols arranged with that structure.

For instance, the following statements use different syntaxes, but result in the same semantic:

x += y; (C, Java, etc)


x := x + y; (PASCAL)
x = x + y (various Basics ,QBasic, Turbo Basic, etc )
Let x = x + y; (some other languages, which? You can find it out... )

Generally these operations would all perform an arithmetical addition of 'y' to 'x'. So, in the above
four statements:

If you find something in common, that is their semantics.


If you find something different, that is their syntax.

Probably you have understood what syntax and semantics are. Here are their definitions in textbooks:

Syntax refers to grammatical structure

Semantics refers to the meaning of the vocabulary symbols arranged with that structure.

So, the following statements have the same syntaxes but different semantics:

x = x + y;
sum = sum + grade[i];

And

He is a new student.
You are a good person.
Trees are big dogs.

They are in the same grammar but with different meanings. Note the last statement Trees are dogs;
it is right in syntax but wrong in semantics. Because trees are not dogs at all, so the meaning
(Semantics) of this sentence is wrong, although grammar (syntax) is right.

1. HTTP

1.1 What is HTTP?

When you are surfing on the Internet, you are sending HTTP requests from your Internet Explorer to
websites, such as yahoo.com, which respond with HTTP responses to you.

HTTP stands for Hypertext Transfer Protocol. It's the network protocol used to deliver virtually all
files and other data (collectively called resources) on the World Wide Web, whether they're HTML
files, image files, query results, or anything else. Usually, HTTP takes place through TCP/IP sockets
(and this tutorial ignores other possibilities).

A browser is an HTTP client because it sends requests to an HTTP server (Web server), which then
sends responses back to the client. The standard (and default) port for HTTP servers to listen on is 80,
though they can use any port.

1.2 HTTP Versions

HTTP/1.0 (May 1996)


This is the first protocol revision to specify its version in communications and is still in wide
use, especially by proxy servers.
HTTP/1.1 (June 1999)

Current version; persistent connections enabled by default and works well with proxies.
Also supports request pipelining, allowing multiple requests to be sent at the same time,
allowing the server to prepare for the workload and potentially transfer the requested
resources more quickly to the client.

1.3 Request Methods

HEAD
Asks for the response identical to the one that would correspond to a GET request without the
response body. This is useful for retrieving meta-information written in response headers,
without having to transport the entire content.
GET
Requests a representation of the specified resource. By far the most common method used
on the Web today. Should not be used for operations that cause side-effects (using it for
actions in web applications is a common misuse). See 'safe methods' below.
TRACE
Echoes back the received request, so that a client can see what intermediate servers are
adding or changing in the request.
OPTIONS
Returns the HTTP methods that the server supports. This can be used to check the
functionality of a web server.
And more read http://en.wikipedia.org/wiki/HTTP if you are interested.

1.4 Do the exercises below:


Run telnet and contact port 80, for example

telnet www.yahoo.com 80

And

GET /index.html HTTP/1.0


Host: www.yahoo.com
(Press Enter again)

[or for http 1.1 ]

GET /index.html HTTP/1.1


Host: www.yahoo.com
(Press Enter again)

Note: here, both of the statements have same syntax, that is GET FileName HTTP/version.
They have different Semantics, the first one uses HTTP/1.0 while the second one uses HTTP/1.1
1.5 Sample Results:

And for HTTP/1.1 command

2. SMTP

2.1 What is SMTP?


SMTP stands for Simple Mail Transfer Protocol, a standard for e-mail transmissions across the
Internet.
SMTP is the Internet protocol used to transfer electronic mail between computers, much like HTTP
is the Internet protocol used to transfer web pages between computers.

In SMTP (and in the rest of this discussion), the client is the computer that is sending email, and the
server is the computer that is receiving it. Thus we say SMTP clients (or SMTP senders) send email
to SMTP servers.

2.2 SMTP Commands

When one sends mail using the SMTP protocol, one has only the following commands:

HELO
Greet the mail server. Used once per session - at the beginning of the session.
HELO is an optional command.

MAIL FROM: <from>


Announce who the sender is. Used once per mail, before specifying any recipients for each
mail, or after a RSET.
RCPT TO: <rcpt>
Announce who the mail is to. Multiple recipients are allowed, each must have its own RCPT
TO: entered immediately after a MAIL FROM:
DATA
Starts mail entry mode. Everything entered on the lines following DATA is treated as the
body of the message and is sent to the recipients. The DATA terminates with a . (period) on
a line by itself. A mail may be queued or sent immediately when the . is entered. It cannot
however be reset at this stage.

Subject: < enter your subject >

If no subject is entered, the email will have no subject.

This command must follow the DATA command

Reply-To: < enter an email address to be replied>

This is optional. And this command must follow the DATA command and the Subjcet:
command ( if there is a Subject: command).

RSET

Reset the state of the current transaction. The MAIL FROM: and RCPT TO: for the current
transaction are cleared.
QUIT
End the session. No commits happen here.
2.3 Do Exercises of Using SMTP to send email
Experiment 1. Send an email to Mr. Kaiyong ZHAO

Send an email to kyzhao@comp.hkbu.edu.hk


Remember to use yourid@hkbu.edu.hk as the sender email address. And mention your id in both
the subject and the email body.
The commands are:

telnet smtp.comp.hkbu.edu.hk 25

MAIL FROM: xxxxxxxx@hkbu.edu.hk


RCPT TO: kyzhao@comp.hkbu.edu.hk
DATA
Subject: comp2330 0600xxxx
My id: 0700xxxx
My name: Mr. XXX.
Comp2330
End
Note: here must be an dot on a
Good bye : )
line by itself, as an indication of
the end of your email.
.
And press Enter afterwards.

After you see the message: 250 xxxxx Message accepted for delivery, enter:

QUIT

Experiment 2. Send an email to your friends

Send an email from any of your preferred email address, to any of your friends email
address.
For example: (the following is example only, DONT send to these emails if you dont know the owner)

Let the sender be: Bruce.Lee@yahoo.com

And the recipient be: Bill.Gates@gmail.com


Of course you can use any of your email addresses, but do not use email addresses belonging to
other people. Remember, pretending to send emails from other peoples email addresses, or sending
huge amount of emails to the people you dont know, would be seen as Spam emails. In Hong
Kong, sending spam emails would constitute a crime. So, only send emails to the
person you know. ONLY Use yourName@somedomain.like.hotmail.com as
sender and/or receiver email addresses.

The commands are similar to step 1. You just need follow the same syntax with different
semantics of step 1.

Experiment 3. Send an email with specified reply-to address

Send an email, using a reply-to address that is different from the sender address. As compared to step
1 and step 2, now you need a different syntax for the reply-to function.

Experiment 4. Check all your emails

Check all the emails of step 2,3 in your email boxes, such as your yahoo, hotmail email box. Your
email sent by step 1 will be checked by the Teaching Assistant as your record of lab 1.

2.4 Sample Results:


Experiment 1.
Experiment 2.

Experiment 3.

[References]
[1] http://www.w3.org/Protocols/, Jan 2009
[2] http://en.wikipedia.org/wiki/HTTP, Jan 2009

You might also like