1
\$\begingroup\$

I am sending two messages from server.exe like this:

sprintf( buffer,"%d %s",1,data1);
SDLNet_TCP_Send(clientSocket, buffer, strlen(buffer)+1); // first message

sprintf( buffer,"%d %s",2,data2);
SDLNet_TCP_Send(clientSocket, buffer, strlen(buffer)+1); // second message

and I am reading messages from client.exe like this:

if(SDLNet_CheckSockets(socketSet, 0)>0)
{
    if(SDLNet_SocketReady(clientSocket)>0)
    {
        if(SDLNet_TCP_Recv(clientSocket, buffer, 5000)>0)
        {
           //there i take only first message
        }
    }
}

Why am I not receiving all sent messages in the client?

\$\endgroup\$

1 Answer 1

1
\$\begingroup\$

Your client code is executed only once. I think you want while loop at the inner most if-statement instead, so something like:

if (SDLNet_CheckSockets(socketSet, 0)>0)
{
    if (SDLNet_SocketReady(clientSocket)>0)
    {
        while (SDLNet_TCP_Recv(clientSocket, buffer, 5000)>0)
        {
        }
    }
}
\$\endgroup\$
4
  • \$\begingroup\$ no client.exe code already inside while but i am still taking only first message \$\endgroup\$
    – Emre Kaya
    Commented May 24, 2018 at 11:22
  • \$\begingroup\$ like this while{if(SDLNet_CheckSockets(socketSet, 0)>0) { if(SDLNet_SocketReady(clientSocket)>0) { if(SDLNet_TCP_Recv(clientSocket, buffer, 5000)>0) { //there i take only first message } } } } \$\endgroup\$
    – Emre Kaya
    Commented May 24, 2018 at 11:23
  • \$\begingroup\$ Well in that case I think you should show more of your code in the initial question. \$\endgroup\$
    – user35344
    Commented May 24, 2018 at 11:37
  • \$\begingroup\$ sorry but you was right :D i take all messsages with your way thank you too much bro really thank you. \$\endgroup\$
    – Emre Kaya
    Commented May 24, 2018 at 11:40

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .