現在、特定の操作を参照するコードをクライアントから受け取る単純なサーバーで作業しています。サーバーはこのデータを受信し、適切なデータを待っているというシグナルを送り返します。
/*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");
}
これは、データを送信する 2 回目の試行でのみ発生するのはなぜですか? send() の最初の呼び出しは正常に機能するためです。誰かが助けてくれることを願っています!! ありがとう