I successfully opened a server and client socket in non-blocking mode.
Why if I call the client send function twice and then the server receive function once, the server only receives the first client message, but says it has received a total number of bytes equal to message 1 and message 2?
Thanks.
Main
Code:
// Send Client
strcpy(Cbuffer, "Client says hello server!!!");
n = sendIPv6J(Csockfd, Cbuffer, &errnoIn);
printf("\nClient: SENT MSG : %s : of size %d - errno = %i\n", Cbuffer, n, errnoIn);
// Send Client
strcpy(Cbuffer, "Client says hello server2!!");
n = sendIPv6J(Csockfd, Cbuffer, &errnoIn);
printf("\nClient: SENT MSG : %s : of size %d - errno = %i\n", Cbuffer, n, errnoIn);
// Recv Server
strcpy(buffer, "default server recv msg");
n = recvIPv6J(newsockfd, buffer, 255, &errnoIn);
printf("\nServer: RECEIVED MSG : %s : of size %d - errno = %i\n", buffer, n, errnoIn);
Functions
Code:
// Send Data
int sendIPv6J(int sockfd, char buffer[], int *errnoOut) {
int n;
n = send(sockfd, buffer, strlen(buffer) + 1, 0);
if(n == -1) {
*errnoOut = errno;
return(-1);
} else {
*errnoOut = 0;
return(n);
}
}
// END
// Recv Data
int recvIPv6J(int sockfd, char buffer[], int maxBufferLength, int *errnoOut) {
int n;
n = recv(sockfd, buffer, maxBufferLength, 0);
if(n == -1) {
*errnoOut = errno;
return(-1);
} else {
*errnoOut = 0;
return(n);
}
}
// END