You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

42 lines
855 B

<?PHP
/**
* struct
* {
* unisgned char type;
* uint32_t time;
* uint32_t serid;
* uint32_t length;
* char body[0];
* }
*/
function remoteCall(string $host, $port, string $data) {
$length = strlen($data);
$pack = pack('CNNNa*', 1, time(), 0, $length, $data);
$client = new Swoole\Client(SWOOLE_SOCK_TCP);
$client->set(array(
'open_length_check' => true,
'package_max_length' => 81920,
'package_length_type' => 'N',
'package_length_offset' => 9,
'package_body_offset' => 13
));
if (!$client->connect($host, $port, 0.5)) {
return false;
}
$client->send($pack);
$pack = $client->recv();
$ret = unpack('Ctype/Ntime/Nserid/Nlength/a*data', $pack);
return $ret['data'];
}
$ret = remoteCall("127.0.0.1", "5188", "sasa");
echo $ret;
?>