I have a simple server that streams binary data (0 and 1) via tcp on a port.
I want to use php and read that binary data (bits), store it in a string and display it in the browser and later decode it my way.
I don't want to read whole TCP packet with the head, just the data in the packet.
Here is the code I managed to produce in this time, when running it in browser, it succesfully connects to server and the server sends data. The data is received, but displayed in some strange russian letters.
<?php
// host and port to connect to
$host = "127.0.0.1";
$port = 1991;
// connect to the port
$fp = fsockopen($host, $port, $errno, $errstr);
// don't die
set_time_limit(0);
// if connection not successfull, display error
if (!$fp)
{
die("Error: Could not open socket for connection!");
}
else
{
// connection successfull, listen for data (1024 bytes by default)
$got = fgets($fp);
// display the data
echo $got;
}
fclose($fp);
?>
<br><br><br><br>
Server closed;
I want to display the received bits in a string. For further decoding I need bytes made out of 8 bits. But I have no idea how to accomplish this.
Thank you for your help.