Can't create socket on Windows

后端 未结 3 1624
猫巷女王i
猫巷女王i 2021-02-15 12:53

I have quite an embarrassing problem. The following code simply will not create a socket on Windows; it fails and displays the error message. Could anyone briefly explain why th

3条回答
  •  忘掉有多难
    2021-02-15 13:20

    An Example:

    #include 
    #include 
    
    #pragma comment(lib,"ws2_32.lib")
    
    int _cdecl main(){
       WSADATA Data;
       int socket; // or you can use SOCKET socket
       WSAStartup(MAKEWORD(2, 2), &Data); // 2.2 version
       socket = socket(AF_INET, SOCK_DGRAM, 0);
       if(udep_socket<0){
            printf("Error Creating Socket");
       }else{
            printf("Successfully Created Socket");
       }
       system("pause");
       return 0;
    }
    

提交回复
热议问题