nt iRet, ret=-1,//select 返回值 iLeft, idx, iSTTBCS=0;//STTBCS=SendToTargetBuffCurrentSize char szSendToTargetBuff[BuffSize]=, szRecvFromClientBuff[BuffSize]=; fd_set fdread,fdwrite; printf("\n\n*****************Connection Active*******************\n\n"); while(1) { FD_ZERO(&fdread); FD_ZERO(&fdwrite); FD_SET(sock[0],&fdread); FD_SET(sock[1],&fdwrite); if((ret=select(0,&fdread,&fdwrite,NULL,NULL))==SOCKET_ERROR) { printf("\nselect() failed:%d",GetLastError()); break; } //printf("\nselect() return value ret=%d",ret); if(ret>0) { //sClinet可读,client有数据要发送过来 if(FD_ISSET(sock[0],&fdread)) { //接收sock[0]发送来的数据 iRet=recv(sock[0],szRecvFromClientBuff,BuffSize,0); if(iRet==SOCKET_ERROR) { printf("\nrecv() from sock[0] failed:%d",GetLastError()); break; } else if(iRet==0) break; printf("\nrecv %d bytes from sClinet.",iRet); //把从client接收到的数据存添加到发往target的缓冲区 memcpy(szSendToTargetBuff+iSTTBCS,szRecvFromClientBuff,iRet); //刷新发往target的数据缓冲区当前buff大小 iSTTBCS+=iRet; //清空接收client数据的缓冲区 memset(szRecvFromClientBuff,0,BuffSize); } //sTarget可写,把从client接收到的数据发送到target if(FD_ISSET(sock[1],&fdwrite)) { //转发数据到target的3389端口 iLeft=iSTTBCS; idx=0; while(iLeft>0) { iRet=send(sock[1],&szSendToTargetBuff[idx],iLeft,0); if(iRet==SOCKET_ERROR) { printf("\nsend() to target failed:%d",GetLastError()); break; } printf("\nsend %d bytes to target",iRet); iLeft-=上一页 [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] ... 下一页 >> |