We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 2612553 commit 547f2bcCopy full SHA for 547f2bc
AsyTCPClient.php
@@ -0,0 +1,26 @@
1
+<?php
2
+// 创建异步TCP客户端
3
+$client = new swoole_client(SWOOLE_COCK_TCP, SWOOLE_SOCK_ASYNC);
4
+
5
+// 注册连接成功的回调
6
+$client->on('connect', function ($cli) {
7
+ $cli->send('hello \n');
8
+});
9
10
+// 注册数据接收 $cli 服务端信息 $data 数据
11
+$client->on('receive', function ($cli, $data) {
12
+ echo "data: $data";
13
14
15
+// 注册连接失败
16
+$client->on('error', function ($cli) {
17
+ echo '失败';
18
19
20
+// 注册关闭函数
21
+$client->on('close', function ($cli) {
22
+ echo '关闭\n';
23
24
25
+//发起连接
26
+$client->connect('192.168.1.31', 8080, 10);
0 commit comments