计算机网络概论 英文版.ppt_第1页
计算机网络概论 英文版.ppt_第2页
计算机网络概论 英文版.ppt_第3页
计算机网络概论 英文版.ppt_第4页
计算机网络概论 英文版.ppt_第5页
已阅读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. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

最新文档

评论

0/150

提交评论