现在我正在一个简单的服务器上工作,它从客户端接收一个引用某个操作的代码。服务器接收此数据并发送回它正在等待正确数据的信号。
/*Server Side*/
if (codigoOperacao == 0)
{
printf("A escolha foi 0\n");
int bytesSent = SOCKET_ERROR;
char sendBuff[1080] = "0";
/*Here "send" returns an error msgm while trying to send back the signal*/
bytesSent = send(socketEscuta, sendBuff, 1080, 0);
if (bytesSent == SOCKET_ERROR)
{
printf("Erro ao enviar");
return 0;
}
else
{
printf("Bytes enviados : %d\n", bytesSent);
char structDesmontada[1080] = "";
bytesRecv = recebeMensagem(socketEscuta, structDesmontada);
printf("structDesmontada : %s", structDesmontada);
}
}
下面是负责发送操作码和接收信号的客户端代码
char sendMsg[1080] = "0";
char recvMsg[1080] = "";
bytesSent = send(socketCliente, sendMsg, sizeof(sendMsg), 0);
printf("Enviei o codigo (%d)\n", bytesSent);
/*Here the program blocks in a infinite loop since the server never send anything*/
while (bytesRecv == SOCKET_ERROR)
{
bytesRecv = recv(socketCliente, recvMsg, 1080, 0);
if (bytesRecv > 0)
{
printf("Recebeu\n");
}
为什么这只发生在第二次尝试发送一些数据时?因为第一次调用 send() 工作正常。希望有人能帮忙!!谢谢