基于UDP协议的WinSock编程

基于UDP协议的WinSock编程

ID:38711469

大小:57.50 KB

页数:7页

时间:2019-06-18

基于UDP协议的WinSock编程_第1页
基于UDP协议的WinSock编程_第2页
基于UDP协议的WinSock编程_第3页
基于UDP协议的WinSock编程_第4页
基于UDP协议的WinSock编程_第5页
资源描述:

《基于UDP协议的WinSock编程》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库

1、WinSocket编程(基于UDP)对于在一个无连接套接字上接收数据的进程来说,步骤并不复杂。先用WSAStartup来加载WinscockDLL相应版本,然后用socket或WSASocket建立套接字。再把这个套接字和准备接收数据的接口绑定在一起。这是通过bind函数来完成的。和面向连接会话不同的是,我们不必调用listen和accept。1、Winsock的初始化每个Winsock应用都必须加载WinsockDLL的相应版本。如果调用Winsock之前,没有加载Winsock库,这个函数就会返回一个SOCKET_ERROR,错误信息是WSANOTINITIALISED。加载Winsoc

2、k库是通过调用WSAStartup函数实现的。这个函数的定义如下:intWSAStartup(WORDwVersionRequested,LPWSADATAlpWSAData);wVersionRequested[in]HighestversionofWindowsSocketssupportthatthecallercanuse.Thehigh-orderbytespecifiestheminorversion(revision)number;thelow-orderbytespecifiesthemajorversionnumber.lpWSAData[out]PointertotheW

3、SADATAdatastructurethatistoreceivedetailsoftheWindowsSocketsimplementation.TheWSAStartupfunctionreturnszeroifsuccessful.Otherwise,itreturnsoneoftheerrorcodeslistedinthefollowing.AnapplicationcannotcallWSAGetLastErrortodeterminetheerrorcodeasisnormallydoneinWindowsSocketsifWSAStartupfails.TheWs2_32.

4、dllwillnothavebeenloadedinthecaseofafailuresotheclientdataareawherethelasterrorinformationisstoredcouldnotbeestablished.ErrorcodeMeaningWSASYSNOTREADYIndicatesthattheunderlyingnetworksubsystemisnotreadyfornetworkcommunication.WSAVERNOTSUPPORTEDTheversionofWindowsSocketssupportrequestedisnotprovided

5、bythisparticularWindowsSocketsimplementation.WSAEINPROGRESSAblockingWindowsSockets1.1operationisinprogress.WSAEPROCLIMLimitonthenumberoftaskssupportedbytheWindowsSocketsimplementationhasbeenreached.WSAEFAULTThelpWSADataisnotavalidpointer.注释:TheWSAStartupfunctionmustbethefirstWindowsSocketsfunctionc

6、alledbyanapplicationorDLL.ItallowsanapplicationorDLLtospecifytheversionofWindowsSocketsrequiredandretrievedetailsofthespecificWindowsSocketsimplementation.TheapplicationorDLLcanonlyissuefurtherWindowsSocketsfunctionsaftersuccessfullycallingWSAStartup.(在使用WindowsSockets之前必须调用WSAStartup加载Winsocket库成功

7、)  OnceanapplicationorDLLhasmadeasuccessfulWSAStartupcall,itcanproceedtomakeotherWindowsSocketscallsasneeded.WhenithasfinishedusingtheservicesoftheWs2_32.dll,theapplicationorDLLmustcallWSACleanuptoallowtheW

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。