yangyanzhao
yangyanzhao
采纳率18.8%
2017-03-21 06:12

SOCKET SEND后等待服务器返回RECV卡死

我程序里有一个一直运行着的RECV,还有一个SEND后的RECV,一直运行着的RECV能接受到数据
SEND后等待服务器返回就会卡死
NetSocket netSocket = (NetSocket *)lparam;
//SOCKET socketTCP = (SOCKET)lparam;
int loop = 0;
char bufRecv[MAX_PACKET];
char tempBuf[4096];
unsigned char
backData = new unsigned char[3036];
while (1){

int flag = recv(netSocket->pThis->socketTCP, bufRecv, strlen(bufRecv)+1, 0);
//int flag = recv(socketTCP, bufRecv, strlen(bufRecv) + 1, 0);
if (flag > 0){
int temp12 = strlen(bufRecv);
for (int i = 0; i tempBuf[i] = bufRecv[i];
}
while (temp12>MAX_PACKET){
loop++;
flag = recv(netSocket->pThis->socketTCP, bufRecv, MAX_PACKET, 0);
//flag = recv(socketTCP, bufRecv, MAX_PACKET, 0);
//temp12 = strlen(bufRecv) - MAX_PACKET*loop;
temp12 = strlen(bufRecv);
for (int i = 0; i < flag; i++){
tempBuf[i + MAX_PACKET*loop] = bufRecv[i];
}
}

        //backData = (unsigned char*)tempBuf;
        string backStr = "recv data from server ";
        backStr += tempBuf;
        //backData = new unsigned char[3036];
        int i = 0;
        for (i = 0; i < backStr.length(); i++){
            backData[i] = backStr[i];
        }
        backData[i] = '\0';
        //netSocket->pThis->index = netSocket->pThis->findIndexNum(backData);
    }
}
return 0;
这个可以接受到服务器的回应
result = send(socketTCP, (const char*)(char*)(sByte+offset), size, 0);
if (result < 0){
    DWORD a = GetLastError();
    ResumeThread(recvThread);
    ReleaseMutex(hMutex);
    return result;
}
Sleep(100);
//等待服务器响应 
int loop = 0;
char bufRecv[MAX_PACKET];
char tempBuf[4096];

int flag = recv(socketTCP, bufRecv, sizeof(bufRecv), 0);
if (flag < 0){
    DWORD a = GetLastError();
    ResumeThread(recvThread);
    ReleaseMutex(hMutex);
    return flag;
}
这个就卡死了
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

相关推荐