At server.cpp I have two int fields to send to client.cpp. I am sending in this way:
if ((bytecount = send(*csock, portstring1, strlen(portstring1), 0)) == -1) {
fprintf(stderr, "Error sending data %d\n", errno);
goto FINISH;
}
sprintf(portstring2, "%d", ncount);
if ((bytecount = send(*csock, portstring2, strlen(portstring2), 0)) == -1) {
fprintf(stderr, "Error sending data %d\n", errno);
goto FINISH;
}
and at receiver side I use:
if((bytecount = recv(hsock, buffer, buffer_len, 0))== -1){
fprintf(stderr, "Error receiving data %d\n", errno);
goto FINISH;
}
printf("Positive counts are :");
printf(" %s \n",buffer);
if((bytecount = recv(hsock, buffer2, buffer_len, 0))== -1){
fprintf(stderr, "Error receiving data %d\n", errno);
goto FINISH;
}
printf("Negative count is :");
printf(" %s \n",buffer2);
But problem is that first rec() function catch both values sent from server and does not reach to second receive function. When I print data received from first rec function it show both values sent from server.
I tried using array to send both values togather but then converting int array to chat * became headache for me. Because send and rec function deal with char * values only. Not even string.
Any idea, how can I get both values at seperate level at client side?
buffer_len. But then, don't ignorebytecount. All you're guaranteed is that you got at least 1 byte. So you also need to add a loop to track how many bytes you have received and keep asking for more until you get the number you wanted. - Damien_The_Unbelieverprintf()with %s unless you set buffer to zero somewhere before eachrecv(). You are not sending a null character after the "integer" strings, sincestrlen()excludes it. - thuovilasendcalls at one end, and the number ofrecvcalls needed at the other end. - Damien_The_Unbeliever