title: send/receive a struct with TCP/IP socket on windows 7 64bit
body: <p>searching here for my problem, I've found more discussion about this, but seems that solution it's not simple for send a struct with a socket. </p>
  
  <p>I don't understand how can send struct with socket in safe mode.</p>
  
  <p>I need to use struct to send my information, and receive it correctly, without loosing any data.</p>
  
  <p>So, the situation is this: the client have to send to server this struct:</p>
  
  <pre><code>typedef array&lt;array&lt;double,4&gt;,4&gt; Matrix4x4;
  
  struct data
  {
         bool shot;
         Matrix4x4 position;
  };
  </code></pre>
  
  <p>where the Matrix4x4 are like this:</p>
  
  <pre><code>Matrix4x4 T1 = {{
          {{-1.0000,   0.0000,  -0.0000,   0.1531}},
          {{0.0000,   0.0000,  -1.0000,   0.1502 }},
          {{-0.0000,  -1.0000,  -0.0000,   1.0790}},
          {{0 ,       0,        0,   1.0000    }} }}; 
  </code></pre>
  
  <p>Every packet of data to send, have the matrix changed and the bool true or false; I need to receive it and can access to bool and matrix.</p>
  
  <p>I'm using PraticalSocket class </p>
  
  <p><a href="http://cs.baylor.edu/~donahoo/practical/CSockets/practical/" rel="nofollow">http://cs.baylor.edu/~donahoo/practical/CSockets/practical/</a> </p>
  
  <p>for send/receive on Windows 7 64bit, with visual C++ 2010 on a 64 bit project.</p>
  
  <p>For sending struct, I'm doing this:</p>
  
  <pre><code>#include "PracticalSocket.h"
  #include &lt;iostream&gt;
  #include &lt;array&gt;
  #include &lt;vector&gt;
  #include &lt;Windows.h&gt;
  #include &lt;cstdlib&gt;
  
  
  using namespace std;
  
  #define servAddress "192.168.0.117"
  const unsigned short SOCKET_SERVER_PORT = 27500;
  
  typedef array&lt;array&lt;double,4&gt;,4&gt; Matrix4x4;
  
  Matrix4x4 T1 = {{
      {{-1.0000,   0.0000,  -0.0000,   0.1531}},
      {{0.0000,   0.0000,  -1.0000,   0.1502 }},
      {{-0.0000,  -1.0000,  -0.0000,   1.0790}},
      {{0 ,       0,        0,   1.0000    }} }}; //example for testing send
  
  //packet to send
  struct data{
      bool shot;
      Matrix4x4 position;
  };
  
  struct data primo = {true, T1};
  
  //socket TCP
  
  
  
  int main()
  {
  try{
      TCPSocket sock(servAddress, SOCKET_SERVER_PORT);   
      sock.send(&amp;primo, sizeof(struct data));
  }catch(SocketException &amp;e){
      cerr &lt;&lt; e.what() &lt;&lt; endl;
      system("PAUSE");
  }
  
  cout&lt;&lt;endl&lt;&lt;"Matrix and bool sendend server"&lt;&lt;endl;
  return 0;
  }
  </code></pre>
  
  <p>The "Send" to server goes OK (from this client, no error) but the server has error on receive. I notice that the recv() function need a char buffer...so, that error it's due to this...</p>
  
  <p>Someone can give me an example of code, that help me to send and receive correctly this struct without loosing data from client to server? </p>
  
  <p>The two PC's are the same architecture (windows 7 64bit, intel processor, same RAM and hardware..)</p>
  
  <p>Thanks in advance...</p>