How to write byte by byte to socket in PHP?
For example how can I do something like:
socket_write($socket,$msg.14.56.255.11.7.89.152,strlen($msg)+7);
The pseudo code concatenated digits are actually bytes in dec. Hope you understand me.
You can use the pack function to pack the data into any datatype you wish. Then send it with any of the socket functions.
$strLen = strlen($msg);
$packet = pack("a{$strLen}C7", $msg, 14, 56, 255, 11, 7, 89, 152);
$pckLen = strlen($packet);
socket_write($socket, $packet, $pckLen);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With