Several WSA*_PHP tutorials on WinSocket

WBOY
Release: 2016-07-12 09:05:57
Original
1135 people have browsed it

Several WSA* for WinSocket

  1. typedef struct WSAData {
  2. WORD wVersion;
  3. WORD wHighVersion;
  4. #ifdef _WIN64
  5. unsigned short iMaxSockets;
  6. unsigned short iMaxUdpDg;
  7. char FAR * lpVendorInfo;
  8. char szDescription[WSADESCRIPTION_LEN 1];
  9. char szSystemStatus[WSASYS_STATUS_LEN 1];
  10. #else
  11. char szDescription[WSADESCRIPTION_LEN 1];
  12. char szSystemStatus[WSASYS_STATUS_LEN 1];
  13. unsigned short iMaxSockets;
  14. unsigned short iMaxUdpDg;
  15. char FAR * lpVendorInfo;
  16. #endif
  17. } WSADATA;

The WSADATA structure is used to store 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 found Socket library to the application. The application can then call other Socket functions in the requested Socket library.

In fact, if the windows socket program does not add this sentence, calling the socket() function will be unsuccessful and will always return -1.


2. WSACleanup

WSAStartup should be used in pairs with WSACleanup. The function of WSAStartup is to initialize Winsock DLL, and WSACleanup is to unbind the Socket library. And release the system resources occupied by the Socket library.

Under Windows, Socket is implemented in the form of DLL. A counter is maintained inside the DLL. Only the first call to WSAStartup is the DLL actually loaded. Subsequent calls simply increment the counter. The function of the WSACleanup function is exactly the opposite. Each call makes the counter decremented by 1. When the counter decreases to 0 When, the DLL is unloaded from memory! Therefore, how many times you call WSAStartup, you should call WSACleanup accordingly.


3. WSAGetLastError()

means that the function returns The last network error that occurred.

To be continued...



Reference URL:

http:// /blog.csdn.net/bolike/article/details/7584727

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1067478.htmlTechArticleWinSocket several WSA* typedef struct WSAData { WORD wVersion; WORD wHighVersion; #ifdef _WIN64 unsigned short iMaxSockets; unsigned short iMaxUdpDg; char FAR * lpVendorInfo; char...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template