Several WSA * of WinSocket *. Several WSA * typedefstructWSAData {WORDwVersion; WORDwHighVersion; # signature; unsignedshortiMaxUdpDg; charFAR * lpVendorInfo; several WSA * of char WinSocket *
- Typedef struct WSAData {
- WORD wVersion;
- WORD wHighVersion;
- # Ifdef _ WIN64
- Unsigned short iMaxSockets;
- Unsigned short iMaxUdpDg;
- Char FAR * lpVendorInfo;
- Char szDescription [WSADESCRIPTION_LEN + 1];
- Char szSystemStatus [WSASYS_STATUS_LEN + 1];
- # Else
- Char szDescription [WSADESCRIPTION_LEN + 1];
- Char szSystemStatus [WSASYS_STATUS_LEN + 1];
- Unsigned short iMaxSockets;
- Unsigned short iMaxUdpDg;
- Char FAR * lpVendorInfo;
- # Endif
- } WSADATA;
The WSADATA structure is used to store the Windows Sockets initialization information returned by calling the AfxSocketInit global function.
1. WSAStartup
Usage:
WSADATA wsaD;
WSAStartup (MAKEWORD (2, 2), & wsaD );
When an application calls the WSAStartup function, the operating system searches for the corresponding Socket library based on the requested Socket version, and then binds the Socket library to the application. In the future, the application can call other Socket functions in the requested Socket Library.
In fact, if the windows socket program does not add this sentence, the call to the socket () function is unsuccessful and-1 is always returned.
2. WSACleanup
WSAStartup should be used in pairs with WSACleanup. the Function of WSAStartup is to initialize Winsock DLL, and WSACleanup is to unbind from the Socket library and release the system resources occupied by the Socket Library.
In Windows, Socket is implemented in the form of DLL. There is a counter in the DLL. only WSAStartup is called for the first time to load the DLL. the subsequent call is simply to add a counter, while the WSACleanup function is opposite, every call reduces the counter by 1. when the counter is reduced to 0, the DLL will be detached from the memory! Therefore, the number of WSAStartup calls should be the number of WSACleanup.
3. WSAGetLastError ()
This function returns the previous network error.
To be continued ......
Reference URL:
Http://blog.csdn.net/bolike/article/details/7584727
Optional typedef struct WSAData {WORD wVersion; WORD wHighVersion; # ifdef _ WIN64 unsigned short iMaxSockets; unsigned short iMaxUdpDg; char FAR * lpVendorInfo; char...