Bài giảng Mạng máy tính - Chương 2, Phần a: Giao thức tầng ứng dụng (Application layer) - Trần Quang Diện

Một số khái niệm và nguyên tắc

 Một số chương trình ứng dụng (network applications):

 Email (Yahoo! Mail, MS Outlook, Google mail, ).

 Web browser (MS Internet Explorer, Fire Fox, Netscape

Navigator, ).

 Instant messenger (Yahoo! Messenger, ICQ, AOL, ).

 P2P file sharing (Napster, KazaA ).

 Internet games (Yahoo! Games).

 Internet telephone (Skype, FPTFone,VNNFone ).

 Streaming stored video clips.

 Real-time video conference.

 Massive parallel computing.

Chapter 2. The Application Layer 4Một số giao thức (application-layer protocols)

 HTTP (Hyper Text Transfer Protocol)

 Giao thức web.

 FTP (File Transfer Protocol)

 Giao thức truyền tệp.

 SMTP (Simple Mail Transfer Protocol)

 Giao thức truyền thư điện tử.

 POP (Post Office Protocol)

 Giao thức nhận thư điện tử.

 IMAP (Internet Mail Access Protocol)

 Giao thức nhận thư điện tử (khác POP3)

 DNS (Domain Name System)

 DNS = hệ thống tên miền, giao thức DNS quy định quy tắc sử dụng tên miền.

 TFTP (Trivial FTP)

 Một dạng khác của FTP

pdf 49 trang kimcuc 5540
Bạn đang xem 20 trang mẫu của tài liệu "Bài giảng Mạng máy tính - Chương 2, Phần a: Giao thức tầng ứng dụng (Application layer) - Trần Quang Diện", để tải tài liệu gốc về máy hãy click vào nút Download ở trên

Tóm tắt nội dung tài liệu: Bài giảng Mạng máy tính - Chương 2, Phần a: Giao thức tầng ứng dụng (Application layer) - Trần Quang Diện

Bài giảng Mạng máy tính - Chương 2, Phần a: Giao thức tầng ứng dụng (Application layer) - Trần Quang Diện
Chương 2.
Giao thức tầng ứng dụng (application layer)
Quang Dieu Tran, PhD
Faculty of Information Technology
University of Communication and Transport 
(Branch in Ho Chi Minh City)
Email: dieutq@gmail.com
Website: sites.google.com/sites/tranlectures
Application Layer
Chapter 2. The Application Layer 2
Ch2. The Application Layer
2.1. Một số khái niệm và nguyên tắc.
2.2. Web & Hyper Text Transfer Protocol.
2.3. Web design and HTTP, Web programming.
2.4. File Transfer Protocol.
2.5. Electronic Mail Protocols.
2.6. Domain Name System.
Chapter 2. The Application Layer 3
2.1. Một số khái niệm và nguyên tắc
 Một số chương trình ứng dụng (network applications):
 Email (Yahoo! Mail, MS Outlook, Google mail,).
 Web browser (MS Internet Explorer, Fire Fox, Netscape 
Navigator,).
 Instant messenger (Yahoo! Messenger, ICQ, AOL,).
 P2P file sharing (Napster, KazaA).
 Internet games (Yahoo! Games).
 Internet telephone (Skype, FPTFone,VNNFone).
 Streaming stored video clips.
 Real-time video conference.
 Massive parallel computing.
Chapter 2. The Application Layer 4
Một số giao thức (application-layer protocols)
 HTTP (Hyper Text Transfer Protocol)
 Giao thức web.
 FTP (File Transfer Protocol)
 Giao thức truyền tệp.
 SMTP (Simple Mail Transfer Protocol)
 Giao thức truyền thư điện tử.
 POP (Post Office Protocol)
 Giao thức nhận thư điện tử.
 IMAP (Internet Mail Access Protocol)
 Giao thức nhận thư điện tử (khác POP3)
 DNS (Domain Name System)
 DNS = hệ thống tên miền, giao thức DNS quy định quy tắc sử dụng tên miền.
 TFTP (Trivial FTP)
 Một dạng khác của FTP.
Chapter 2. The Application Layer 5
Net applications vs. application-layer protocols
 Applications:
 Chương trình ứng dụng chạy trên các máy tính.
 Trao đổi thông điệp (message) với các ứng dụng khác nhằm thực thi vai trò 
của ứng dụng.
 Vd: web browser, email client
 Application-layer protocols:
 Là một thành phần của chương trình ứng dụng.
 Định nghĩa các quy tắc trao đổi thông điệp.
 Giao tiếp với các dịch vụ được cung cấp bởi tầng dưới (TCP, UDP).
Chapter 2. The Application Layer 6
Các chương trình giao tiếp với nhau ntn?
 Các chương trình trên cùng một máy tính
Sử dụng các dịch vụ được cung cấp bởi hệ điều hành 
(interprocess communication).
 Các chương trình trên các máy tính khác nhau
Giao tiếp thông qua giao thức của tầng ứng dụng 
(application-layer protocol).
 Chương trình phía người dùng = user agent
Giao tiếp với người sử dụng (giao diện sử dụng).
Giao tiếp với các giao thức mạng.
Chapter 2. The Application Layer 7
Mô hình khách-phục vụ (client-server paradigm)
Mô hình khách-phục vụ được quen gọi là mô hình khách-chủ. Một 
ứng dụng cụ thể bao gồm hai phần:
 Client
 Thiết lập liên kết với server.
 Yêu cầu dịch vụ từ server.
 Nhiều clients.
 Vd: web browser.
 Server
 Chờ và cung cấp các dịch vụ khi client yêu cầu.
 Thường chỉ có 1 server, không thay đổi địa chỉ, chạy 24/7.
 Vd: web server.
Chapter 2. The Application Layer 8
application
transport
network
data link
physical
application
transport
network
data link
physical
request
reply
Mô hình ngang hàng (Peer-to-peer paradigm)
 Không có máy dịch vụ cố định, các máy tính trong mạng 
lúc này là server (nhận yêu cầu kết nối) nhưng lúc khác lại 
là client (yêu cầu máy khác kết nối).
 Các máy tính là ngang hàng, tự do kết nối và giao tiếp đôi 
một.
 Địa chỉ của các máy tính tham gia giao tiếp liên tục thay 
đổi.
Chapter 2. The Application Layer 9
Client-server & P2P examples
 CNN.com
 Yahoo! Mail
 Google
 Yahoo! Messenger
 Internet Relay Chat (IRC)
Chapter 2. The Application Layer 10
 Client-server
 Client-server
 Client-server
 Client-server & P2P
 Client-server & P2P
Dịch vụ tầng dưới đối với application-layer
 Có thể coi tầng application (Internet) = tầng application + 
presentation + session trong mô hình OSI.
 Các dịch vụ với application:
 Presentation: gắn liền với application trong TCP/IP
 File formats: picture (JPEG, GIF), audio (MP3, RM), video (MPEG, 
MOV), document (HTML, XML).
 Data encryption & compression.
 Session: gắn liền với application trong TCP/IP
 NFS (Network File System), RPC (Remote Procedure Call), SQL 
(Structured Query Language), SSL (Secure Socket Layer).
 Transport (*)
 Cung cấp dịch vụ vận chuyển cho application (TCP/IP).
 Hai giao thức: TCP và UDP.
Chapter 2. The Application Layer 11
Yêu cầu đối với việc vận chuyển dữ liệu
 Data loss
 Các ứng dụng audio/video có thể chấp nhận mất mát, sai lệch dữ 
liệu trong khoảng cho phép.
 Email, file transfer yêu cầu dữ liệu phải chính xác.
 Timing
 Các ứng dụng online cần độ trễ (delay) nhỏ (phone, games).
 Bandwidth
 Các ứng dụng multimedia cần đường truyền tốc độ cao để đảm 
bảo chất lượng.
 Các ứng dụng email, file transfer mềm dẻo hơn, tuỳ theo tốc độ.
Chapter 2. The Application Layer 12
Các yêu cầu giao vận của một số ứng dụng
Chapter 2. The Application Layer 13
Internet Transport protocols: TCP & UDP
TCP (Transmission Control Protocol)
 connection-oriented: setup 
required between client, server.
 reliable transport between 
sending and receiving process.
 flow control: sender won’t 
overwhelm receiver.
 congestion control: throttle 
sender when network 
overloaded.
 does not providing: timing, 
minimum bandwidth 
guarantees.
UDP (User Datagram Protocol)
 unreliable data transfer
between sending and receiving 
process
 does not provide: connection 
setup, reliability, flow control, 
congestion control, timing, or 
bandwidth guarantee.
Chapter 2. The Application Layer 14
Internet applications: TCP or UDP?
Chapter 2. The Application Layer 15
Ch2. The Application Layer
2.1. Một số khái niệm và nguyên tắc.
2.2. Web & Hyper Text Transfer Protocol.
2.3. Web design and programming.
2.4. File Transfer Protocol.
2.5. Electronic Mail Protocols.
2.6. Domain Name System.
Chapter 2. The Application Layer 16
2.2. Web & HTTP
 Trang web (web page): một loại tài liệu có chứa trong đó 
nhiều đối tượng: text, image, audio, Java applet, HTML
 Về cơ bản, web page = HTML file (base HTML).
 HTML = Hyper Text Markup Language.
 HTML sử dụng các thẻ (tag) để mô tả đối tượng chứa trong nó.
 Mỗi đối tượng được chỉ ra bởi địa chỉ URL (Uniform 
Resource Locator)
 

Chapter 2. The Application Layer 17
Protocol Host name & port Path
HTTP (Hyper Text Transfer Protocol)
 Giao thức tầng ứng dụng web.
 Sử dụng mô hình client/server.
 Client (user agent):
 Trình duyệt web (web browser)
 Yêu cầu truy cập web thông qua URL (URL request).
 Server
 Máy phục vụ web (web server).
 Gửi các đối tượng tới client thông quan phản hồi (response).
 HTTP version:
 HTTP 1.0: RFC 1945
 HTTP 1.1: RFC 2068
Chapter 2. The Application Layer 18
HTTP: Quá trình trao đổi thông điệp
 Client (browser) thiết lập liên kết tới web server 
(TCP connection) qua cổng 80 (mặc định).
 Server đồng ý kết nối (accept).
 Các thông điệp (HTTP messages) được trao đổi 
giữa browser và server.
 Ngắt kết nối.
Chapter 2. The Application Layer 19
HTTP example
Chapter 2. The Application Layer 20
1a. http client thiết lập liên kết 
TCP với http server (process) 
tại địa chỉ www.uct2.edu.vn, 
cổng 80 (ngầm định với http 
server).
2. http client gửi http request 
message (bao gồm cả URL) tới 
TCP connection socket
1b. http server tại máy phục vụ 
www.uct2.edu.vn chờ yêu cầu 
kết nối TCP tại cổng 80, chấp 
nhận kết nối rồi thông báo với 
client.
3. http server nhận request 
message, tạo ra http response 
message có chứa các đối tượng 
được yêu cầu rồi gửi vào 
socket.
time
Giả sử người dùng truy cập URL: www.uct2.edu/index.html
(trang web có text và 10 hình ảnh jpeg)
Chapter 2. The Application Layer 21
5. http client nhận response 
message có chứa html file, hiển 
thị html. Sau đó, phân tích html 
file, tìm URL của 10 hình ảnh 
jpeg trong tài liệu.
6. Bước 1-5 được lặp lại với từng 
hình ảnh.
4. http server ngắt liên kết. 
time
HTTP Connection: Persistent & Non-persistent
Non-persistent HTTP
 Nhiều nhất là một đối 
tượng được truyền qua 
liên kết TCP.
 HTTP 1.0
Persistent HTTP
 Cho phép nhiều đối tượng 
được truyền trên cùng một 
liên kết.
 Client phân tích, tìm ra và gửi 
yêu cầu tới tất cả các đối 
tượng ngay sau khi nhận 
được trang HTML ban đầu 
(base HTML).
 HTTP 1.1 sử dụng liên kết 
loại này ở chế độ mặc định.
Chapter 2. The Application Layer 22
HTTP Message Format: request & response
 Hai loại message: request và response.
 HTTP request message: dạng ASCII (đọc được!)
Chapter 2. The Application Layer 23
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
HTTP request message
Chapter 2. The Application Layer 24
HTTP response message
Chapter 2. The Application Layer 25
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 ... 
status line
(protocol
status code
status phrase)
header
lines
data, e.g., 
requested
html file
HTTP response message
Chapter 2. The Application Layer 26
HTTP response message: status codes
Chapter 2. The Application Layer 27
200 OK
 request succeeded, requested object later in this message
301 Moved Permanently
 requested object moved, new location specified later in 
this message (Location:)
400 Bad Request
 request message not understood by server
404 Not Found
 requested document not found on this server
505 HTTP Version Not Supported
Ví dụ thực hành
1. Telnet tới web server:
Chapter 2. The Application Layer 28
Mở một kết nối (TCP) tới cổng 80 tại web server của UCT2. Sau khi 
kết nối, tất cả ký tự gõ vào sẽ được gửi tới cổng 80.
telnet 113.161.72.233 80
2. Nhập vào GET http request:
GET /dangkythilai/help.htm HTTP/1.0
Đây là một http request đơn giản. 
Nhập xong gõ 2 lần Enter để gửi tới server
3. Kiểm tra kết quả nhận được (http response message)!
User-server interaction: authentication & cookies
Chapter 2. The Application Layer 29
client server
usual http request msg
401: authorization req.
WWW authenticate:
usual http request msg
+ Authorization: 
usual http response msg
usual http request msg
+ Authorization: 
usual http response msg
time
Authenthication
Cookies: keeping “state”
 Server phát sinh một con số 
nào đó (#) khi client request, 
đồng thời ghi nhớ số này để 
sử dụng sau này:
Chứng thực 
(authentication)
Ghi nhớ sở thích, thói 
quen, lựa chọn truy 
cập lần trước.
 server gửi “cookie” tới 
client qua response msg, vd:
Set-cookie: 1678453
 Lần sau truy cập website, 
client gửi kèm cookie, vd:
cookie: 1678453
Chapter 2. The Application Layer 30
client server
usual http request msg
usual http response +
Set-cookie: #
usual http request msg
cookie: #
usual http response msg
usual http request msg
cookie: #
usual http response msg
cookie-
spectific
action
cookie-
spectific
action
Conditional GET: client-side caching
 Mục đích: server không cần 
gửi obj tới client khi client 
đã có phiên bản cập nhật 
(up-to-date) của obj.
 Client phải chỉ ra thời gian 
sửa gần đây nhất của obj 
trong http request msg.
If-modified-since: 
 Server sẽ trả về response 
msg không chứa obj nếu obj 
là cập nhật: 
HTTP/1.0 304 Not Modified
Chapter 2. The Application Layer 31
client server
http request msg
If-modified-since: 
http response
HTTP/1.0 
304 Not Modified
object 
not 
modified
http request msg
If-modified-since: 
http response
HTTP/1.1 200 OK
object 
modified
Web Caches (proxy server)
 Client gửi http requests tới 
web cache thay vì tới server.
 Nếu obj có tại web cache: web 
cache tạo http response msg 
gửi về cho client.
 Nếu không, web cache tạo gửi 
http request tới server, nhận 
obj, lưu trữ, rồi gửi http 
response msg tới client.
 Web cache sẽ khiến người 
dùng có cảm giác duyệt web 
nhanh hơn, giảm nghẽn 
mạng.
 Ví dụ: proxy server trong IE.
Chapter 2. The Application Layer 32
client
Proxy
server
client
origin 
server
origin 
server
Why Web Caching?
Assume: cache is “close” to 
client (e.g., in same 
network)
 smaller response time: 
cache “closer” to client
 decrease traffic to distant 
servers
 link out of institutional/local 
ISP network often 
bottleneck 
Chapter 2. The Application Layer 33
origin
servers
public
Internet
institutional
network
10 Mbps LAN
1.5 Mbps 
access link
institutional
cache
Caching example 
Assumptions
 average object size = 100 Kbits
 avg. request rate from 
institution’s browsers to origin 
servers = 15/sec
 delay from institutional router 
to any origin server and back to 
router = 2 sec
Consequences
 utilization on LAN = 15%
 utilization on access link = 100%
 Total delay = Internet delay + access 
delay + LAN delay
= 2 sec + minutes + milliseconds
Chapter 2. The Application Layer 34
origin
servers
public
Internet
institutional
network
10 Mbps LAN
1.5 Mbps 
access link
institutional
cache
Caching example (cont)
Possible solution
 increase bandwidth of 
access link to, say, 10 
Mbps
Consequences
 utilization on LAN = 15%
 utilization on access link = 
15%
 Total delay = Internet delay + 
access delay + LAN delay
= 2 sec + msecs + msecs
 often a costly upgrade
Chapter 2. The Application Layer 35
origin
servers
public
Internet
institutional
network
10 Mbps LAN
10 Mbps 
access link
institutional
cache
Caching example (cont)
Install cache
 suppose hit rate is 0.4
Consequence
 40% requests will be satisfied 
almost immediately
 60% requests satisfied by 
origin server
 utilization of access link 
reduced to 60%, resulting in 
negligible delays (say 10 
msec).
 Total avg delay = Internet 
delay + access delay + LAN 
delay = 0.6*(2.01) secs + 
milliseconds < 1.4 secs
Chapter 2. The Application Layer 36
origin
servers
public
Internet
institutional
network
10 Mbps LAN
1.5 Mbps 
access link
institutional
cache
Web servers
 IIS (Microsoft Internet Information Server)
Chạy trên môi trường Windows
Đi kèm Windows 2000 Server (IIS 5.0).
 Apache web server
Mã nguồn mở.
Linux/Windows

Web server được dùng nhiều nhất.
 Tomcat, Netscape, Xitami
Chapter 2. The Application Layer 37
Ch2. The Application Layer
2.1. Một số khái niệm và nguyên tắc.
2.2. Web & Hyper Text Transfer Protocol.
2.3. Web design and HTTP, Web programming.
2.4. File Transfer Protocol.
2.5. Electronic Mail Protocols.
2.6. Domain Name System.
Chapter 2. The Application Layer 38
Web design: HTML
 Thiết kế web: Tạo ra tài liệu HTML
 HTML (Hyper Text Markup Language)
 Trong tài liệu HTML có thể có nhiều đối tượng
 Text
 Images
 Hyper link
 Sử dụng thẻ (tag) để diễn đạt đối tượng.
 Thẻ mở, vd: ; ; ; 
 Thẻ đóng, vd: ; ;;
 Công cụ:
 Text editor: Notepad, Ultra Edit...
 Microsoft FrontPage
 Macromedia Dreamweaver
  ( 
Chapter 2. The Application Layer 39
Web programming
 HTML = trang web tĩnh (Static web): Web server 
luôn trả về một trang HTML cố định khi nhận được 
yêu cầu của người dùng.
 Lập trình web: tương tác với người sử dụng thông 
qua web.
Lập trình web # Lập trình Pascal, C:
 Tương tác thông qua HTTP Message.
Client-side scripts: Java script, VB script.
Server-side scripts: ASP, JSP, PHP, Perl
Chapter 2. The Application Layer 40
HTML Form: Send user requests
Simple Form
Chapter 2. The Application Layer 41
Simple ASP
<%
dim welcome
dim myName
myName=Request.Form("myName")
welcome = “Welcome " & myName & “!”
Response.Write (welcome )
%>
ASPHTML
ASP (Active Server Page)
 Microsoft/IIS.
 Một tài liệu ASP có thể coi như một tài liệu HTML có 
nhúng các script ASP, được ghi lại dạng tệp *.asp, đặt tại 
web server.
 Mỗi khi được request, các script được chạy ở phía server, 
kết quả trả về client dạng HTML (client không thấy 
source).
 Các đối tượng:
 Request Client request.
 Response Server response.
 Application
 QueryString
 Công cụ: MS Visual InterDev
Chapter 2. The Application Layer 42
Mô hình 3 lớp trong lập trình web
Chapter 2. The Application Layer 43
WEB BROWSER WEB SERVER (Apache, IIS)
ASP, PHP, JSP
DB
req
resp
DB APICác thủ tục truy xuất CSDL
CSDL
Server-side scripts
Socket programming
Socket API
 introduced in BSD 4.1 UNIX, 
1981
 explicitly created, used, released 
by apps 
 client/server paradigm 
 two types of transport service via 
socket API: 
 unreliable datagram 
 reliable, byte stream-oriented 
Chapter 2. The Application Layer 44
a host-local, 
application-created, 
OS-controlled interface 
(a “door”) into which
application process can 
both send and 
receive messages to/from 
another application 
process
socket
Goal: learn how to build client/server application that 
communicate using sockets
TCP Socket Programming
 Giao thức HTTP: application-layer protocol
 Hai ứng dụng application muốn giao tiếp phải sử dụng 
dịch vụ của tầng giao vận:
 Socket: a door between application process and end-end-transport 
protocol (UCP or TCP).
Chapter 2. The Application Layer 45
process
TCP with
buffers,
variables
socket
controlled by
application
developer
controlled by
operating
system
host or
server
process
TCP with
buffers,
variables
socket
controlled by
application
developer
controlled by
operating
system
host or
server
internet
TCP Socket: Client/server
 Server socket đã mở sẵn và đợi tại một cổng (port) 
nào đó.
Port được sử dụng để chỉ một process cụ thể sử dụng 
TCP trên một host.
 Client phải thiết lập kết nối với server (request).
 Khi server nhận yêu cầu kết nối, nó tạo ra một 
socket mới để tiếp nhận (cho phép nhiều clients).
 Microsoft Visual Basic:
Winsock: Windows Socket Component.
Chapter 2. The Application Layer 46
Winsock & OSI
Chapter 2. The Application Layer 47
Bài tập
 Tìm hiểu cú pháp ngôn ngữ HTML, từ đó xây dựng 3 trang web tĩnh 
page1.htm, page2.htm, page3.htm (nội dung của 3 trang web này tùy 
theo ý tưởng sáng tạo của mỗi người) nộp báo cáo bằng file nén 
.zip hoặc .rar bao gồm 3 file .htm và các file hình ảnh, âm 
thanhv.v liên quan (nếu có)
 Sử dụng một trong các ngôn ngữ script ASP, PHP, JSP lập trang 
web động (không bắt buộc).
 Tham khảo: 
 Sử dụng công cụ Visual Basic và Winsock component để viết một 
web server đơn giản (không bắt buộc)
 Phân tích lệnh GET
 Trả về response message thích hợp.
 Header
 Body
Chapter 2. The Application Layer 48
 : bắt đầu đóng tài liệu dạng HTML
: quy định các đặc điểm phải hiển thị trang 
HTML
: Hiển thị nội dung thanh tiêu đề cửa sổ WebBrowser
: mở/đóng phần thân của 1 trang html
: tạo liên kết (link) đến trang khác
: font chữ
: quy định đoạn văn
: hiển thị ảnh
: mở đóng một bảng
: mở đóng 1 dòng trong bảng
: mở/đóng 1 cell trong row của bảng
Chapter 2. The Application Layer 49

File đính kèm:

  • pdfbai_giang_mang_may_tinh_chuong_2_phan_a_giao_thuc_tang_ung_d.pdf