Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to write byte by byte to socket in PHP?

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.

like image 210
PatlaDJ Avatar asked Mar 18 '10 20:03

PatlaDJ


1 Answers

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);
like image 109
Mark Tomlin Avatar answered Sep 19 '22 13:09

Mark Tomlin