我对cpp相当陌生。我希望能够通过 sock_stream 接收数据。我想将接收到的数据从 SocketInfo->DataBuf.buf 传递到在程序开始时初始化的 char recvArray[1024] 缓冲区。我需要能够从我的 recvArray[] 中检查/解析和组合数值。我如何使这个副本工作?我尝试过的几件事得到编译器错误“从 char* 到 char 的无效转换”
//check sockets for for read or write notification
for(int i=0; Total>0 && i<TotalSockets; i++){
LPSOCKET_INFORMATION SocketInfo = SocketList[i];
//check if data incomming on each socket
if( FD_ISSET(SocketInfo->Socket, &Reader)){
Total--;
SocketInfo->DataBuf.buf = SocketInfo->Buffer;
SocketInfo->DataBuf.len = BUFFERSIZE;
Flags = 0;
//receive data
SocketInfo->RecvBytes = sizeof(SocketInfo->DataBuf);
check = WSARecv(SocketInfo->Socket, &(SocketInfo->DataBuf), 1, &(SocketInfo->RecvBytes), &Flags, NULL, NULL);
//error checking
if( check == SOCKET_ERROR){
if( WSAGetLastError() != WSAEWOULDBLOCK){
printf("base station client receive failed with error %d \n", WSAGetLastError());
FreeSocketInformation(i); //shuts down client socket if no data
}
continue;
}
else{
//receive bytes into array
//print received bytes on screen
printf("%s \n", SocketInfo->DataBuf.buf);
//otherwise deal with data
//need to copy to recvArray
//if no bytes received then connection is closed.
if( SocketInfo->RecvBytes == 0){
FreeSocketInformation(i); //shuts down client socket if no data
continue;
}
}
} //end of read data from socket
}