views:

55

answers:

1

Hello. Right now I'm working in a simple Server that receives from client a code referring to a certain operation. The server receives this data and send back the signal that it's waiting for the proper data.

                   /*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);
                        }
                    }

Following here is the client code responsible for sending the operation code and receiving the signal

                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");
            }

Why this is happening only in the second attempt to send some data? Because the first call to send() works fine. Hope someone can help!! Thnks

A: 

I sorted it out. The first receive buffer was to small for the incoming message and it got overflowed, erasing the SOCKET socketEscuta variable. Now it's working fine. Thanks for the tips!

Paulo Victor