基于UDP协议的WinSock编程.doc

  1. 1、本文档共8页,可阅读全部内容。
  2. 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
  3. 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  4. 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
基于UDP协议的WinSock编程

WinSocket 编程 (基于UDP) 对于在一个无连接套接字上接收数据的进程来说,步骤并不复杂。先用WSAStartup来加载Winscock DLL相应版本,然后用socket或WSASocket建立套接字。再把这个套接字和准备接收数据的接口绑定在一起。这是通过b i n d函数来完成的。和面向连接会话不同的是,我们不必调用l i s t e n和a c c e p t。 1、Winsock的初始化 每个Wi n s o c k应用都必须加载Winsock DLL的相应版本。如果调用Wi n s o c k之前,没有加载Wi n s o c k库,这个函数就会返回一个S O C K E T _ E R R O R,错误信息是W S A N O T I N I T I A L I S E D。加载Wi n s o c k库是通过调用W S A S t a r t u p函数实现的。这个函数的定义如下: int WSAStartup( WORD wVersionRequested, LPWSADATA lpWSAData ); wVersionRequested [in] Highest version of Windows Sockets support that the caller can use. The high-order byte specifies the minor version (revision) number; the low-order byte specifies the major version number. lpWSAData [out] Pointer to the WSADATA data structure that is to receive details of the Windows Sockets implementation. The WSAStartup function returns zero if successful. Otherwise, it returns one of the error codes listed in the following. An application cannot call WSAGetLastError to determine the error code as is normally done in Windows Sockets if WSAStartup fails. The Ws2_32.dll will not have been loaded in the case of a failure so the client data area where the last error information is stored could not be established. Error code Meaning WSASYSNOTREADY Indicates that the underlying network subsystem is not ready for network communication. WSAVERNOTSUPPORTED The version of Windows Sockets support requested is not provided by this particular Windows Sockets implementation. WSAEINPROGRESS A blocking Windows Sockets 1.1 operation is in progress. WSAEPROCLIM Limit on the number of tasks supported by the Windows Sockets implementation has been reached. WSAEFAULT The lpWSAData is not a valid pointer. 注释: The WSAStartup function must be the first Windows Sockets function called by an application or DLL. It al

文档评论(0)

xcs88858 + 关注
实名认证
内容提供者

该用户很懒,什么也没介绍

版权声明书
用户编号:8130065136000003

1亿VIP精品文档

相关文档