title: Simple C++ server-client application with winsock
body: <p>I'm trying to write a simple server-client application, which all it's supposed to do is this:
  Client connects to server, Server waits for a message, client takes input from user, and sends it over to the server. Server receives this message, and sends it back to the client, client prints the message and loops and starts over again.
  However, for some reason I have a rather weird problem: when I send my first message, server responds with it, when I send my second message, server responds again with the first message. When I send my third message, server responds with the second message and so forth.</p>
  
  <p>Here's my server code that handles the connection:</p>
  
  <pre><code>class themusers {
      char ReMessage[200],SeMessage[200];
  
  public:
      void * HandleConnections(SOCKET connector,int location) {
  
      std::string Converter;
  
          for (;;) {
  
          if (recv(connector,ReMessage,sizeof(ReMessage),NULL) == -1)
              std::cout &lt;&lt; "Disconnected." &lt;&lt; std::endl;
              discon.lock();
              sock_connection[location] = NULL;
              discon.unlock();
              break;
          }
  
  
          else {
                     //this is the code that handles the receive/send operation
              msgmut.lock();
              //std:: cout &lt;&lt; ReMessage &lt;&lt; std::endl;
              memcpy(SeMessage, ReMessage, sizeof(ReMessage));
              send(connector, SeMessage, sizeof(SeMessage), NULL);
              msgmut.unlock();        
          }
  
          }
  
  
          return NULL;
          }
  };
  </code></pre>
  
  <p>And this is my client code:</p>
  
  <pre><code>for (;;) {
      cin &gt;&gt; tell;
      send(sock, tell, sizeof(tell), NULL);
      recv(sock,Message,sizeof(Message),NULL);
      Converter = Message;
      cout &lt;&lt; "Server: " &lt;&lt; Converter &lt;&lt; endl;
  }
  </code></pre>