Problem in using a second call to send() in C

Posted by Paulo Victor on Stack Overflow See other posts from Stack Overflow or by Paulo Victor
Published on 2010-06-01T01:24:34Z Indexed on 2010/06/01 1:33 UTC
Read the original article Hit count: 265

Filed under:
|
|
|
|

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

© Stack Overflow or respective owner

Related posts about c

    Related posts about Windows