title: How to parse binary data from socket in python?
body: <p>I'm currently working on a project where I need to communicate to a microhard cellular modem IPn3G. I have the modem set up to send messages to my computer through TCP and I can pick up the message in a socket.</p>
  
  <p>The message looks like this though:</p>
  
  <pre><code>���������DKReadyCANRogersWirelessInc. Home354626030393530302720391029547
  </code></pre>
  
  <p>Now, I can recognize a few of these fields like the Status or the Carrierinfo as well as the imei and imsi in the end.</p>
  
  <p>My problem is, how do I parse the funny looking things? I have tried struct, but it didn't seem to help me out very much.</p>
  
  <p>In the documentation of the modem I only found this:</p>
  
  <p>Modem_event message structure:</p>
  
  <ul>
  <li>fixed header (fixed size 20 bytes)</li>
  <li>Modem ID (uint64_t (8 bytes))</li>
  <li>Message type mask (uint8_t(1 byte))</li>
  <li>reserved</li>
  <li>packet length (uint16_t(2 bytes))
  Note: packet length = length of fixed header + length of message payload.</li>
  </ul>
  
  <p>Carrier info:</p>
  
  <ul>
  <li>Content length 2 BYTES (UINT16_T)</li>
  <li>RSSI 1 BYTE (UINT8_T)</li>
  <li>RF Band 2 BYTES (UINT16_T)</li>
  <li>Service type STRING (1-30 Bytes)        </li>
  <li>Channel number STRING (1-30 Bytes)</li>
  <li>SIM card number STRING (1-30 Bytes)</li>
  <li>Phone number STRING (1-30 Bytes)</li>
  </ul>
  
  <p>To me it seems like the message doesn't even line up with what it's supposed to be. I would be very glad if anyone had advice on how to tackle this problem.</p>
  
  <p>Thank you</p>