欢迎来到天天文库
浏览记录
ID:55460386
大小:91.50 KB
页数:14页
时间:2020-05-14
《所谓服务器听,是服务器端套接字并不定位具体的客户端.doc》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、所谓服务器监听,是服务器端套接字并不定位具体的客户端套接字,而是处于等待连接的状态,实时监控网络状态。 所谓客户端请求,是指由客户端的套接字提出连接请求,要连接的目标是服务器端的套接字。为此,客户端的套接字必须首先描述它要连接的服务器的套接字,指出服务器端套接字的地址和端口号,然后就向服务器端套接字提出连接请求。 所谓连接确认,是指当服务器端套接字监听到或者说接收到客户端套接字的连接请求,它就响应客户端套接字的请求,建立一个新的线程,把服务器端套接字的描述发给客户端,一旦客户端确认了此描述,连接就建立好了
2、。而服务器端套接字继续处于监听状态,继续接收其他客户端套接字的连接请求。Networkprogramminginwindowsispossiblewithsockets.Asocketislikeahandletoafile.SocketprogrammingresemblesthefileIOasdoestheSerialCommunication.Youcanusesocketsprogrammingtohavetwoapplicationscommunicatewitheachother.Theappl
3、icationaretypicallyonthedifferentcomputersbuttheycanbeonsamecomputer.Forthetwoapplicationstotalktoeacheitheronthesameordifferentcomputersusingsocketsoneapplicationisgenerallyaserverthatkeepslisteningtotheincomingrequestsandtheotherapplicationactsasaclientan
4、dmakestheconnectiontotheserverapplication.Theserverapplicationcaneitheracceptorrejecttheconnection.Ifthe serveracceptstheconnection,adialogcanbeginwithbetweentheclientandtheserver. Oncetheclientisdonewithwhateveritneedstodoitcanclosetheconnectionwiththeserv
5、er.Connectionsareexpensiveinthesensethatserversallowfiniteconnectionstooccur. Duringthetimeclienthasanactiveconnectionitcansendthedatatotheserverand/orreceivethedata.Thecomplexitybeginshere.Wheneitherside(clientorserver)sendsdatatheothersideissupposedtoread
6、thedata.Buthowwilltheothersideknowwhendatahasarrived.Therearetwooptions-eithertheapplicationneedstopollforthedataatregularintervalsorthereneedstobesomesortofmechanismthatwouldenableapplicationtogetnotificationsandapplicationcanreadthedataatthattime.Well,aft
7、erallWindowsisaneventdrivensystemandthenotificationsystemseemsanobviousandbestchoiceanditinfactis. AsIsaidthetwoapplicationsthatneedtocommunicatewitheachother needtomakeaconnectionfirst.Inorderforthetwoapplicationtomakeconnectionsthetwoapplicationsneedtoi
8、dentifyeachother(oreachother'scomputer).Computersonnetworkhaveauniqueidentifiercalled I.P.addresswhichisrepresentedindot-notationlike10.20.120.127etc.Letsseehowallthisworksin.NET.System.Net.SocketsName
此文档下载收益归作者所有