开发者社区> 问答> 正文

C++的TCP的socket编程遇到了“未经处理的异常错误”

TCP的socket编程,我把它拆为了两部分,后半部分用线程处理,但是前半部分遇到了错误大神们帮我检查一下吧,谢谢!
screenshot
screenshot

//***********************************************
    WORD wVersionRequested;
    WSADATA wsaData;
    int err;

    wVersionRequested = MAKEWORD(1, 1);

    err = WSAStartup(wVersionRequested, &wsaData);
    if (err != 0) {
        return 0;
    }

    if (LOBYTE(wsaData.wVersion) != 1 ||
        HIBYTE(wsaData.wVersion) != 1) {
        WSACleanup();
        return 0;
    }
    SOCKET sockSrv = socket(AF_INET, SOCK_STREAM, 0);

    SOCKADDR_IN addrSrv;
    addrSrv.sin_addr.S_un.S_addr = htonl(INADDR_ANY);
    addrSrv.sin_family = AF_INET;
    addrSrv.sin_port = htons(8088);

    bind(sockSrv, (SOCKADDR*)&addrSrv, sizeof(SOCKADDR));

    listen(sockSrv, 5);

    thread t(comsock, sockSrv);

展开
收起
a123456678 2016-03-09 10:29:06 2961 0
1 条回答
写回答
取消 提交回答
  • //***********************************************
    WORD wVersionRequested;
    WSADATA wsaData;
    int err;
    
    wVersionRequested = MAKEWORD(1, 1);
    
    err = WSAStartup(wVersionRequested, &wsaData);
    
    SOCKET sockSrv = socket(AF_INET, SOCK_STREAM, 0);
    
    SOCKADDR_IN addrSrv;
    addrSrv.sin_addr.S_un.S_addr = htonl(INADDR_ANY);
    addrSrv.sin_family = AF_INET;
    addrSrv.sin_port = htons(8088);
    
    bind(sockSrv, (SOCKADDR*)&addrSrv, sizeof(SOCKADDR));
    
    listen(sockSrv, 5);
    
    thread t(comsock, sockSrv);
    2019-07-17 18:55:31
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
使用C++11开发PHP7扩展 立即下载
GPON Class C++ SFP O;T Transce 立即下载
GPON Class C++ SFP OLT Transce 立即下载