title: Php socket programming - ACK Server with 4 byte integer format
body: <p>I am working on a GPS tracker project and created the socket server using this class</p>
  
  <p><a href="https://stackoverflow.com/questions/13054291/how-to-listen-to-a-tcp-port-using-php">How to listen to a TCP port using PHP?</a></p>
  
  <p>Its working fine till the 2nd step ACK of the number of the data received from the device. </p>
  
  <p>This is what is exactly required by the integration document.</p>
  
  <blockquote>
    <p>Then module starts to send first AVL data packet. After server
    receives packet and parses it, server must report to module number of
    data received as integer (four bytes).</p>
    
    <p>If sent data number and reported by server doesn’t match module
    resends sent data.</p>
    
    <p>Server acknowledges data reception (3 data elements):    00000003 (3)
    Server ACK to AVL Data Packet</p>
  </blockquote>
  
  <p>I am able to fully parse the data but unable to understand the way to send the integer in a 4 byte format but probably not getting sent the correct way. </p>
  
  <p>I have tried <a href="http://in1.php.net/pack" rel="nofollow noreferrer">php pack()</a>  with these formats i*, l*, L*</p>
  
  <pre><code>$output =pack('l*', $reply);
  SocketServer::socket_write_smart($client-&gt;socket,$output); // Send the Client back the String
  SocketServer::socket_write_smart($client-&gt;socket,"String? ",""); // Request Another String
  </code></pre>
  
  <p>$reply holds the number of the data sent as packet. I have tried to send 3 as integer or left padded 3 so that it becomes 0000003 (4 characters - 4 bytes) </p>
  
  <p>But none of the formats was successful as the device is not sending me the next set of data. 
  Its mandatory that i send the number of data received as ACK to send back to get the next set if data from the device.</p>
  
  <p>Can someone help me with the correct way so that i send the integer in the way so that its sent as 4 byte format.</p>