$str = $_GET['a'];
$client = new swoole_client(SWOOLE_SOCK_TCP);
if (!$client->connect("127.0.0.1", 9501, -1))
{
exit("connect failed. Error: {$client->errCode}
");
}
$client->send("hello world
" . $str);
echo $client->recv(); //打印 接收到的数据
$client->close();
$server = new swoole_server("127.0.0.1", 9501);
$server->on('connect', function ($server, $fd){
echo "connection open: {$fd}
";
});
$server->on('receive', function ($server, $fd, $reactor_id, $data) {
$server->send($fd, "Swoole: {$data}");
$server->close($fd);
});
$server->on('close', function ($server, $fd) {
echo "connection close: {$fd}
";
});
$server->start();