title: Read floats from tcp
body: <p>I'm trying to read big-endian 8 32-bit floats being passed from a packaged struct in a Python tcp streaming server. It seems to be close to working, but the first few values are off by an odd amount, and the later values seem off by a small amount, or just imprecise.</p>
  
  <p>For example, these are values interpreted by the client:</p>
  
  <pre><code>Val[0] -1926.34
  Val[1] -1936.86
  Val[2] -1901.15
  Val[3] -1935.93
  Val[4] -148932
  Val[5] -145905
  Val[6] -41580.8
  Val[7] -134330
  </code></pre>
  
  <p>And here are (close to but now quite) the values they're supposed to be. It's not quite the real ones because catching the exact same packet on the server and client is difficult.</p>
  
  <pre><code>Val[0] -7737.77159902711
  Val[1] -7746.444075875769
  Val[2] -7638.46279841218
  Val[3] -7776.037785534595
  Val[4] -148935.79768369172
  Val[5] -145903.3365134402
  Val[6] -41594.9200504923
  Val[7] -134328.9103304041
  </code></pre>
  
  <p>Here is my code:</p>
  
  <pre><code>int size = 32;
  char buffer[size];
  float vals[8];
  int count = 0;
  int t;
  
  // Receive a reply from the server
  if (recv(sock, buffer, size, 0) &lt; 0) {std::cout &lt;&lt; "Receive failed..." &lt;&lt; std::endl;}
  
  for (int i = 0; count &lt; 8; i += 4, count++) {
      t =
              (buffer[i+3])       +
              (buffer[i+2] &lt;&lt; 8)  +
              (buffer[i+1] &lt;&lt; 16) +
              (buffer[i]   &lt;&lt; 24);
  
      vals[count] = *reinterpret_cast&lt;float*&gt;(&amp;t);
  }
  </code></pre>
  
  <p>The Python server sending the packet:</p>
  
  <pre><code>packer = struct.Struct('&gt;%sf' % 8)
  packed_data = packer.pack(*values)
  sock.send(packed_data)
  </code></pre>
  
  <p>I have a feeling this could be an issue about conversion between the int and float but I can't seem to figure it out. Any help is greatly appreciated.</p>