




已阅读5页,还剩36页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
2009PearsonEducationInc UpperSaddleRiver NJ Allrightsreserved 1 ComputerNetworksandInternets 5eByDouglasE Comer LecturePowerPointsByLamiKaya LKaya ieee org 2009PearsonEducationInc UpperSaddleRiver NJ Allrightsreserved 2 Chapter3InternetApplicationsandNetworkProgramming 2009PearsonEducationInc UpperSaddleRiver NJ Allrightsreserved 3 TopicsCovered 3 1Introduction3 2TwoBasicInternetCommunicationParadigms3 3Connection OrientedCommunication3 4TheClient ServerModelofInteraction3 5CharacteristicsofClientsandServers3 6ServerProgramsandServer ClassComputers3 7Requests Responses andDirectionofDataFlow3 8MultipleClientsandMultipleServers3 9ServerIdentificationandDemultiplexing3 10ConcurrentServers3 11CircularDependenciesAmongServers3 12Peer to PeerInteractions3 13NetworkProgrammingandtheSocketAPI 2009PearsonEducationInc UpperSaddleRiver NJ Allrightsreserved 4 TopicsCovered 3 14Sockets Descriptors andNetworkI O3 15ParametersandtheSocketAPI3 16SocketCallsinaClientandServer3 17SocketFunctionsUsedbyBothClientandServer3 18TheConnectionFunctionUsedOnlybyaClient3 19SocketFunctionsUsedOnlybyaServer3 20SocketFunctionsUsedwiththeMessageParadigm3 21OtherSocketFunctions3 22Sockets Threads andInheritance 2009PearsonEducationInc UpperSaddleRiver NJ Allrightsreserved 5 3 1Introduction TheInternetoffersusersarichdiversityofservicesnoneoftheservicesispartoftheunderlyingcommunicationinfrastructureInternetprovidesageneralpurposemechanismonwhichallservicesarebuiltandindividualservicesaresuppliedbyapplicationprogramsthatrunoncomputersattachedtotheInternetItispossibletodevisenewserviceswithoutchangingtheInternetChaptercoverstwokeyconceptsofInternetapplications describestheconceptualparadigmthatapplicationsfollowwhentheycommunicateovertheInternetpresentsthedetailsofthesocketApplicationProgrammingInterface socketAPI thatInternetapplicationsuse 2009PearsonEducationInc UpperSaddleRiver NJ Allrightsreserved 6 3 1Introduction InternetapplicationprogrammerscangetstartedeasilyItispossibletocreateInternetapplicationswithoutknowinghownetworksoperateHowever understandingnetworkprotocolsandtechnologiesallowsthemtowriteefficientandreliablecodethatenablesapplicationstoscaleacrossmanysitesLaterpartsofthetextprovidethenecessaryinformationbyexplainingdatacommunicationsandprotocolsusedtoformtheInternet 2009PearsonEducationInc UpperSaddleRiver NJ Allrightsreserved 7 3 2TwoBasicInternetCommunicationParadigms TheInternetsupportstwobasiccommunicationparadigms 3 2 1StreamTransportintheInternet3 2 2MessageTransportintheInternetFigure3 1summarizesthedifferences 3 2 1StreamTransportintheInternet StreamdenotesaparadigminwhichasequenceofbytesflowsfromoneapplicationprogramtoanotherInternet smechanismarrangestwostreamsbetweenapairofcommunicatingapplications oneineachdirectionThenetworkacceptsinputfromeitherapplication anddeliversthedatatotheotherapplicationThestreammechanismtransfersasequenceofbyteswithoutattachingmeaningtothebytesandwithoutinsertingboundariesAsendingapplicationcanchoosetogenerateonebyteatatime orcangenerateblocksofbytesThenetworkchoosesthenumberofbytestodeliveratanytimethenetworkcanchoosetocombinesmallerblocksintoonelargeblockorcandividealargeblockintosmallerblocks 2009PearsonEducationInc UpperSaddleRiver NJ Allrightsreserved 8 3 2 2MessageTransportintheInternet Inamessageparadigm thenetworkacceptsanddeliversmessagesEachmessagedeliveredtoareceivercorrespondstoamessagethatwastransmittedbyasenderthenetworkneverdeliverspartofamessage nordoesitjoinmultiplemessagestogetherifasenderplacesexactlynbytesinanoutgoingmessage thereceiverwillfindexactlynbytesintheincomingmessageThemessageparadigmallowsdeliveryindifferentforms Unicastamessagecanbesentfromanapplicationononecomputerdirectlytoanapplicationonanother 1 to 1Multicastamessagecanbemulticasttosomeofthecomputersonanetwork 1 to manyBroadcastamessagecanbebroadcasttoallcomputersonagivennetwork 1 to all 2009PearsonEducationInc UpperSaddleRiver NJ Allrightsreserved 9 3 2 2MessageTransportintheInternet MessageservicedoesnotmakeanyguaranteesSomessagesmaybeLost i e neverdelivered Duplicated morethanonecopyarrives Deliveredout of orderAprogrammerwhousesthemessageparadigmmustinsurethattheapplicationoperatescorrectlyevenifpacketsarelostorreorderedMostapplicationsrequiredeliveryguaranteesProgrammerstendtousethestreamserviceexceptinspecialsituationssuchasvideo wheremulticastisneededandtheapplicationprovidessupporttohandlepacketreorderingandlossThus wewillfocusonthestreamparadigm 2009PearsonEducationInc UpperSaddleRiver NJ Allrightsreserved 10 2009PearsonEducationInc UpperSaddleRiver NJ Allrightsreserved 11 3 3Connection OrientedCommunication TheInternetstreamserviceisconnection orientedItoperatesanalogoustoatelephonecall twoapplicationsmustrequestthataconnectionbecreatedonceithasbeenestablished theconnectionallowstheapplicationstosenddataineitherdirectionfinally whentheyfinishcommunicating theapplicationsrequestthattheconnectionbeterminatedAlgorithm3 1summarizestheinteraction 2009PearsonEducationInc UpperSaddleRiver NJ Allrightsreserved 12 3 4TheClient ServerModelofInteraction ThefirststepinAlgorithm3 1raisesaquestion howcanapairofapplicationsthatrunontwoindependentcomputerscoordinatetoguaranteethattheyrequestaconnectionatthesametime Theanswerliesinaformofinteractionknownastheclient servermodelAserverstartsfirstandawaitscontactAclientstartssecondandinitiatestheconnectionFigure3 2summarizestheinteractionSubsequentsectionsdescribehowspecificservicesusetheclient servermodelApplicationprogramsknownasclientsandservershandleallservicesintheInternet 2009PearsonEducationInc UpperSaddleRiver NJ Allrightsreserved 13 3 4TheClient ServerModelofInteraction 2009PearsonEducationInc UpperSaddleRiver NJ Allrightsreserved 14 3 5CharacteristicsofClientsandServers Mostinstancesofclient serverinteractionhavethesamegeneralcharacteristicsAclientsoftware Isanarbitraryapplicationprogramthatbecomesaclienttemporarilywhenremoteaccessisneeded butalsoperformsothercomputationIsinvokeddirectlybyauser andexecutesonlyforonesessionRunslocallyonauser spersonalcomputerActivelyinitiatescontactwithaserverCanaccessmultipleservicesasneeded butusuallycontactsoneremoteserveratatimeDoesnotrequireespeciallypowerfulcomputerhardware 2009PearsonEducationInc UpperSaddleRiver NJ Allrightsreserved 15 3 5CharacteristicsofClientsandServers Aserversoftware Isaspecial purpose privilegedprogramIsdedicatedtoprovidingoneservicethatcanhandlemultipleremoteclientsatthesametimeIsinvokedautomaticallywhenasystemboots andcontinuestoexecutethroughmanysessionsRunsonalarge powerfulcomputerWaitspassivelyforcontactfromarbitraryremoteclientsAcceptscontactfromarbitraryclients butoffersasingleserviceRequirespowerfulhardwareandasophisticatedoperatingsystem OS 2009PearsonEducationInc UpperSaddleRiver NJ Allrightsreserved 16 3 6ServerProgramsandServer ClassComputers TermserverreferstoaprogramthatwaitspassivelyforcommunicationNottothecomputeronwhichitexecutesHowever whenacomputerisdedicatedtorunningoneormoreserverprograms thecomputeritselfissometimescalledaserverHardwarevendorscontributetotheconfusionbecausetheyclassifycomputersthathavefastCPUs largememories andpowerfuloperatingsystemsasservermachinesFigure3 3illustratesthedefinitions 2009PearsonEducationInc UpperSaddleRiver NJ Allrightsreserved 17 3 6ServerProgramsandServer ClassComputers 2009PearsonEducationInc UpperSaddleRiver NJ Allrightsreserved 18 3 7Requests Responses andDirectionofDataFlow Clientandserver Whichsideinitiatescontact Oncecontacthasbeenestablished two waycommunicationispossible i e datacanflowfromaclienttoaserverorfromaservertoaclient Insomecases aclientsendsaseriesofrequestsandtheserverissuesaseriesofresponses e g adatabaseclientmightallowausertolookupmorethanoneitematatime 2009PearsonEducationInc UpperSaddleRiver NJ Allrightsreserved 19 3 8MultipleClientsandMultipleServers AllowingagivencomputertooperatemultipleserversisusefulbecausethehardwarecanbesharedasinglecomputerhaslowersystemadministrationoverheadthanmultiplecomputersystemsexperiencehasshownthatthedemandforaserverisoftensporadicaservercanremainidleforlongperiodsoftimeanidleserverdoesnotusetheCPUwhilewaitingforarequesttoarriveIfdemandforservicesislow consolidatingserversonasinglecomputercandramaticallyreducecostwithoutsignificantlyreducingperformance 2009PearsonEducationInc UpperSaddleRiver NJ Allrightsreserved 20 3 8MultipleClientsandMultipleServers Acomputercanrun AsingleclientAsingleserverMultiplecopiesofaclientthatcontactagivenserverMultipleclientsthateachcontactaparticularserverMultipleservers eachforaparticularserviceAllowingacomputertooperatemultipleclientsisusefulbecauseservicescanbeaccessedsimultaneouslyForexample ausercanhavethree 3 windowsopensimultaneouslyrunningthree 3 applications onethatretrievesanddisplaysemailanotherthatconnectstoachatserviceandathirdrunningawebbrowser 2009PearsonEducationInc UpperSaddleRiver NJ Allrightsreserved 21 3 9ServerIdentificationandDemultiplexing Howdoesaclientidentifyaserver TheInternetprotocolsdivideidentificationintotwopieces AnidentifierforthecomputeronwhichaserverrunsAnidentifierforaserviceonthecomputerIdentifyingacomputer EachcomputerintheInternetisassignedaunique32 bitidentifierknownasanInternetProtocoladdress IPaddress Aclientmustspecifytheserver sIPaddressTomakeserveridentificationeasyforhumans eachcomputerisalsoassignedaname andtheDomainNameSystem DNS describedinChapter4isusedtotranslateanameintoanaddressThus ratherthananintegeraddress 2009PearsonEducationInc UpperSaddleRiver NJ Allrightsreserved 22 3 9ServerIdentificationandDemultiplexing Identifyingaservice EachserviceavailableintheInternetisassignedaunique16 bitidentifierknownasaprotocolportnumber orportnumber Examples email portnumber25 andtheweb portnumber80WhenaserverbeginsexecutionitregisterswithitslocalOSbyspecifyingtheportnumberforitsserviceWhenaclientcontactsaremoteservertorequestservicetherequestcontainsaportnumberWhenarequestarrivesataserversoftwareontheserverusestheportnumberintherequesttodeterminewhichapplicationontheservercomputershouldhandletherequestFigure3 4summarizesthebasicsteps 2009PearsonEducationInc UpperSaddleRiver NJ Allrightsreserved 23 3 9ServerIdentificationandDemultiplexing 2009PearsonEducationInc UpperSaddleRiver NJ Allrightsreserved 24 3 10ConcurrentServers ThestepsinFigure3 4implythataserverhandlesoneclientatatimeAlthoughaserialapproachworksinafewtrivialcases mostserversareconcurrentThatis aserverusesmorethanonethreadofcontrolConcurrentexecutiondependsontheOSbeingusedConcurrentservercodeisdividedintotwopiecesamainprogram thread ahandlerThemainthreadacceptscontactfromaclientandcreatesathreadofcontrolfortheclientEachthreadofcontrolinteractswithasingleclientandrunsthehandlercode 2009PearsonEducationInc UpperSaddleRiver NJ Allrightsreserved 25 3 10ConcurrentServers AfterhandlingoneclientthethreadterminatesThemainthreadkeepstheserveraliveaftercreatingathreadtohandlearequestthemainthreadwaitsforanotherrequesttoarriveIfNclientsaresimultaneouslyusingaconcurrentserver N 1threadswillberunning themainthread 1 iswaitingforadditionalrequestsandNthreadsareeachinteractingwithasingleclient 2009PearsonEducationInc UpperSaddleRiver NJ Allrightsreserved 26 3 11CircularDependenciesAmongServers Inpractice thedistinctionblursbecauseaserverforoneservicecanactasaclientforanotherForexample beforeitcanfillinawebpage awebservermayneedtobecomeaclientofadatabaseAservermayalsobecometheclientofasecurityservice e g toverifythataclientisallowedtoaccesstheservice ProgrammersmustbecarefultoavoidcirculardependenciesamongserversForexample considerwhatcanhappenifaserverforserviceXbecomesaclientofserviceX whichbecomesaclientofserviceX whichbecomesaclientofXThechainofrequestscancontinueindefinitelyuntilallthreeserversexhaustresourcesThepotentialforcircularityisespeciallyhighwhenservicesaredesignedindependentlybecausenosingleprogrammercontrolsallservers 2009PearsonEducationInc UpperSaddleRiver NJ Allrightsreserved 27 3 12Peer to PeerInteractions IfasingleserverprovidesagivenservicethenetworkconnectionbetweentheserverandtheInternetcanbecomeabottleneckFigure3 5illustratesthearchitecture 2009PearsonEducationInc UpperSaddleRiver NJ Allrightsreserved 28 3 12Peer to PeerInteractions CanInternetservicesbeprovidedwithoutcreatingacentralbottleneck Onewaytoavoidabottleneckformsthebasisoffilesharingknownasapeer to peer P2P architectureTheschemeavoidsplacingdataonacentralserverdataisdistributedequallyamongasetofNserversandeachclientrequestissenttotheappropriateserveragivenserveronlyprovides1 NofthedatatheamountoftrafficbetweenaserverandtheInternetis1 Nasmuchasinthesingle serverarchitectureServersoftwarecanrunonthesamecomputersasclientsFigure3 6illustratesthearchitecture 2009PearsonEducationInc UpperSaddleRiver NJ Allrightsreserved 29 3 12Peer to PeerInteractions 2009PearsonEducationInc UpperSaddleRiver NJ Allrightsreserved 30 3 13NetworkProgrammingandtheSocketAPI TheinterfaceanapplicationusestospecifycommunicationisknownasanApplicationProgramInterface API Appendix1containsasimplifiedAPI withonlysevenfunctions examplecodethatdemonstrateshowsuchanAPIcanbeusedtocreateInternetapplications includingaworkingwebserverDetailsofanAPIdependontheOSOneparticularAPIhasemergedasthedefactostandardforsoftwarethatcommunicatesovertheInternetknownasthesocketAPI andcommonlyabbreviatedsocketsThesocketAPIisavailableformanyOSsuchasMicrosoft sWindowssystemsaswellasvariousUNIXsystems includingLinux 2009PearsonEducationInc UpperSaddleRiver NJ Allrightsreserved 31 3 14Sockets Descriptors andNetworkI O BecauseitwasoriginallydevelopedaspartoftheUNIXOS thesocketAPIisintegratedwithI OWhenanapplicationcreatesasockettouseforInternetOSreturnsasmallintegerdescriptorthatidentifiesthesocketTheapplicationthenpassesthedescriptorasanargumentwhenitcallsfunctionstoperformanoperationonthesocket e g totransferdataacrossthenetworkortoreceivedata InmanyOS socketdescriptorsareintegratedwithotherI Odescriptorsasaresult anapplicationcanusethereadandwriteoperationsforsocketI OorI Otoafile 2009PearsonEducationInc UpperSaddleRiver NJ Allrightsreserved 32 3 15ParametersandtheSocketAPI SocketprogrammingdiffersfromconventionalI OAnapplicationmustspecifymanydetails suchastheaddressofaremotecomputertheprotocolportnumberandwhethertheapplicationwillactasaclientorasaserverToavoidhavingasinglesocketfunctionwithmanyparameters designersofthesocketAPIchosetodefinemanyfunctionsAnapplicationcreatesasocket andtheninvokesfunctionsfordetailsTheadvantageofthesocketapproachisthatmostfunctionshavethreeorfewerparametersThedisadvantageisthataprogrammermustremembertocallmultiplefunctionswhenusingsocketsFigure3 7summarizeskeyfunctionsinthesocketAPI 2009PearsonEducationInc UpperSaddleRiver NJ Allrightsreserved 33 2009PearsonEducationInc UpperSaddleRiver NJ Allrightsreserved 34 3 16SocketCallsinaClientandServer Figure3 8illustratesthesequenceofsocketcallsmadebyatypicalclientandserverthatuseastreamconnectionTheclientsendsdatafirstandtheserverwaitstoreceivedataInpractice someapplicationsarrangefortheservertosendfirst i e sendandrecvarecalledinthereverseorder 2009PearsonEducationInc UpperSaddleRiver NJ Allrightsreserved 35 2009PearsonEducationInc UpperSaddleRiver NJ Allrightsreserved 36 3 17SocketFunctionsUsedbyBothClientandServer Readersareencouragedtocheckthebookforthedetailsofthesefunctions3 17 1TheSocketFunction3 17 2TheSendFunction3 17 3TheRecvFunction3 17 4ReadandWritewithSockets3 17 5TheCloseFunction 2009PearsonEducationInc UpperSaddleRiver NJ Allrightsreserved 37 3 18TheConnectionFunctionUsedOnlybyaClient Clientscallconnecttoestablishaconnectionwithaspecificserver Theformis connect socket saddress saddresslen ArgumentsocketisthedescriptorofasockettousefortheconnectionReadersareencouragedtocheckthebookforthedetails 2009PearsonEducationInc UpperSaddleRiver NJ Allrightsreserved 38 3 19SocketFunctionsUsedOnlybyaServer Readersareencouragedtocheckthebookforthedetailsofthesefunctions3 19 1TheBindFuncti
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025北京海淀第十九中学教师招聘模拟试卷附答案详解(突破训练)
- 2025年西安经开第七小学招聘数学教师考前自测高频考点模拟试题及答案详解一套
- 2025福建武夷山市供销总公司招聘3人模拟试卷及答案详解(夺冠)
- 2025贵州黔西南州兴义民族师范学院高层次人才引进20人模拟试卷及答案详解参考
- 2025广东深圳市优才人力资源有限公司招聘编外聘用人员拟聘人员考前自测高频考点模拟试题及参考答案详解
- 2025年滁州明光市公开引进高中教育紧缺人才11人考前自测高频考点模拟试题及答案详解(必刷)
- 2025河南许昌市建安区人力资源和社会保障局招聘公益性岗位人员13人考前自测高频考点模拟试题及答案详解(夺冠)
- 2025广西南宁隆安县南圩镇杨湾卫生院医学影像专业招聘1人模拟试卷及答案详解(易错题)
- 安全培训教学图课件
- 安全培训救护小结课件
- 小学数学西南师大四年级上册二加减法的关系和加法运算律《减法的运算性质》教学设计
- 深信服SDWAN产品介绍
- 通信光缆线路工程安全技术交底大全
- 购牛合同参考参考
- 纳迪亚之宝全流程攻略 100%完结完整通关指南
- 高一语法——句子成分、句式
- mc2200监控模块后台通讯协议v
- 第四讲政府间关系
- GB 30678-2014 客车用安全标志和信息符号(高清版)
- 中国传统节气二十四节气秋分简介农民丰收节专题资料PPT课件
- 起诉状(变更抚养权)
评论
0/150
提交评论