Several wsa*_php tutorials for WinSocket

Source: Internet
Author: User

Several wsa* of 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 that is 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 appropriate socket library based on the requested socket version, and then binds the found socket library into the application. The application can then invoke the 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 returns 1.


2, WSACleanup

WSAStartup should be used in pairs with wsacleanup, the function of WSAStartup is to initialize Winsock Dll,wsacleanup to unbind the socket library and release the system resources occupied by the socket library.

Under Windows, the socket is implemented as a DLL. Inside the DLL maintains a counter, only the first call to WSAStartup to actually load the DLL, the subsequent call is simply to increase the counter, and the function of the WSACleanup function is just the opposite, each call to make the counter minus 1, when the counter is reduced to 0 o'clock, DLL is unloaded from memory! So how many times you call WSAStartup, the WSACleanup should be called the corresponding number of times.


3, WSAGetLastError ()

Refers to the function that returns the last network error that occurred.

Cond......



Reference URL:

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

http://www.bkjia.com/PHPjc/1067478.html www.bkjia.com true http://www.bkjia.com/PHPjc/1067478.html techarticle WinSocket a few wsa* typedef struct WSADATA {WORD wversion; WORD whighversion; #ifdef _win64 unsigned short imaxsockets; unsigned short IMAXUDPDG; char FAR * LPVENDORINFO; Char ...

  • 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.