Assume client send the message " Hello ", i get output such as
Sent mesg: hello
Bytes Sent to Client: 6
bytes_received = recv(clientSockD, data, MAX_DATA, 0);
if(bytes_received)
{
send(clientSockD, data, bytes_received, 0);
data[bytes_received] = '\0';
printf("Sent mesg: %s", data);
cout<<"Bytes Sent to Client: "<<bytes_received<<endl;
}
clients send that data as follows:
cout<<"you: ";
fgets(clientInput, MAX_DATA, stdin);
send(sockfd, clientInput, strlen(clientInput), 0);
Why?
bytes_received should be 5, not 6 ..... Any idea?
**************************************************************
Lets say we have:
cout<<"Enter a port: ";
cin>>portNum;
fgets(clientInput, MAX_DATA, stdin);
Does fgets() takes a "\0" from the previous input, as you know cin leaves \0 there? getline() does...