Skip to content

Commit

Permalink
对接一个swoole
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexchent committed Jul 3, 2021
1 parent e63c1da commit ea6c4a2
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Services/client.php → Swoole/client.php
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<?php/** * Created by PhpStorm. * User: chentao * Date: 2020/1/12 * Time: 4:00 PM */$client = new swoole_client(SWOOLE_SOCK_TCP);//连接到服务器if (!$client->connect('127.0.0.1', 9501, 0.5)){ die("connect failed.");}//向服务器发送数据if (!$client->send("hello world")){ die("send failed.");}//从服务器接收数据$data = $client->recv();if (!$data){ die("recv failed.");}echo $data;//关闭连接$client->close();
<?php/** * Created by PhpStorm. * User: chentao * Date: 2020/1/12 * Time: 4:00 PM */$client = new swoole\Client(SWOOLE_SOCK_TCP);//连接到服务器if (!$client->connect('127.0.0.1', 9501, 0.5)){ die("connect failed.");}//向服务器发送数据if (!$client->send("hello world")){ die("send failed.");}//从服务器接收数据$data = $client->recv();if (!$data){ die("recv failed.");}echo $data;//关闭连接$client->close();
Expand Down
2 changes: 1 addition & 1 deletion Services/services.php → Swoole/services.php
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<?php/** * Created by PhpStorm. * User: chentao * Date: 2020/1/12 * Time: 3:11 PM *///创建Server对象,监听 127.0.0.1:9501端口$serv = new Swoole\Server("127.0.0.1", 9501);//监听连接进入事件$serv->on('Connect', function ($serv, $fd) { echo "Client: Connect.\n";});//监听数据接收事件$serv->on('Receive', function ($serv, $fd, $from_id, $data) { $serv->send($fd, "Server: ".$data);});//监听连接关闭事件$serv->on('Close', function ($serv, $fd) { echo "Client: Close.\n";});//启动服务器$serv->start();
<?php/** * Created by PhpStorm. * User: chentao * Date: 2020/1/12 * Time: 3:11 PM *///创建Server对象,监听 127.0.0.1:9501端口$serv = new Swoole\Server("127.0.0.1", 9501);//监听连接进入事件$serv->on('Connect', function ($serv, $fd) { echo "Client: Connect.\n";});//监听数据接收事件$serv->on('Receive', function ($serv, $fd, $from_id, $data) { $serv->send($fd, "Server: 已接收到你的请求:".$data);});//监听连接关闭事件$serv->on('Close', function ($serv, $fd) { echo "Client: Close.\n";});//启动服务器$serv->start();
Expand Down

0 comments on commit ea6c4a2

Please sign in to comment.