Home > Article > Backend Development > Several WSA*_PHP tutorials on WinSocket
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