版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、1,计算机网络原理,第二章 应用层 Chapter 2 Application Layer,2.1 Principles of Application Layer Protocol,2,2.1.1 Application-Layer Protocol,应用层协议(Application Layer Protocol) 应用层协议为网络应用提供服务。网络应用是若干标准、协议等的集合,它采用 应用层协议来实现信息的传送。,例如: Web浏览器和Web服务器采用http协议进行网页传送 电子邮件程序采用SMTP协议来发送邮件、采用POP3或IMAP协议来接收邮件 网络管理程序采用SNMP来传送网络设
2、备的状态信息 ,2.1 Principles of Application Layer Protocol,3,2.1.1 Application-Layer Protocol,应用层协议(Application Layer Protocol) An application-layer protocol defines how the applications processes, running on different hosts, pass messages to each other: The types of massages exchanged. Ex. , request mess
3、ages and response messages The syntax of the various message type. Such as the fields in the messages and how the fields delineated The semantics of fields, that is, the meaning of contents in the fields Rules for determining when and how a process sends messages and responds to messages,2.1 Princip
4、les of Application Layer Protocol,4,2.1.1 Application-Layer Protocol,网络协议的共同特点Client/Server方式 网络协议由Client side和Server side组成 例如:http既有服务器端(接受请求、给予响应),又有客户端(发出请求、接收数据) 网络应用是Client/Server工作方式 Server是守侯进程(Daemon process),它倾听并随时接受呼叫,建立会话并进行数据处理和发送 ;Client总是通信的 发起者 一台主机中既可以运行一个或多个Server进程、又可以运行一个或多个Clien
5、t进程,2.1 Principles of Application Layer Protocol,5,2.1.1 Application-Layer Protocol,网络上的进程间通信(Processes Communication Across a Network) 通过Socket(套接口)来实现,网络基础设施,进程看到的传输通道,OS,开发者,实际传输通道,2.1 Principles of Application Layer Protocol,6,2.1.1 Application-Layer Protocol,网络上的进程间通信(Processes Communication Ac
6、ross a Network) Socket是一台主机内部的应用层与传送层之间的接口 也是网络应用与网络之间的应用程序接口(API),网络应用通过对API的调用来实现通信,2.1 Principles of Application Layer Protocol,7,2.1.1 Application-Layer Protocol,进程寻址(Process Addressing) 进程寻址是指发送者进程如何标识接收者进程 进程寻址至少需要两个信息 接收者进程所在的主机名或地址 IP地址 接收者进程在该主机上的标识TCP port number,2.1 Principles of Applicat
7、ion Layer Protocol,8,2.1.1 Application-Layer Protocol,用户代理(User Agent) User Agent是用户使用网络应用的接口 User Agent按照应用层协议(一个或多个)规定,调用Socket来完成报文传输任务 User Agent的例子: IE、Netscape Navigator Outlook Express、Foxmail,2.1 Principles of Application Layer Protocol,9,2.1.2 What Services Dose an Application Need?,Data Lo
8、ss 有的应用不允许数据丢失。如文件传输、电子邮件、Web应用等 有的应用能容忍一定量的数据丢失。如实时音频、视频应用,它们允许质量的降低,但不允许时间的延误,它们靠自身的强壮性保证应用不中断、靠编码等手段保证质量 因此,实际的网络应用既需要可靠的传输服务,也需要不可靠的传输服务,2.1 Principles of Application Layer Protocol,10,2.1.2 What Services Dose an Application Need?,Bandwidth 应用可分为带宽敏感应用(Bandwidth-sensitive application) 和弹性带宽应用(Ba
9、ndwidth-elastic application)两类。 实时应用是带宽敏感应用,它有基本的带宽要求,如IP Phone、Networking conference 等。 非实时应用是弹性带宽应用,它不明确要求带宽,如E-mail、FTP、Web传输等。 Bandwidth当然越宽越好,但必须实事求是。,2.1 Principles of Application Layer Protocol,11,2.1.2 What Services Dose an Application Need?,Timing(时效性) 应用可以是时效性强的,也可以是时效性弱的。 实时应用是时效性强的应用,数据必
10、须限时送达,如IP Phone、Networking conference 、Multiplayer game等。 非实时应用是时效性弱的应用,如E-mail、FTP、Web传输等 时效性与带宽等因素有关,有时必须以质量换取时效。,2.1 Principles of Application Layer Protocol,12,2.1.2 What Services Dose an Application Need?,2.1 Principles of Application Layer Protocol,13,2.1.3 Services Provided by transport-layer
11、 protocol,提供两类服务 TCP服务 UDP服务,2.1 Principles of Application Layer Protocol,14,2.1.3 Services Provided by transport-layer protocol,TCP Services Connection-oriented service 在数据传输之前,Client和Server之间通过“握手”建立连接,实际上是通信双方确认可以通信的过程,因而是松散的连接 互相之间的数据传输(双向的,或全双工的) 通信完成后拆除连接 Reliable transport service 没有数据丢失 没有数据
12、错误 没有数据重复 要进行流控制、拥塞控制 TCP保证数据能送达,但不提供带宽保证和传输时延保证,2.1 Principles of Application Layer Protocol,15,2.1.3 Services Provided by transport-layer protocol,UDP Services Connectionless service Client和Server之间不需要建立连接 任何时候都可以将报文发送给本机的UDP Socket 可以以任何可能的速率将报文发送给本机的UDP Socket Unreliable service 不保证报文一定到达接收者Sock
13、et 不保证报文按顺序到达接收者Socket 不保证报文及时到达接收者Socket 不进行流控制和拥塞控制 best-effort service,2.1 Principles of Application Layer Protocol,16,2.1.3 Services Provided by transport-layer protocol,RFC: Request for Comments , IETF (Internet Engineering Task Force) Standard Documents,2.2 The World Wide Web: HTTP,17,2.2.1 Ov
14、erview of HTTP,Web Servers document: ,http request,http request,http response,http response,Web Browser,Web Browser,HTTP 版本: HTTP 1.0(1997年前,RFC 1945) HTTP 1.1(1998年开始,RFC 2616),2.2 The World Wide Web: HTTP,18,2.2.2 Nonpersistent and Persistent Connections,Nonpersistent Connections: 为每个目标(HTML文档及其中链
15、接的对象)建立一个TCP连接 Persistent Connections: 每个页面中的所有目标共用一个TCP连接(非流水线方式) 多个页面中的所有目标共用一个TCP连接(流水线方式) HTTP 1.0Nonpersistent Connections HTTP 1.1Nonpersistent Connections, Persistent Connections,2.2 The World Wide Web: HTTP,19,2.2.2 Nonpersistent and Persistent Connections,RTT(Round-Trip Time,周游时间):Client发送请
16、求报文到接收到Server的应答报文之间的时间,假定服务器和客户机的处理时延为0,现在来讨论不同HTTP连接方式的传输性能网页传输所需的时间,2.2 The World Wide Web: HTTP,20,2.2.2 Nonpersistent and Persistent Connections,Nonpersistent Connections:,一个目标的传输时间: 2RTT+dtrans 一个网页的传输时间: (2RTT+dtrans) 多个网页的传输时间: (2RTT +dtrans),2.2 The World Wide Web: HTTP,21,2.2.2 Nonpersiste
17、nt and Persistent Connections,Persistent Connections without pipelining:,一个目标的传输时间: 2RTT+dtrans 一个网页的传输时间 2RTT +dtrans 多个网页的传输时间: (2RTT +dtrans),2.2 The World Wide Web: HTTP,22,2.2.2 Nonpersistent and Persistent Connections,Persistent Connections with pipelining:,一个目标的传输时间: 2RTT+dtrans 一个网页的传输时间 2RT
18、T +dtrans 多个网页的传输时间: 2RTT +dtran,dtrans,2.2 The World Wide Web: HTTP,23,2.2.3 HTTP Message Format,HTTP request Message,GET /somedir/page.html HTTP/1.1 Host: www.somedomain Connection: close User-agent: Mozilla/4.0 Accept-language: en (Extra carriage return and linefeed),method GET,POST,HEAD closeNon
19、persistent Mozilla/4.0Netscape navigator enEnglish,Mozilla来源于Netscape浏览器的前身Mosaic浏览器,与日本怪兽电影Gozilla两个单词的组合。1998年,Netscape公司成立了Mozilla开放源代码浏览器开发小组,并公开了Mozilla源代码。,3.17,2.2 The World Wide Web: HTTP,24,2.2.3 HTTP Message Format,HTTP method,GET:请求读一个目标 HEAD:请求读一个目标的头 PUT:请求存储一个目标 POST:附加一个命名的资源(如一个表单数据)
20、 DELETE:删除一个目标 LINK:链接两个资源 UNLINK:切断两个已经链接的资源,2.2 The World Wide Web: HTTP,25,2.2.3 HTTP Message Format,HTTP response Message,HTTP/ 1.1 200 OK Connection: Close Date: Mon,10 Mar 2005 9:29:33 GMT Server: Apache/1.3(Linux) Last-Modified: Sun,9 Mar 2004 16:44:01 GMT Content-Length: 7632 Content-Type: T
21、ext/html (Data ),2.2 The World Wide Web: HTTP,26,2.2.3 HTTP Message Format,HTTP Status Code,Status Code : 200 OK: 成功 301 Moved Permanently: 请求的对象被永久移动,在Location行中返回新URL 400 Bad Request: 服务器不明白的请求 401 Authorization Required: 需要授权,在WWW-Authenticate行中说明如何授权 404 Not Found: 请求的目标不存在 505 HTTP Version Not
22、Supported: 不支持请求的HTTP协议版本,2.2 The World Wide Web: HTTP,27,2.2.3 HTTP Message Format,HTTP session demo,查看学院网站上”云南大学软件学院院庆公告”信息: C: telnet 80 连接到Web服务器 GET /view.aspx?s=1490 HTTP/1.0 HTTP帧开始 Host: Connection: close User-agent: Mozilla/4.0 Accept-language: en HTTP帧结束,2.2 The World Wide Web: HTTP,29,2.2
23、.4 User-Server Interaction: Authentication and cookies,Authentication(访问者的身份认证),访问者的身份认证过程:,请求报文,状态码=401,WWW-Authenticate行中包含认证方法,提示用户输入用户名和密码,在Authorization行中包含用户名和密码,密码缓存,在每个目标的请求报文的Authorization行中都包含用户名和密码,2.2 The World Wide Web: HTTP,30,2.2.4 User-Server Interaction: Authentication and cookies,C
24、ookies(小甜饼、巨型炸弹、厨师?),Web站点跟踪用户的一种技术,在RFC2109中描述,用户首次访问的请求包,在Set-Cookies行中包含服务器分配的ID,追加ID及相关信息到本地的特定Cookies文件中,特定的 Cookies文件,在以后的每个请求包中都包含Cookies: ID,存放在cookies File中的信息包括:服务器主机名、与用户相关的标识信息等,2.2 The World Wide Web: HTTP,31,2.2.4 User-Server Interaction: Authentication and cookies,Cookies(小甜饼、巨型炸弹、厨师?
25、),Cookies的典型用途: 避免用户每次访问都输入用户名、密码,以简化身份认证过程。 记住用户,以便以后访问时提供该用户喜爱的信息(如广告) 跟踪用户,以便实现虚拟购物卡等特殊的网络应用,2.2 The World Wide Web: HTTP,32,2.2.5 The Conditional GET,条件 GET是向服务器询问某目标是否已经修改的机制,Client首次访问目标:any.html,Cache,响应报文中的Any.html及Last_modified中的日期,Client第二次访问目标:any.html,在请求报文的Last-Modofied行的值为:Cache中该文件的最后
26、修改日期时间,N时间后,服务器判断: 修改过吗?,发送any.html,响应报文: HTTP/1.0 304 Not Modified Date: Server: (empty entity body),从Cache中读any.html,Y,N,服务器端,客户端,2.2 The World Wide Web: HTTP,33,2.2.6 Web Cache (Proxy Server),User Agent,User Agent,Cache,Web Server,Proxy Server,Web Server,Object base,Cache,2.2 The World Wide Web:
27、HTTP,34,2.2.6 Web Cache (Proxy Server),对Client来说,Web Cache是一个Web Server 对Web Server 来说,Web cache是一个Client Web Cache是Client和Web Server之间的桥梁 Web Cache可以增强内部网络的安全性 Web Cache可以改善网络时延 Web Cache可以使出口线路更有效 Cooperative Caching能更进一步改善网络性能,2.3 File Transfer: FTP(RFC 959),35,FTP协议用于在FTP客户机、服务器之间传输文件 从客户机传送文件到服
28、务器上载 (Upload) 从服务器传送文件到客户机下载(Download),Server File System,Client File System,FTP Server,FTP Client,2.3 File Transfer: FTP,36,FTP协议使用两个TCP连接: Port Number 21为控制连接 Port Number 20为数据连接,Server File System,Client File System,FTP Server,FTP Client,TCP Control Connection Port Number: 21,TCP Data Connection
29、Port Number: 20,2.3 File Transfer: FTP,37,2.3.1 FTP Commands and Replies,FTP Command USER username: 发送用户名到服务器 PASS password: 发送密码到服务器 LIST:请求服务器发送文件列表 RETR filename:从服务器当前目录下取文件 STOR filename: 将文件存放到服务器当前目录下,2.3 File Transfer: FTP,38,2.3.1 FTP Commands and Replies,FTP replies message 331: 用户名OK,要求输入
30、密码 125: 数据连接已经打开,传输开始 425:不能打开数据连接 452:写文件到服务器上时错误,2.4 Simple Mail Transfer Protocol: SMTP(RFC 821),39,电子邮件传送过程,user Agent,user Agent,SMTP,SMTP,SMTP,SMTP,SMTP,Pop3/IMAP,Mail Server 1,Mail Server 2,Mail Server 3,DNS,DNS,DNS,SMTP port number : 25 POP3:Post Office Protocol, 110 IMAP:Internet Mail Acces
31、s , 143,2.4 Simple Mail Transfer Protocol: SMTP,40,2.4.1 SMTP(RFC 821),SMTP demo 220 ESMTP ready 28/unknown HELO 250 HELO: MAIL FROM: 250 OK (eyou mta) RCPT TO: 250 OK (eyou mta) DATA 354 Please start mail input. This a test for SMTP. . 250 Mail queued for delivery. QUIT 221 Closing con
32、nection. Good bye.,2.4 Simple Mail Transfer Protocol: SMTP,41,2.4.1 SMTP(RFC 821),SMTP command and status Code 以下是必不可少的命令: HELO 请求发送邮件 MAIL FROM 发信人邮件地址 RCPT TO 收信人邮件地址 DATA 请求输入邮件正文 . 请求结束邮件正文 QUIT 从邮件服务器退出,2.4 Simple Mail Transfer Protocol: SMTP,42,2.4.2 Mail message formats (RFC 822) and MIME,邮件报
33、文格式 From: To: Subject: .,2.4 Simple Mail Transfer Protocol: SMTP,43,2.4.2 Mail message formats (RFC 822) and MIME,MIME(Multipurpose Internet Mail Extensions) 在RFC 1341、1521、2045、2046中描述 解决二进制文件传送问题 扩展的Key Header lines: Content-Type: Type/subtype;parameters Content-Transfer-Encoding: encoding-method
34、MIME-Version: version Content-Description: description of message content (text) Content-ID: ID of this message,2.4 Simple Mail Transfer Protocol: SMTP,44,2.4.2 Mail message formats (RFC 822) and MIME,MIME(Multipurpose Internet Mail Extensions) Content-type中的parameter Charset= 用来指定字符集,例如us-ascii、ISO
35、-8859-1等,2.4 Simple Mail Transfer Protocol: SMTP,45,2.4.2 Mail message formats (RFC 822) and MIME,MIME(Multipurpose Internet Mail Extensions) Content-type中的type/subtype text 表示Body中是文本,subtype: Plain: 纯文本 Richtext: 带格式文本,例如用SGML语言(Standard generalized markup language)编排的文本 image 表示Body中是图象文件,subtype
36、: Gif: Body中是gif图象 Jpeg: Body中是jpeg图象 Audio 表示Body中是声音文件,subtype: Basic: 基本的8位-law编码 32kadpcm: 32Kbps格式编码(RFC 1911),2.4 Simple Mail Transfer Protocol: SMTP,46,2.4.2 Mail message formats (RFC 822) and MIME,MIME(Multipurpose Internet Mail Extensions) Content-type中的type和subtype video 表示Body中是视频文件,subty
37、pe: mpeg quicktime application 表示Body中是用特定程序才能打开的文档,subtype: Octet-Stream : 不间断字节流,可存入客户指定的文件 PostScript: Body中是PostScript文档 msword:表示是Word文档 message 表示Body中是一条封装后的消息(如一个完整的Mail),subtype: Rfc822: 一条RFC822消息(即完整邮件) Partial: 被拆散传送的消息 External-body: body中给出地址,内容需要从网络上获取,2.4 Simple Mail Transfer Protoco
38、l: SMTP,47,2.4.2 Mail message formats (RFC 822) and MIME,MIME(Multipurpose Internet Mail Extensions) Content-Transfer-encoding(5种): Base64 : 用64个符号对内容进行编码,64个符号依次是26个大写字母、26个小写字母、10个数字符号、+、-。 编码规则: 把二进制信息按24位分段,若最后段是8位组,则补= =;若最后段是16位组,则补=。 每段分为4个6位组,每个6位组用一个符号代替,000000用A表示、000001用B表示,依此类推。,2.4 Simp
39、le Mail Transfer Protocol: SMTP,48,2.4.3 Mail Access Protocols,POP3 (Post Office Protocol) IMAP (Internet Mail Access Protocol),2.4 Simple Mail Transfer Protocol: SMTP,49,2.4.3 Mail Access Protocols,POP3 (Post Office Protocol , RFC 1939 ) TCP Port Number: 110 功能:从邮件服务器下载邮件到本地邮件用户代理 服务器端运行POP3服务器、客户端
40、为POP3用户代理,2.4 Simple Mail Transfer Protocol: SMTP,50,2.4.3 Mail Access Protocols,POP3 (Post Office Protocol , RFC 1939 ) POP3使用示例,+OK POP3 ready user spwang +OK pass * +OK authorization succeeded (eyou mta) list +OK 1 1574 . retr 1 +OK,Received: (eyou send program); Mon, 30 Mar 2009 21:54:09 +0800 X
41、-EYOUMAIL-SMTPAUTH: Received: from 8 (HELO localhost) (8) by 2 with SMTP; Mon, 30 Mar 2009 21:54:09 +0800 From: ? To: Subject: Test Date: Mon, 30 Mar 2009 21:53:49 +0800 This is a test. . quit,2.4 Simple Mail Transfer Protocol: SMTP,51,2.4.3 Mail Access Protoco
42、ls,POP3 (Post Office Protocol , RFC 1939 ) POP3常用命令,user username pass password list retr n dele n quit,2.4 Simple Mail Transfer Protocol: SMTP,52,2.4.3 Mail Access Protocols,IMAP (Internet Mail Access Protocol) 在RFC 2060中有详细的描述 使用的TCP Port Number:143 交互式在服务器上阅读,邮件不需要下载到本地; 可维护服务器端的邮件夹,就像POP3中维护本地邮件
43、夹一样;,2.5 Domain Name System: DNS,53,UDP Port number: 53 标准:在RFC 1034、1035中有详细的描述 功能: IP地址-主机地址之间的转换; 查找域(Domain)的Mail Server 地址; 将主机别名(alias hostname)转换为正规名(canonical hostname) ; 负载分担(轮流将访问请求分布到多台服务器) 构成:大型分布式数据库系统,2.5.1 Overview of DNS,2.5 Domain Name System: DNS,54,2.5.2 How DNS Works?,Root Server
44、,,,Authoritative name server ,Local Name Server ,DB,本地服务器 根服务器 权威服务器,55,2.5.3 DNS resource records,DNS: distributed db storing resource records (RR),Type=NS name is domain (e.g. ) value is hostname of authoritative name server for this domain,Type=A name is hostname value is IP
45、address,Type=CNAME name is alias name for some “canonical” (the real) name is really value is canonical name,Type=MX value is name of mailserver associated with domain name,TTL: Time To Live,2.5 Domain Name System: DNS,56,2.5.4 DNS protocol, messages,DNS protocol : query and reply messages, both wit
46、h same message format,message header identification: 16 bit # for query, reply to query uses same # flags: query or reply recursion desired recursion available reply is authoritative,2.5 Domain Name System: DNS,57,2.5.4 DNS protocol, messages,2.5 Domain Name System: DNS,2.6 Socket Programming with T
47、CP,58,2.6.1 Socket programming with TCP,网络基础设施,进程看到的通道,OS,开发者,2.6 Socket Programming with TCP,59,2.6.1 Socket programming with TCP,Client socket,bytes,bytes,Welcome socket,Connection socket,Create connection,Three-way handshake,Client process,Server process,TCP Connection,2.6 Socket Programming with
48、 TCP,60,2.6.2 An Example Client/Server Application in Java,Create socket port=x For incoming request: WelcomeSocket= ServerSocket(),Read request from ConnectionSocket,Write reply to ConnectionSocket,Close ConnectionSocket,Waiting for incoming Connection request ConnectionSocket= WelcomeSocket.accpet
49、(),Create socket , Connect to hostid,port=x ClientSocket=Socket(),Send request using ClientSocket,Read reply from ClientSocket,Close ClientSocket,Setup TCP Connection,Server: hostid,Client,2.6 Socket Programming with TCP,61,2.6.2 An Example Client/Server Application in Java,import java.io.*; import .*; Class TCPClient Public stat
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2026年及未来5年市场数据中国钼酸行业市场竞争格局及发展趋势预测报告
- 2026年及未来5年市场数据中国竹材采运行业发展监测及市场发展潜力预测报告
- 2026年数据资产评估差异度高企的成因分析与标准化建议
- 2026年中国先进半导体材料产业竞争格局与国产化率分析
- 2026江苏南通市工会社会工作者招聘21人备考题库含完整答案详解(各地真题)
- 2026年轻工纺织行业全流程数字化改造应用指南
- 2026甘肃天水市张家川县县直事业单位选调33人备考题库附参考答案详解【综合题】
- 2026广东佛山三水区白坭镇岗头中心幼儿园春季招聘1人备考题库(达标题)附答案详解
- 2026山东省新动能基金管理有限公司校园招聘8人备考题库及参考答案详解(研优卷)
- 2026广东广州花都城投住宅建设有限公司第二次招聘项目用工人员4人备考题库含答案详解(培优b卷)
- 中小学教师绩效工资分配激励研究-基于 2024 年中小学教师绩效工资实施办法
- 2026春统编版一年级下册语文第二单元测试卷及答案
- 智能驾驶专题之四:2026智驾展望:向上升阶与向下平权的双轨渗透
- 2026年淮南职业技术学院单招职业适应性测试题库带答案详解
- 2026年汕头市普通高考第一次模拟考试 英语+答案
- 初中语文中考主旨探究与表达题知识清单
- 2026年宝山区国有(集体)企业招聘笔试参考题库附带答案详解
- 2026复工复产安全培训第9版
- 储能工程项目验收标准
- 《TCSUS69-2024智慧水务技术标准》
- 1到5的分解与组成(课堂PPT)
评论
0/150
提交评论