$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}\n");}$client->send("hello world\n" . $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}\n";});$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}\n";});$server->start();
来源:https://www.cnblogs.com/bandbandme/p/12581252.html