Web 與 Email

Preview:

DESCRIPTION

Web 與 Email. HTTP. HTTP: Hyper Text Transfer Protocol Web 的應用層協定 採用用戶端和伺服器端的服務架構 用戶端 : 要求 、 接收並顯示所接收的 web pages 伺服器端 : 接受要求並回應所要求的 web pages. www.someschool.edu/someDept/pic.gif. path name. host name. HTTP. Web page 所包含的原件有 Objects HTML file, jpeg image, java applet … Base HTML file - PowerPoint PPT Presentation

Citation preview

Web Web 與與 EmailEmail

HTTPHTTP

HTTP: Hyper Text Transfer ProtocolWeb 的應用層協定採用用戶端和伺服器端的服務架構

用戶端:要求、接收並顯示所接收的 web pages

伺服器端:接受要求並回應所要求的 web pages

Application

Transport

Network

Data link

Physical

Application

Transport

Network

Data link

Physicalbrowser web server

http request

http reply

HTTPHTTP

Web page 所包含的原件有 Objects

HTML file, jpeg image, java applet… Base HTML file

HTML 是用來描述 web page 的一種語言 URL :是用來表示一個 page 或是 object

www.cyu.edu.tw/web/index.html (hostname + path name) 目前 HTTP 有兩種標準

http 1.0 (RFC 1945) http 1.1 (RFC 2068)— 目前所使用

www.someschool.edu/someDept/pic.gif

host name path name

HTML: Hypertext Markup HTML: Hypertext Markup LanguageLanguage

使一種用來描述網頁的文件要如何定義的語言

Embedding markup commands with each HTML files so that a browser can reformat the files.

HTML 的標準化 由 WWW 組織所制訂ex: W3C

HTTPHTTP

HTTP 下層協定使用 TCP 傳送服務由用戶端初始化連線 (setup TCP connection) ,使用 socket port 80 與伺服器端溝通

伺服器端回應後,兩端開始交換訊息直到結束 (TCP connection close)

HTTP 是一個 stateless 的協定Stateless 意指伺服器端不需要保有任何有關過去用戶端的要求訊息 (request message)

通常協定要保有過去的 state ,就會變的很複雜

Non-Non-persistentpersistent 和和 persistentpersistent 連線的連線的不同不同

Non-persistent HTTP/1.0 每一個 TCP 連線都會在

server 送完物件後結束 所以每一個連線都只會有一個 request 和一個 respond

Respond time = 2 RTTs + Ttrans

每一個所傳送的物件,都會受到 slow start 影響

Persistent Default for HTTP/1.1 在同一個用戶端會一直使用同一個 TCP 連線,直到 time out 才關掉

有較少的 RTT 和 slow start

有分成 pipeline 和 non-pipeline

HTTPHTTP 的訊息格式的訊息格式 -- request-- request

訊息是使用 ASCII text 所寫(易於閱讀)Http 的要求訊息格式

GET /somedir/page.html HTTP/1.0 User-agent: Mozilla/4.0 Accept: text/html, image/gif,image/jpeg Accept-language:fr

(extra carriage return, line feed)

request line(GET, POST,

HEAD commands)

header lines

Carriage return, line feed

indicates end of message

HTTPHTTP 的要求訊息格式的要求訊息格式 -- -- 一般式一般式

HTTPHTTP 的訊息格式的訊息格式 -- response-- response

status line(protocol

status codestatus phrase)

HTTP/1.0 200 OK Date: Thu, 06 Aug 1998 12:00:15 GMT Server: Apache/1.3.0 (Unix) Last-Modified: Mon, 22 Jun 1998 …... Content-Length: 6821 Content-Type: text/html data data data data data ...

data, e.g., requestedhtml file

header lines

常見的回應訊息常見的回應訊息

200 OK 要求成功, 所要求的物件會夾帶在接下來的訊息

301 Moved Permanently 所要求的物件已經一到別處,新的位置將會出現在下一個訊息中 (L

ocation:)400 Bad Request

所要求的訊息,伺服器無法判讀404 Not Found

所要求的物件並不存在伺服器裡505 HTTP Version Not Supported

所要求使用的協定,伺服器端並不支援

Java Language (Java Language ( 爪窪語言爪窪語言 ))

在 1995 年,由昇揚公司 (Sun Microsystems Inc.) 所制訂

For waiting interactive web pages.A small Java program, called an applet, is

associated with a web page and downloaded to the client machine to interpret the web page.

Java Language (cont.)Java Language (cont.)

認證認證 (Authentication)(Authentication) 目的:為了要控制存取伺服器資料的權力

因為是 stateless 所以用戶端每一次 request 都要認證一次

認證通常使用 name 和 password

為避免需要重覆輸入認證資料,瀏覽器會自行讀取catch 的資料

認證步驟如右

server

usual http request msg401: authorization

req.WWW authenticate:

usual http request msg+ Authorization:line

usual http response msg

usual http request msg+ Authorization:line

usual http response msg

time

client

cookiescookies

設定 cookie 是為了方便在下一次存取網站時,可以不需要再輸入一些重複性的資料

Cookie 是由伺服器端要求用戶端建立,並且存在用戶端的機器上

Cookie 大多用來 認證 使用者的訊息

建立步驟如右

client server

usual http request msgusual http response

+Set-cookie: #

usual http request msgcookie: #

usual http response msg

usual http request msgcookie: #

usual http response msg

cookie-spectific

action

cookie-spectific

action

WebWeb 快取快取(( proxyproxy 伺服器伺服器)) 目的:為了可以使用戶端送出的 request 不用直接到原來的伺服器,如此一來便可以加速網頁的取得及瀏覽

所以大部分的用戶端都會透過 proxy server 來存取網路資源,而 proxy server 會保有一些 web的快取資料,以利存取 如果現在的網頁資料不是最新的,則 proxy 會去原始的網站去更新目前保有的資料

client

Proxyserver

client

http request

http re

quest

http response

http re

sponse

http re

quest

http re

sponse

http requesthttp response

origin server

origin server

為什麼使用為什麼使用 web catchingweb catching 因為 proxy 一般會離用戶端較近,會使的存取的速度較快

可以減少一些較長距離的traffic

同一筆資料可以統一由 proxy 來維持更新

右圖為示意圖 1.5 Mbps access link 是一個 bottleneck

originservers

public Internet

institutionalnetwork 10 Mbps LAN

1.5 Mbps access link

用指令方式連線用指令方式連線 HTTP (client side)HTTP (client side) 網頁網頁

1. Telnet to your favorite Web server:

Opens TCP connection to port 80(default HTTP server port) at cis.poly.edu.Anything typed in sent to port 80 at cis.poly.edu

telnet mail.cyu.edu.tw 80

2. Type in a GET HTTP request:

GET /index.html HTTP/1.1Host: mail.cyu.edu.tw

By typing this in ( 兩行指令輸入完成後按兩次 Enter), you send this minimal(but complete) GET request to HTTP server

3. Look at response message sent by HTTP server!

FTP: File Transfer ProtocolFTP: File Transfer Protocol

FTP 是現在較普遍也較常用的一個檔案傳輸的協定

採用用戶端與伺服器端模式溝通RFC 編號: 959所使用的 port:21

file transfer FTPserver

FTPuser

interface

FTPclient

local filesystem

remote filesystem

user at host

FTP: File Transfer ProtocolFTP: File Transfer Protocol (cont.)(cont.)

FTP 使用 TCP 作為傳輸層所使用的協定 在 FTP 的連結中有分為兩種

Control :在 client 和 server 之間交換 commands 和 response ,屬於” out of band control”

Data :在 client 和 server 之間的 data 交換 FTP 和 HTTP 不同,他會 maintain state

目前所在目錄 登錄所做的認證

FTPclient

FTPserver

TCP control connection

port 21

TCP data connectionport 20

FTP: File Transfer ProtocolFTP: File Transfer Protocol (cont.) (cont.)

Commands Open: 連接 FTP server User: 使用者帳號 Pass: 密碼 RETR filename: 取得檔案 STOR filename: 上傳檔案 Bye: 結束連線

回應訊息 331 帳號 OK,需要密

碼 125 data connection 已經開啟 ; 傳送開始

425 無法開啟 data connection

452 檔案寫入錯誤

如何連結上 FTP server?

>>ftp xxx.xxx.xxx.xxx port

>>get file.xxx ( 取得檔案 )

>>put file.xxx ( 上傳檔案 )

EElectroniclectronic-mail-mail (E-mail, (E-mail, 電子電子郵件郵件 ))

包含三個部分使用者代理人

(user agent)郵件伺服器

(mail server)SMTP 協定

mailserver

useragent

useragent

useragent

mailserver

useragent

useragent

mailserver

useragent

SMTP

SMTP

SMTP

user mailbox

outgoing message queue

E-mail– user agentE-mail– user agent

有時亦稱為郵件讀取者 (mail reader)它可以讓 user 讀取、回復、轉發、儲存和建構訊息 (message, mail…)

使用者需要讀取信息時, user agent 會去跟郵件伺服器溝通,取回信息,或是送出信息

User agent 常見的有:Microsoft Outlook or Outlook ExpressNetscape Messenger

E-mail– Mail serverE-mail– Mail server

每一個 user 都會有一個信箱 (mail box) 來存放尚未讀取的信件

尚未傳送出去的信件會暫時存在 message queue

SMTP扮演了兩種角色Client :當作傳送信件的 serverServer :當作接收信件的 serverClient 和 server這兩種服務都會執行在每一台郵件伺服器上

E-mail– SMTPE-mail– SMTP

SMTP: Simple Mail Transfer ProtocolRFC 編號 : 821

使用 TCP 作為下層溝通的協定Port: 25

傳送三部曲HandshakingTransfer of messagesclosure

所有信息資訊必須是 7-bit ASCII

SMTPSMTP 和和 HTTPHTTP 的比較的比較

相同處使用 TCP 為傳輸層協定Client and server model使用 persistent connections

不同處http 是 pull protocol 而 SMTP 是 push protocolSMTP 的 message限定在 7 bit ASCII文件組成方式不同

SMTPSMTP 溝通範例溝通範例 S: 220 cs.nthu.edu.tw C: HELO oz.nthu.edu.tw S: 250 Hello oz.nthu.edu.tw, pleased to meet you C: MAIL FROM: <alice@oz.nthu.edu.tw > S: 250 alice@oz.nthu.edu.tw... Sender ok C: RCPT TO: <bob@cs.nthu.edu.tw > S: 250 bob@cs.nthu.edu.tw ... Recipient ok C: DATA S: 354 Enter mail, end with "." on a line by itself C: Do you like ketchup? C: How about pickles? C: . S: 250 Message accepted for delivery C: QUIT S: 221 cs.nthu.edu.tw closing connection

信息格式信息格式RFC 822 為 text mes

sage exchange 標準Header lines

To:From:Subject:

BodyThe message, ASCII c

haracter only

header

body

blankline

信息格式 信息格式 (cont.)(cont.)

信息格式 信息格式 (cont.)(cont.)

MIME extension for Non-MIME extension for Non-ASCII dataASCII data

MIME: multimedia mail extension RFC 2045, 2056目的:為了要能夠支援非 ASCII 的 data在標頭檔定義 MIME 的格式

From: alice@crepes.fr To: bob@hamburger.edu Subject: Picture of yummy crepe. MIME-Version: 1.0 Content-Transfer-Encoding: base64 Content-Type: image/jpeg

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

多媒體資料的種類及副檔名 (type, subtype)

壓縮資料的方法(encode data)

MIME version(版本 )

壓縮的資料(encoded data)

MIME (cont.)MIME (cont.)

RFC 822 MIME 所增加的標頭檔 (headers)

Header Meaning

MIME-version 定義 MIME 的版本Content-Description 描述信息內容Content-ID 唯一的識別碼Content-Transfer-Encoding

在傳送所壓縮的方法

Content-Type 信息的種類

MIME MIME 的種類的種類 (types)(types)Content-Type: Content-Type: 種類種類 // 副檔名副檔名 ; ; 參數參數

(type/subtype; parameters)(type/subtype; parameters)

文字 (Text) 例如:副檔名為 plain, html

圖片 (Image) 例如:副檔名為 jpeg, gif

聲音 (Audio) 例如:副檔名為 basic (

8-bit mu-law encoded), 32kadpcm (32 kbps coding)

影像 (Video) 例如:副檔名為 mpeg, quicktime

應用程式 (Application) other data that must be

processed by reader before “viewable”

例如:副檔名為 msword, octet-stream

郵件存取協定郵件存取協定 (mail access protocol(mail access protocol))

SMTP負責接收端 server 的傳送及儲存信息 Mail access protocol:從 server 取回信件

POP: Post Office ProtocolRFC 1939提供認證及下載服務

IMAPRFC 2060可以遠端操作信件,不需下載信件至機器上

HTTP (web mail)Hot mail, mail2000, yahoo…

POP3POP3 協定協定

authorization phase client commands:

user: declare usernamepass: password

server responses+OK-ERR

transaction phase, client: list: list message numbers retr: retrieve message by numb

er 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 alice S: +OK C: pass hungry S: +OK user successfully logged on

用指令方式連線用指令方式連線 SMTP SMTP 送送 EmailEmail telnet mail.cyu.edu.tw 25 see 220 reply from server enter HELO, MAIL FROM, RCPT TO, DATA, QUIT

commands above lets you send email without using email cli

ent (reader)

Sample SMTP interactionSample SMTP interaction

S: 220 mail.cyu.edu.tw …… C: HELO mail.cyu.edu.tw S: 250 Hello mail.cyu.edu.tw, pleased to meet you C: MAIL FROM: <B96xxxxx@cyu.edu.tw> S: 250 B96xxxxx@cyu.edu.tw... OK C: RCPT TO: <B96xxxxx@cyu.edu.tw> S: 250 B96xxxxx@cyu.edu.tw... Recipient ok C: DATA S: 354 Enter mail, end with "." C: Do you like ketchup? C: How about pickles? C: . S: 250 Message accepted for delivery C: QUIT S: 221 mail.cyu.edu.tw closing connection

用指令方式連線 用指令方式連線 POP POP 收 收 EmailEmail telnet mail.cyu.edu.tw 110 See +OK reply from server enter user, pass, list commands above lets you receive email without using email

client (reader)

POP3 protocolPOP3 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 B9613xxx S: +OK C: pass keyin 密碼S: +OK user successfully logged on

網路工具軟體網路工具軟體

Wireshark( 封包解析軟體 )http://www.wireshark.org/

Free IP Scanner( 網路掃瞄工具 ) http://www.eusing.com/ipscan/free_ip_scanner.htm

TCP View( 檢查 Windows 開啟的 TCP 連線 ) http://technet.microsoft.com/en-us/sysinternals/bb897437.as

px

WindowsWindows 網路相關指令網路相關指令arp –a 查詢 IP 的 MAC 位址Ping IP_address 送出 ICMP 封包,查詢該 I

P 的回應時間Tracert 查詢路由路徑netstat -anb

參數“ b” ,除了會列出 PID 外,也會列出該程式的名稱,及相關的動態函式庫

Ipconfig 電腦 IP 的設定情況與指令

Recommended