swoole 示例

我的未来我决定 提交于 2020-03-27 14:54:20

 

$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();
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!