




已阅读5页,还剩64页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
Chapter2ApplicationLayer ComputerNetworking ATopDownApproach 4thedition JimKurose KeithRossAddison Wesley July2007 Chapter2 Applicationlayer 2 1Principlesofnetworkapplications2 2WebandHTTP2 3FTP2 4ElectronicMailSMTP POP3 IMAP2 5DNS2 6P2Papplications ElectronicMail Threemajorcomponents useragentsmailserverssimplemailtransferprotocol SMTPUserAgentcomposing editing readingmailmessagese g foxmail Outlook NetscapeMessengeroutgoing incomingmessagesstoredonserver 收到和要发的邮件存在服务器中 usermailbox outgoingmessagequeue 电子邮件的发送和接收过程 发送方 邮件缓存 接收端邮件服务器 用户代理 发送端邮件服务器 用户代理 接收方 用户代理 用户代理 邮件服务器 邮件服务器 因特网 1 发信人调用用户代理来编辑要发送的邮件 用户代理用SMTP把邮件传送给发送端邮件服务器 电子邮件的发送和接收过程 发送方 接收端邮件服务器 用户代理 SMTP 发送端邮件服务器 用户代理 接收方 用户代理 用户代理 邮件服务器 邮件服务器 SMTP 发送邮件 发送邮件 TCP连接 因特网 2 发送端邮件服务器将邮件放入邮件缓存队列中 等待发送 电子邮件的发送和接收过程 发送方 邮件缓存 接收端邮件服务器 用户代理 SMTP 发送端邮件服务器 用户代理 接收方 用户代理 用户代理 邮件服务器 邮件服务器 SMTP 发送邮件 发送邮件 TCP连接 因特网 3 运行在发送端邮件服务器的SMTP客户进程 发现在邮件缓存中有待发送的邮件 就向运行在接收端邮件服务器的SMTP服务器进程发起TCP连接的建立 电子邮件的发送和接收过程 发送方 邮件缓存 接收端邮件服务器 用户代理 SMTP 发送端邮件服务器 用户代理 接收方 用户代理 用户代理 邮件服务器 邮件服务器 SMTP 发送邮件 发送邮件 TCP连接 因特网 4 TCP连接建立后 SMTP客户进程开始向远程的SMTP服务器进程发送邮件 当所有的待发送邮件发完了 SMTP就关闭所建立的TCP连接 电子邮件的发送和接收过程 发送方 邮件缓存 接收端邮件服务器 用户代理 SMTP 发送端邮件服务器 用户代理 接收方 用户代理 用户代理 邮件服务器 邮件服务器 SMTP 发送邮件 发送邮件 TCP连接 因特网 5 运行在接收端邮件服务器中的SMTP服务器进程收到邮件后 将邮件放入收信人的用户邮箱中 等待收信人在方便时进行读取 电子邮件的发送和接收过程 发送方 邮件缓存 接收端邮件服务器 用户代理 SMTP 发送端邮件服务器 用户代理 接收方 用户代理 用户代理 邮件服务器 邮件服务器 SMTP 发送邮件 发送邮件 TCP连接 因特网 6 收信人在打算收信时 调用用户代理 使用POP3 或IMAP 协议将自己的邮件从接收端邮件服务器的用户邮箱中的取回 如果邮箱中有来信的话 应当注意 由于SMTP使用客户服务器方式 因此负责发送邮件的SMTP进程就是SMTP客户 而负责接收邮件的SMTP进程就是SMTP服务器 一个邮件服务器既可以作为客户 也可以作为服务器 例如 当邮件服务器A向另一个邮件服务器B发送邮件时 邮件服务器A就作为SMTP客户 而B是SMTP服务器 当邮件服务器A从另一个邮件服务器B接收邮件时 邮件服务器A就作为SMTP服务器 而B是SMTP客户 ElectronicMail SMTP RFC2821 usesTCPtoreliablytransferemailmessagefromclienttoserver port25threephasesoftransferhandshaking greeting transferofmessagesclosurecommand responseinteractioncommands ASCIItextresponse statuscodeandphrasemessagesmustbein7 bitASCII 简单邮件传送协议SMTP SMTP规定了14条命令和21种应答信息 每条命令用4个字母组成 而每一种应答信息一般只有一行信息 由一个3位数字的代码开始 后面附上 也可不附上 很简单的文字说明 SMTP通信的三个过程1 连接建立 连接是在发送主机的SMTP客户和接收主机的SMTP服务器之间建立的 SMTP不使用中间的邮件服务器 2 邮件传送3 连接释放 邮件发送完毕后 SMTP应释放TCP连接 Mailmessageformat SMTP protocolforexchangingemailmsgsRFC822 standardfortextmessageformat headerlines e g To From Subject differentfromSMTPcommands bodythe message ASCIIcharactersonly header body blankline 邮件内容的首部 To 后面填入一个或多个收信人的电子邮件地址 用户只需打开地址簿 点击收信人名字 收信人的电子邮件地址就会自动地填入到合适的位置上 Subject 是邮件的主题 它反映了邮件的主要内容 便于用户查找邮件 抄送 Cc 表示应给某某人发送一个邮件副本 From 和 Date 表示发信人的电子邮件地址和发信日期 Reply To 是对方回信所用的地址 Messageformat multimediaextensions MIME multimediamailextension RFC2045 2056additionallinesinmsgheaderdeclareMIMEcontenttype multimediadatatype subtype parameterdeclaration methodusedtoencodedata MIMEversion encodeddata MIME和SMTP的关系 MIME并没有改动SMTP或取代它 MIME的意图是继续使用目前的 RFC822 格式 但增加了邮件主体的结构 并定义了传送非ASCII码的编码规则 非ASCII码 7位ASCII码 MIME SMTP MIME SMTP 7位ASCII码 7位ASCII码 非ASCII码 用户 用户 MIME主要包括三个部分 5个新的邮件首部字段 它们可包含在 RFC822 首部中 这些字段提供了有关邮件主体的信息 定义了许多邮件内容的格式 对多媒体电子邮件的表示方法进行了标准化 定义了传送编码 可对任何内容格式进行转换 而不会被邮件系统改变 MIME增加5个新的邮件首部 MIME Version 标志MIME的版本 现在的版本号是1 0 若无此行 则为英文文本 Content Description 这是可读字符串 说明此邮件是什么 和邮件的主题差不多 Content Id 邮件的惟一标识符 Content Transfer Encoding 在传送时邮件的主体是如何编码的 Content Type 说明邮件的性质 Mailaccessprotocols SMTP delivery storagetoreceiver sserverMailaccessprotocol retrievalfromserverPOP PostOfficeProtocol RFC1939 authorization agentserver anddownloadIMAP InternetMailAccessProtocol RFC1730 morefeatures morecomplex manipulationofstoredmsgsonserverHTTP Hotmail Yahoo Mail etc SMTP accessprotocol receiver smailserver POP3protocol authorizationphaseclientcommands user declareusernamepass passwordserverresponses OK ERRtransactionphase client list listmessagenumbersretr retrievemessagebynumberdele deletequit C listS 1498S 2912S C retr1S S C dele1C retr2S S C dele2C quitS OKPOP3serversigningoff S OKPOP3serverreadyC userbobS OKC passhungryS OKusersuccessfullyloggedon POP3 more andIMAP MoreaboutPOP3Previousexampleuses downloadanddelete mode Bobcannotre reade mailifhechangesclient Download and keep copiesofmessagesondifferentclientsPOP3isstatelessacrosssessions IMAPKeepallmessagesinoneplace theserverAllowsusertoorganizemessagesinfoldersIMAPkeepsuserstateacrosssessions namesoffoldersandmappingsbetweenmessageIDsandfoldername Chapter2 Applicationlayer 2 1Principlesofnetworkapplications2 2WebandHTTP2 3FTP2 4ElectronicMailSMTP POP3 IMAP2 5DNS2 6P2Papplications 域名系统DNS IP地址虽然包含网络号和主机号 但难于记忆 无法通过IP地址猜测主机的用途 因此必须用更友好的 便于记忆的名字来代替数字IP地址 主机名字要求全局唯一的 即能在整个Internet通用 要便于管理 Internet中主机名字管理工作包括名字分配 确认和名字回收等 DNS 国家名码 DNS 国际流行域类型 因特网的域名空间 根 域名示例 服务器类型 公司名 域类型 服务器名 系名 学校名 域类型 国家名 服务器类型 网络名 域类型服务器名 组织名 域类型www whitehouse govwww ieee org主机名 研究机构名 学校名 域类型 国家名 新增加了下列的通用顶级域名 aero 航空运输企业 biz 公司和企业 cat 加泰隆人的语言和文化团体 coop 合作团体 info 各种情况 jobs 人力资源管理者 mobi 移动产品与服务的用户和提供者 museum 博物馆 name 个人 pro 有证书的专业人员 travel 旅游业 域名服务器 由于在通信时采用的是IP地址 所以通信前必须将主机的域名转换成IP地址 实现域名与IP之间互相转化的系统称之为域名服务系统 DomainNameSystem DNS 这个转换过程又称为域名解析 NameResolution DNS服务器以层次型结构分布在世界各地 使用了分布式的数据库 每台DNS服务器存储一部分域名数据 DNS DomainNameSystem DomainNameSystem distributeddatabaseimplementedinhierarchyofmanynameserverscoreInternetfunction implementedasapplication layerprotocol DNS WhynotcentralizeDNS singlepointoffailuretrafficvolumedistantcentralizeddatabasemaintenance Distributed HierarchicalDatabase ClientwantsIP 1stapprox ClientqueriesarootservertofindcomDNSserverClientqueriescomDNSDNSserverCDNSservertogetIP DNS Rootnameservers contactedbylocalnameserverthatcannotresolvenamerootnameserver contactsauthoritativenameserverifnamemappingnotknowngetsmappingreturnsmappingtolocalnameserver TLDandAuthoritativeServers Top leveldomain TLD servers responsibleforcom org net edu etc andalltop levelcountrydomainsuk fr ca jp NetworksolutionsmaintainsserversforcomTLDEducauseforeduTLDAuthoritativeDNSservers organization sDNSservers providingauthoritativehostnametoIPmappingsfororganization sserversCanbemaintainedbyorganizationorserviceprovider LocalNameServer DoesnotstrictlybelongtohierarchyEachISP residentialISP company university hasone Alsocalled defaultnameserver WhenahostmakesaDNSquery queryissenttoitslocalDNSserverActsasaproxy forwardsqueryintohierarchy requestinghostcis poly edu gaia cs umass edu rootDNSserver 1 2 3 4 5 6 authoritativeDNSserverdns cs umass edu 7 8 TLDDNSserver Example Hostatcis poly eduwantsIPaddressforgaia cs umass edu requestinghostcis poly edu gaia cs umass edu rootDNSserver 1 2 4 5 6 authoritativeDNSserverdns cs umass edu 7 8 TLDDNSserver 3 Recursivequeries递归查询 recursivequery 递归查询 putsburdenofnameresolutiononcontactednameserverheavyloaditeratedquery 迭代查询contactedserverreplieswithnameofservertocontact Idon tknowthisname butaskthisserver DNS cachingandupdatingrecords once any nameserverlearnsmapping itcachesmappingcacheentriestimeout disappear aftersometimeTLDserverstypicallycachedinlocalnameserversThusrootnameserversnotoftenvisitedupdate notifymechanismsunderdesignbyIETFRFC2136http www ietf org html charters dnsind charter html Chapter2 Applicationlayer 2 1Principlesofnetworkapplications2 2WebandHTTP2 3FTP2 4ElectronicMailSMTP POP3 IMAP2 5DNS2 6P2Papplications2 7SocketprogrammingwithTCP2 8SocketprogrammingwithUDP2 9BuildingaWebserver P2Pfilesharing ExampleAlicerunsP2PclientapplicationonhernotebookcomputerIntermittentlyconnectstoInternet getsnewIPaddressforeachconnectionAsksfor HeyJude ApplicationdisplaysotherpeersthathavecopyofHeyJude Alicechoosesoneofthepeers Bob FileiscopiedfromBob sPCtoAlice snotebook HTTPWhileAlicedownloads otherusersuploadingfromAlice Alice speerisbothaWebclientandatransientWebserver Allpeersareservers highlyscalable P2P centralizeddirectory original Napster design1 whenpeerconnects itinformscentralserver IPaddresscontent2 Alicequeriesfor HeyJude 3 AlicerequestsfilefromBob P2P problemswithcentralizeddirectory SinglepointoffailurePerformancebottleneckCopyrightinfringement 版权侵犯 filetransferisdecentralized butlocatingcontentishighlycentralized Queryflooding Gnutella fullydistributednocentralserverpublicdomainprotocolmanyGnutellaclientsimplementingprotocol overlaynetwork覆盖型网络 graphedgebetweenpeerXandYifthere saTCPconnectionallactivepeersandedgesisoverlaynetEdgeisnotaphysicallinkGivenpeerwilltypicallybeconnectedwith 10overlayneighbors Gnutella protocol Filetransfer HTTP QuerymessagesentoverexistingTCPconnectionspeersforwardQuerymessageQueryHitsentoverreversepath Scalability limitedscopeflooding Gnutella Peerjoining JoiningpeerXmustfindsomeotherpeerinGnutellanetwork uselistofcandidatepeersXsequentiallyattemptstomakeTCPwithpeersonlistuntilconnectionsetupwithYXsendsPingmessagetoY YforwardsPingmessage AllpeersreceivingPingmessagerespondwithPongmessageXreceivesmanyPongmessages ItcanthensetupadditionalTCPconnections Exploitingheterogeneity KaZaA Eachpeeriseitheragroupleaderorassignedtoagroupleader TCPconnectionbetweenpeeranditsgroupleader TCPconnectionsbetweensomepairsofgroupleaders Groupleadertracksthecontentinallitschildren KaZaA Querying EachfilehasahashandadescriptorClientsendskeywordquerytoitsgroupleaderGroupleaderrespondswithmatches Foreachmatch metadata hash IPaddressIfgroupleaderforwardsquerytoothergroupleaders theyrespondwithmatchesClientthenselectsfilesfordownloadingHTTPrequestsusinghashasidentifiersenttopeersholdingdesiredfile Chapter2 Applicationlayer 2 1Principlesofnetworkapplications2 2WebandHTTP2 3FTP2 4ElectronicMailSMTP POP3 IMAP2 5DNS2 6P2Papplications2 7SocketprogrammingwithTCP2 8SocketprogrammingwithUDP2 9BuildingaWebserver Socketprogramming SocketAPIintroducedinBSD4 1UNIX 1981explicitlycreated used releasedbyappsclient serverparadigmtwotypesoftransportserviceviasocketAPI unreliabledatagramreliable bytestream oriented Goal learnhowtobuildclient serverapplicationthatcommunicateusingsockets Socket programmingusingTCP Socket adoorbetweenapplicationprocessandend end transportprotocol UCPorTCP TCPservice reliabletransferofbytesfromoneprocesstoanother controlledbyapplicationdeveloper controlledbyoperatingsystem hostorserver controlledbyapplicationdeveloper controlledbyoperatingsystem hostorserver internet SocketprogrammingwithTCP Clientmustcontactserverserverprocessmustfirstberunningservermusthavecreatedsocket door thatwelcomesclient scontactClientcontactsserverby creatingclient localTCPsocketspecifyingIPaddress portnumberofserverprocessWhenclientcreatessocket clientTCPestablishesconnectiontoserverTCP Whencontactedbyclient serverTCPcreatesnewsocketforserverprocesstocommunicatewithclientallowsservertotalkwithmultipleclientssourceportnumbersusedtodistinguishclients moreinChap3 Client serversocketinteraction TCP Server runningonhostid Client Clientprocess clientTCPsocket Streamjargon Astreamisasequenceofcharactersthatflowintooroutofaprocess Aninputstreamisattachedtosomeinputsourcefortheprocess e g keyboardorsocket Anoutputstreamisattachedtoanoutputsource e g monitororsocket SocketprogrammingwithTCP Exampleclient serverapp 1 clientreadslinefromstandardinput inFromUserstream sendstoserverviasocket outToServerstream 2 serverreadslinefromsocket3 serverconvertslinetouppercase sendsbacktoclient4 clientreads printsmodifiedlinefromsocket inFromServerstream Example Javaclient TCP importjava io classTCPClient publicstaticvoidmain Stringargv throwsException Stringsentence StringmodifiedSentence BufferedReaderinFromUser newBufferedReader newInputStreamReader System in SocketclientSocket newSocket hostname 6789 DataOutputStreamoutToServer newDataOutputStream clientSocket getOutputStream Createinputstream Createclientsocket connecttoserver Createoutputstreamattachedtosocket Example Javaclient TCP cont BufferedReaderinFromServer newBufferedReader newInputStreamReader clientSocket getInputStream sentence inFromUser readLine outToServer writeBytes sentence n modifiedSentence inFromServer readLine System out println FROMSERVER modifiedSentence clientSocket close Createinputstreamattachedtosocket Sendlinetoserver Readlinefromserver Example Javaserver TCP importjava io classTCPServer publicstaticvoidmain Stringargv throwsException StringclientSentence StringcapitalizedSentence ServerSocketwelcomeSocket newServerSocket 6789 while true SocketconnectionSocket welcomeSocket accept BufferedReaderinFromClient newBufferedReader newInputStreamReader connectionSocket getInputStream Createwelcomingsocketatport6789 Wait onwelcomingsocketforcontactbyclient Createinputstream attachedtosocket Example Javaserver TCP cont DataOutputStreamoutToClient newDataOutputStream connectionSocket getOutputStream clientSentence inFromClient readLine capitalizedSentence clientSentence toUpperCase n outToClient writeBytes capitalizedSentence Readinlinefromsocket Createoutputstream attachedtosocket Writeoutlinetosocket Endofwhileloop loopbackandwaitforanotherclientconnection TCP面向流的概念 发送TCP报文段 发送方 接收方 把字节写入发送缓存 从接收缓存读取字节 应用进程 应用进程 18 17 16 15 14 H 加上TCP首部构成TCP报文段 TCP TCP 字节流 字节流 H 表示TCP报文段的首部 x 表示序号为x的数据字节 TCP连接 Chapter2 Applicationlayer 2 1Principlesofnetworkapplications2 2WebandHTTP2 3FTP2 4ElectronicMailSMTP POP3 IMAP2 5DNS 2 6P2Pfilesharing2 7SocketprogrammingwithTCP2 8SocketprogrammingwithUDP2 9BuildingaWebserver Berkley套接字 服务器首先用SOCKET函数产生一个套接字 然后用BIND函数把这个套接字绑到一个自己的IP上 然后再调用LISTEN函数 进入监听模式 再调用ACCEPT函数接受客户端连接 连接建立后 ACCEPT返回一个套接字 以后就用这个套接字与客户端通信 SocketprogrammingwithUDP UDP no connection betweenclientandservernohandshakingsenderexplicitlyattachesIPaddressandportofdestinationtoeachpacketservermustextractIPaddress portofsenderfromreceivedpacketUDP transmitteddatamaybereceivedoutoforder orlost Client serversocketinteraction UDP Server runningonhostid Example Javaclient UDP Output sendspacket recallthatTCPsent bytestream Input receivespacket recallthatTCPreceived bytestream Clientprocess clientUDPsocket Example Javaclient UDP importjava io classUDPClient publicstaticvoidmain Stringargs throwsException BufferedReaderinFromUser newBufferedReader newInputStreamReader System in DatagramSocketclientSocket newDatagramSocket InetAddressIPAddress InetAddress getByName hostname byte sendData newbyte 1024 byte receiveData newbyte 1024 Stringsentence inFromUser readLine send
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 时间的脚步课件
- 时间沈从文句子课件
- 小学语文板书培训
- 2025版农业科技孵化基地入驻项目合作协议
- 二零二五版法人股份转让与员工激励计划协议
- 二零二五年度城市轨道交通截桩施工合同
- 二零二五版农业科技推广与应用服务合同
- 2025版办公室装修工程合同范本
- 二零二五年度矿山地质勘查服务合同汇编
- 二零二五年度金融理财产品购销合同范本
- 义务消防队组建方案
- 中邮保险笔试题型及答案
- 2025-2030中国ARM核心板行业市场现状分析及竞争格局与投资发展研究报告
- 脐灸技术操作流程图及考核标准
- 给药错误PDCA课件
- 医美注射培训
- 2025至2031年中国缓冲体总成行业投资前景及策略咨询研究报告
- 香菇多糖生产工艺创新-洞察分析
- 箱泵一体化泵站设计图集
- 三上10《公共场所文明言行》道德法治教学设计
- 可研报告收费标准(国家标准)
评论
0/150
提交评论