windows socket函数详解 您所在的位置:网站首页 inconnect函数 windows socket函数详解

windows socket函数详解

2024-07-11 23:23| 来源: 网络整理| 查看: 265

windows socket函数详解

  近期一直用第三方库写网络编程,反倒是遗忘了网络编程最底层的知识。因而产生了整理Winsock函数库的想法。以下知识点均来源于MSDN,本人只做翻译工作。虽然很多前辈都做已了此类工作,但亲力亲为总记得清楚点。

  0:函数库头文件 1 #include 2 #pragma comment(lib,"Ws2_32.lib ")   1:WSAStartup   初始化Ws2_32.dll的函数

description:The WSAStartup function initiates use of the Winsock DLL by a process.

  WSAStartup 函数用于初始化供进程调用的Winsock相关的dll。

1 int WSAStartup( 2 __in WORD wVersionRequested, 3 __out LPWSADATA lpWSAData 4 ); Parameters   wVersionRequested

The highest version of Windows Sockets specification that the caller can use. The high-order byte specifies the minor version number; the low-order byte specifies the major version number.

The current version of the Windows Sockets specification is version 2.2. The current Winsock DLL, Ws2_32.dll, supports applications that request any of the following versions of Windows Sockets specification,1.0、1.1、2.0、2.1、2.2。

标识了用户调用的Winsock的版本号。高字节指明辅版本编号,低字节指明主版本编号。通常使用MAKEWORD来生成一个版本号。 当前Winsock sockets的版本号为2.2,用到的dll是 Ws2_32.dll。

  lpWSAData

A pointer to the WSADATA data structure that is to receive details of the Windows Sockets implementation.

指向WSADATA结构体的指针,lpWSAData返回了系统对Windows Sockets 的描述。

Return Value

If successful, the WSAStartup function returns zero. Otherwise, it returns one of the error codes listed below.

WSAVERNOTSUPPORTED、WSAVERNOTSUPPORTED、WSAEINPROGRESS、WSAEPROCLIM、WSAEFAULT。

The WSAStartup function directly returns the extended error code in the return value for this function. A call to the WSAGetLastError function is not needed and should not be used. 

如果调用成功,WSAStartup 函数返回0。否则,将返回五种错误代码之一。但绝对不能使用WSAGetLastError获取错误代码。

1   WSAData wsa; 2 if (::WSAStartup(MAKEWORD(2,2),&wsa) != 0) 3 { 4 cout


【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有