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;
         else if(bytesRead >0)
             cout << "<" << xbuffer << endl;
                      //cout << xbuffer;

                    cin.getline(buffer, sizeof(buffer));
                    buffer[strlen(buffer)] = '\0';
                    send(skt, buffer, sizeof(buffer)+1, 0);
                    cout << endl;
Who is Participating?
bsnh99Connect With a Mentor Commented:
You're sending sizeof(buffer), but buffer only contains strlen(buffer) of valid data. Change the call to send to:

send(skt, buffer, strlen(buffer)+1, 0);
yep, that's right, but it's ok if you do:
send(skt, buffer, strlen(buffer), 0); - send exactly the buffer size (without terminator '\0')
All Courses

From novice to tech pro — start learning today.