azizs
asked on
Please Help Urgent Client send() recv() problem
Question is changed a bit
Following is the code from my server program. As far as sending and receiving data is concerned, it does 'almost' right job. It does receive data without any problem from server side. However, when i send data from client to server, it sends it but it sends like 12 blank lines as well to the server. Can anyone tell me whats wrong?//
memset(buffer, 0, sizeof(buffer));
memset(xbuffer, 0, sizeof(xbuffer));
unsigned long on = 1;
ioctlsocket(skt, FIONBIO, &on);
while (true)
{
int bytesRead;
bytesRead = recv(skt, xbuffer, sizeof(xbuffer), 0);
if (0 == bytesRead)
{
cout << "Socket closed on other side" << endl;
break;
}
else if(bytesRead >0)
{
cout << "<" << xbuffer << endl;
//cout << xbuffer;
}
if(_kbhit())
{
cin.getline(buffer, sizeof(buffer));
buffer[strlen(buffer)] = '\0';
send(skt, buffer, sizeof(buffer)+1, 0);
cout << endl;
}
Sleep(500);
}
Following is the code from my server program. As far as sending and receiving data is concerned, it does 'almost' right job. It does receive data without any problem from server side. However, when i send data from client to server, it sends it but it sends like 12 blank lines as well to the server. Can anyone tell me whats wrong?//
memset(buffer, 0, sizeof(buffer));
memset(xbuffer, 0, sizeof(xbuffer));
unsigned long on = 1;
ioctlsocket(skt, FIONBIO, &on);
while (true)
{
int bytesRead;
bytesRead = recv(skt, xbuffer, sizeof(xbuffer), 0);
if (0 == bytesRead)
{
cout << "Socket closed on other side" << endl;
break;
}
else if(bytesRead >0)
{
cout << "<" << xbuffer << endl;
//cout << xbuffer;
}
if(_kbhit())
{
cin.getline(buffer, sizeof(buffer));
buffer[strlen(buffer)] = '\0';
send(skt, buffer, sizeof(buffer)+1, 0);
cout << endl;
}
Sleep(500);
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
send(skt, buffer, strlen(buffer), 0); - send exactly the buffer size (without terminator '\0')