title: read single byte as an unsigned byte
body: <p>I have some a java server that I'm trying to get to play with a php script.</p>
  
  <p>The format provides the number of bytes the message will take as an unsigned byte, and then the bytes that comprise the string.</p>
  
  <p>here's my function with commentary</p>
  
  <pre><code>function read($socket, $readnum) {
      $endl = "&lt;br&gt;"; // It's running on apache
  
      // attempt to get the byte for the size
      $len = unpack("C",socket_read($socket, 1))[0];
      // this prints "after ", but $len does not print. $endl does
      echo "after " . $len . $endl;
      // obviously this fails because $len isn't in a valid state
      $msg = socket_read($socket, $len);
      // print the message for debugging?
      echo $len . " " . $msg;
      return $msg;
  }
  </code></pre>
  
  <p>I'm not really a php guy, more of a Java guy, so I'm not sure how I should go about getting this length.</p>
  
  <p>On @c0le2's request, I made the following edit</p>
  
  <pre><code>$lenarr = unpack("C",socket_read($socket, 1));
  $len = $lenarr[0]; // line 81
  </code></pre>
  
  <p>Which gave the following error</p>
  
  <pre><code>PHP Notice:  Undefined offset: 0 in simple_connect.php on line 81
  </code></pre>