23
1 Application Layer Application Layer Lecture 7 Lecture 7 Imran Ahmed Imran Ahmed University of Management & Technology University of Management & Technology

1 Application Layer Lecture 7 Imran Ahmed University of Management & Technology

Embed Size (px)

Citation preview

Page 1: 1 Application Layer Lecture 7 Imran Ahmed University of Management & Technology

1

Application LayerApplication LayerLecture 7Lecture 7

Imran AhmedImran AhmedUniversity of Management & TechnologyUniversity of Management & Technology

Page 2: 1 Application Layer Lecture 7 Imran Ahmed University of Management & Technology

2

Agenda

• Principles of network applications

• Web and HTTP

• FTP

• Electronic Mail– SMTP, POP3, IMAP

• DNS

Page 3: 1 Application Layer Lecture 7 Imran Ahmed University of Management & Technology

3

FTP: the file transfer protocol

• transfer file to/from remote host

• client/server model

– client: side that initiates transfer (either to/from remote)

– server: remote host

• ftp: RFC 959

• ftp server: port 21

file transfer FTPserver

FTPuser

interface

FTPclient

local filesystem

remote filesystem

user at host

Page 4: 1 Application Layer Lecture 7 Imran Ahmed University of Management & Technology

4

FTP: Control connections, Data connections

• FTP client contacts FTP server at port 21, specifying TCP as transport protocol.

• Client obtains authorization over control connection.

• Client browses remote directory by sending commands over control channel.

• When server receives a command for a file transfer, the server opens a TCP data connection to client.

• After transferring one file, server closes connection.

• Server opens a second TCP data connection to transfer another file.

• FTP server maintains “state” current directory, earlier authentication.

Page 5: 1 Application Layer Lecture 7 Imran Ahmed University of Management & Technology

5

Agenda

• Principles of network applications• Web and HTTP• FTP• Electronic Mail

– SMTP, POP3, IMAP

• DNS• P2P file sharing• Socket programming with TCP• Socket programming with UDP

Page 6: 1 Application Layer Lecture 7 Imran Ahmed University of Management & Technology

6

Electronic Mail

Three major components: • user agents • mail servers • simple mail transfer protocol:

SMTP

User Agent• a.k.a. “mail reader”• composing, editing, reading

mail messages• e.g., Eudora, Outlook, elm,

Netscape Messenger• outgoing, incoming messages

stored on server

user mailbox

outgoing message queue

mailserver

useragent

useragent

useragent

mailserver

useragent

useragent

mailserver

useragent

SMTP

SMTP

SMTP

Page 7: 1 Application Layer Lecture 7 Imran Ahmed University of Management & Technology

7

Electronic Mail: Mail Servers

Mail Servers: • Mailbox contains

incoming message for user.

• Message queue of outgoing (to be sent) mail messages.

• SMTP protocol between mail servers to send email messages.

mailserver

useragent

useragent

useragent

mailserver

useragent

useragent

mailserver

useragent

SMTP

SMTP

SMTP

Page 8: 1 Application Layer Lecture 7 Imran Ahmed University of Management & Technology

8

Electronic Mail: SMTP [RFC 2821]

• It uses TCP to reliably transfer email message form client to server, port 25.

• Direct transfer – sending server to receiving server.

• Three phases to transfer:-– Handshaking (greeting)– Transfer of messages– Closure

• Command/response interaction:-– Commands: ASCII text– Response: status code and phrase

• Messages must be in 7-bit ASCII

Page 9: 1 Application Layer Lecture 7 Imran Ahmed University of Management & Technology

9

SMTP Concept

Page 10: 1 Application Layer Lecture 7 Imran Ahmed University of Management & Technology

10

SMTP

• Two components:– User agent (UA)– Mail transfer agent (MTA)

• To send mail, a system must have a client MTA, and to receive, a system must have a server MTA.

Page 11: 1 Application Layer Lecture 7 Imran Ahmed University of Management & Technology

11

UA and MTA

Page 12: 1 Application Layer Lecture 7 Imran Ahmed University of Management & Technology

12

Mail Gateways

Page 13: 1 Application Layer Lecture 7 Imran Ahmed University of Management & Technology

13

Scenario: Alice sends message to Bob

1) Alice uses UA to compose message and “to” [email protected]

2) Alice’s UA sends message to her mail server; message placed in message queue

3) Client side of SMTP opens TCP connection with Bob’s mail server

4) SMTP client sends Alice’s message over the TCP connection

5) Bob’s mail server places the message in Bob’s mailbox

6) Bob invokes his user agent to read message

useragent

mailserver

mailserver user

agent

1

2 3 4 56

Page 14: 1 Application Layer Lecture 7 Imran Ahmed University of Management & Technology

14

A few words about SMTP• SMTP uses persistent connections

• SMTP requires message (header & body) to be in 7-bit ASCII

• SMTP server uses CRLF.CRLF to determine end of message

• To facilitate user communication (between different user agents), we need a uniform message format in addition to SMTP.

Page 15: 1 Application Layer Lecture 7 Imran Ahmed University of Management & Technology

15

Multipurpose Internet Mail Extension (MIME)

• MIME is a supplementary protocol that allows non-ASCII data to be sent through SMTP.

• It is just an extension to SMTP.

• Just think, MIME is as a set of software functions that transforms non-ASCII data to ASCII data and vice versa.

Page 16: 1 Application Layer Lecture 7 Imran Ahmed University of Management & Technology

16

MIME

Page 17: 1 Application Layer Lecture 7 Imran Ahmed University of Management & Technology

17

Concept of NVT

Page 18: 1 Application Layer Lecture 7 Imran Ahmed University of Management & Technology

18

Mail message format [RFC 822]

RFC 822: standard for text message format:

• header lines, e.g.,– To:– From:– Subject:different from SMTP

commands!

• body– the “message”, ASCII

characters only

header

body

blankline

Page 19: 1 Application Layer Lecture 7 Imran Ahmed University of Management & Technology

19

Message format: multimedia extensions

• MIME: multimedia mail extension, RFC 2045, 2056

• additional lines in msg header declare MIME content type

From: [email protected] To: [email protected] Subject: Picture of yummy crepe. MIME-Version: 1.0 Content-Transfer-Encoding: base64 Content-Type: image/jpeg

base64 encoded data ..... ......................... ......base64 encoded data

multimedia datatype, subtype,

parameter declaration

method usedto encode data

MIME version

encoded data

Page 20: 1 Application Layer Lecture 7 Imran Ahmed University of Management & Technology

20

Mail access protocols

• SMTP: delivery/storage to receiver’s server• Mail access:

– Sharing the file system with the server.– No common file system, need mail access protocol

• POP: Post Office Protocol [RFC 1939]– authorization (agent <-->server) and download

• IMAP: Internet Mail Access Protocol [RFC 1730]– manipulation of stored msgs on server

• HTTP: Hotmail , Yahoo! Mail, etc.

useragent

sender’s mail server

useragent

SMTP SMTP accessprotocol

receiver’s mail server

Page 21: 1 Application Layer Lecture 7 Imran Ahmed University of Management & Technology

21

POP3 protocol

authorization phase• client commands:

– user: declare username– pass: password

• server responses– +OK– -ERR

transaction phase, client:• list: list message numbers• retr: retrieve message by number• dele: delete• quit

C: list S: 1 498 S: 2 912 S: . C: retr 1 S: <message 1 contents> S: . C: dele 1 C: retr 2 S: <message 1 contents> S: . C: dele 2 C: quit S: +OK POP3 server signing off

S: +OK POP3 server ready C: user bob S: +OK C: pass hungry S: +OK user successfully logged on

Page 22: 1 Application Layer Lecture 7 Imran Ahmed University of Management & Technology

22

POP3 and SMTP

Page 23: 1 Application Layer Lecture 7 Imran Ahmed University of Management & Technology

23

IMAP

• Keep all messages in one place: the server

• Allows user to organize messages in folders.

• IMAP keeps user state across sessions:– Names of folders and mapping between

message IDs and folder name.