I'm working on a piece of networking code I want to use in a multiplayer game. The idea is that the machine that will run the client will sent keyboard status to the server which will reply with the information about the graphical objects the client should draw on its screen. I've studied how sockets work, compiled and tested the examples I found on the internet and all worked fine. The only problem is that I can't run the client code in a loop ( I need to send the keyboard status regularly to the server ). Always when the send() function is run the second time it fails with the error code 10053 -connection closed in host.

this is the code I loop in the client:

Code:
while( ! kh.esc )
{
 
   kh.ReadKeys();
   memcpy( buff, &kh, Len );


   if ( ( size = send( mySocket, buff, Len, 0 )) == -1 )
   {
      printf( "Error: %d\n", WSAGetLastError() );
      WSACleanup();
      return -1;
   }

    while ( ((size = recv( mySocket, buf, BUFSIZE, 0 ) ) != 0 ) && ( size != -1 ) )
    {
         text += buf;
         cout << text;             
    }
    
    if (size == -1)
    {
        cout << "Error receiving data" << endl;
    }

    
    Sleep( 100 );
    
}

thanx for help