2 a1214490813 a1214490813 于 2016.02.08 22:42 提问

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

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

 //***********************************************
    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);

2个回答

a1214490813
a1214490813   2016.02.08 22:42

//***********************************************
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);
devmiao
devmiao   Ds   Rxr 2016.02.09 06:53
Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!