Reputation: 493
$data = socket_read($this->socket, 5);
$counter = strlen($data);
for($i = 0; $i < $counter; ++$i) {
$char = (int)$data[$i];
echo "\nByte $i: $char\n";
}
The client sends two bytes to the server, and even when I read 5, it still only receives 2. The issue is that the byte is reading as 0. It's not reading it properly. How can I read the actual byte/byte array.
Thanks in advance!
Upvotes: 3
Views: 2082
Reputation: 84159
If the client only sent two bytes, why do you want five? Try using socket_recv()
instead to get explicit return value of bytes read.
Upvotes: 2