Precautions established under Win Socket

Under Windows socket established

  1. First of all windows to be introduced under the header file windows.h and WinSock2.h

    (Note: Since the early windows.h socket1 which contains several versions, when the code is under the execution of this command, it displays the error of the duplicate)

    #include<windows.h>
    #include<WinSock2.h>
    
    int main(){
        return 0;
    }

    To solve this problem, Microsoft proposed two solutions.

    • The header file references WinSock2.h placed before pretreatment windows.h
    • Added before pre-header file #define WIN32_LEAN_AND_MEAN
  2. WORD ver = MAKEWORD(2, 2);//版本号
    WSADATA dat;//一个数据指针
    WSAStartup(ver, &dat);//函数有2个参数,一个版本号,一个数据指针
    //           ↓
    //连接socket和其他系统基本一样
    //           ↑
    WSACleanup();

Guess you like

Origin www.cnblogs.com/ranbom/p/12363148.html