資源描述:
《分布式計算原理與應(yīng)用(Distributed Computing)第四章課件》由會員上傳分享,免費在線閱讀,更多相關(guān)內(nèi)容在教育資源-天天文庫。
1、TheSocketAPIMei-LingLiu9/17/20211DistributedComputing,M.L.LiuIntroductionThesocketAPIisanInterprocessingCommunication(IPC)programminginterfaceoriginallyprovidedaspartoftheBerkeleyUNIXoperatingsystem.Ithasbeenportedtoallmodernoperatingsystems,includingSunSolarisandWindowssystems.Itisadefactostandardf
2、orprogrammingIPC,andisthebasisofmoresophisticatedIPCinterfacesuchasremoteprocedurecallandremotemethodinvocation.9/17/20212DistributedComputing,M.L.LiuTheconceptualmodelofthesocketAPI9/17/20213DistributedComputing,M.L.LiuThesocketAPIAsocketAPIprovidesaprogrammingconstructtermedasocket.Aprocesswishing
3、tocommunicatewithanotherprocessmustcreateaninstance,orinstantiate,suchaconstructThetwoprocessesthenissuesoperationsprovidedbytheAPItosendandreceivedata.9/17/20214DistributedComputing,M.L.LiuConnection-oriented&connectionlessdatagramsocketAsocketprogrammingconstructcanmakeuseofeithertheUDPorTCPprotoc
4、ol.SocketsthatuseUDPfortransportareknownasdatagramsockets,whilesocketsthatuseTCParetermedstreamsockets.Becauseofitsrelativesimplicity,wewillfirstlookatdatagramsockets,returningtostreamsocketsafterwehaveintroducedtheclient-servermodelinChapter5.9/17/20215DistributedComputing,M.L.LiuConnection-oriente
5、d&connectionlessdatagramsocketDatagramsocketscansupportbothconnectionlessandconnection-orientedcommunicationattheapplicationlayer.Thisissobecauseeventhoughdatagramsaresentorreceivedwithoutthenotionofconnectionsatthetransportlayer,theruntimesupportofthesocketAPIcancreateandmaintainlogicalconnectionsf
6、ordatagramsexchangedbetweentwoprocesses,asyouwillseeinthenextsection.(TheruntimesupportofanAPIisasetofsoftwarethatisboundtotheprogramduringexecutioninsupportoftheAPI.)9/17/20216DistributedComputing,M.L.LiuConnection-oriented&connectionlessdatagramsocket9/17/20217DistributedComputing,M.L.LiuTheJavaDa
7、tagramSocketAPIInJava,twoclassesareprovidedforthedatagramsocketAPI:theDatagramSocketclassforthesockets.theDatagramPacketclassforthedatagramexchanged.AprocesswishingtosendorreceivedatausingthisAPImusti