WinSocket WSA * _ PHP Tutorial

Source: Internet
Author: User
Several WSA * of WinSocket *. Several WSA * typedefstructWSAData {WORDwVersion; WORDwHighVersion; # signature; unsignedshortiMaxUdpDg; charFAR * lpVendorInfo; several WSA * of char 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 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...

Large-Scale Price Reduction
  • 59% Max. and 23% Avg.
  • Price Reduction for Core Products
  • Price Reduction in Multiple Regions
undefined. /
Connect with us on Discord
  • Secure, anonymous group chat without disturbance
  • Stay updated on campaigns, new products, and more
  • Support for all your questions
undefined. /
Free Tier
  • Start free from ECS to Big Data
  • Get Started in 3 Simple Steps
  • Try ECS t5 1C1G
undefined. /

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.