I have some a java server that I'm trying to get to play with a php script.
The format provides the number of bytes the message will take as an unsigned byte, and then the bytes that comprise the string.
here's my function with commentary
function read($socket, $readnum) {
$endl = "<br>"; // 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;
}
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.
On @c0le2's request, I made the following edit
$lenarr = unpack("C",socket_read($socket, 1));
$len = $lenarr[0]; // line 81
Which gave the following error
PHP Notice: Undefined offset: 0 in simple_connect.php on line 81