title: Wrong reception of data with UDP socket (C++)
body: <p>Good morning,</p>
  <p>I need to establish a UDP connection in order to send some data from a client to a server. I implemented the connection starting form this <a href="http://linux.m2osw.com/c-implementation-udp-clientserver" rel="nofollow noreferrer">example </a> .</p>
  <p>Then I defined my client.cc class:</p>
  <pre><code>#include &lt;iostream&gt;
  #include &lt;string.h&gt;
  #include &lt;stdio.h&gt;
  #include &quot;udp_client_server.h&quot;
  #include &quot;prova.h&quot;
  
  using udp_client_server::udp_client;
  
  #define LDM_IP &quot;127.0.0.1&quot;
  #define LDM_PORT 5445       //8000
  
  using namespace std;
  
  int main() {
      cout &lt;&lt; &quot;!!!I'm a client!!!&quot; &lt;&lt; endl; 
  
      prova *ciao = new prova() ;
      ciao-&gt;a = 86;
      ciao-&gt;b = 8.1;
      ciao-&gt;c = 90;
  
      udp_client_server::udp_client *client = new udp_client(LDM_IP, LDM_PORT);
  
      int b = client-&gt;send((char *)ciao,strlen((char *)ciao));
  
      if (b != strlen((char *)ciao)){
          std::cout&lt;&lt;&quot;Packet corrupted &quot;&lt;&lt; std::endl;
      }
  
      return 0;
  }
  </code></pre>
  <p>Then the sender.cc class :</p>
  <pre><code>#include &lt;iostream&gt;
  #include &lt;string.h&gt;
  
  #include &quot;udp_client_server.h&quot;
  #include &quot;prova.h&quot;
  
  using udp_client_server::udp_server;
  
  #define LDM_IP &quot;127.0.0.1&quot;
  #define LDM_PORT 5445       //8000
  
  using namespace std;
  
  int main() {
      cout &lt;&lt; &quot;!!!I'm a server!!!&quot; &lt;&lt; endl;
  
      int size_max = 256; 
  
      udp_client_server::udp_server *server = new udp_server(LDM_IP, LDM_PORT);
  
      char *buffer;
      int gotMsg = server-&gt;recv(buffer,size_max);
      prova *pippo = new prova();
      pippo = (prova *)(buffer);
  
      std::cout&lt;&lt; &quot;result &quot; &lt;&lt; gotMsg &lt;&lt;std::endl;
      std::cout&lt;&lt; &quot;value &quot; &lt;&lt; pippo &lt;&lt;std::endl;
  
      return 0;
  }
  </code></pre>
  <p>The connection is establish, but I don't get the what I send. At each run I get a different wrong value instead of the transmitted one.</p>
  <p>Could any one tell me where is the error?
  Thanks in advance</p>