-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathte.php
44 lines (32 loc) · 1.08 KB
/
te.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2020/11/17 0017
* Time: 下午 8:47
*/
require_once "vendor/autoload.php";
//tcp connect/receive/close
//udp packet / close
//stream/text
//http request
//ws open/message/close
//mqtt connect/subscribe/unsubscribe/publish/close
ini_set("memory_limit","2048M");
$server = new \Te\Server("tcp://0.0.0.0:4567");
$server->on("connect",function (\Te\Server $server,\Te\TcpConnection $connection){
fprintf(STDOUT,"有客户端连接了\r\n");
});
//fread
$server->on("receive",function (\Te\Server $server,$msg,\Te\TcpConnection $connection){
fprintf(STDOUT,"recv from client<%d>:%s\r\n",(int)$connection->socketfd(),$msg);
$connection->send("i am server".time());
});
$server->on("receiveBufferFull",function (\Te\Server $server,\Te\TcpConnection $connection){
fprintf(STDOUT,"接收缓冲区已经满了\r\n");
//$connection->send("i am server");
});
$server->on("close",function (\Te\Server $server,$msg,\Te\TcpConnection $connection){
fprintf(STDOUT,"客户端断开连接了\r\n");
});
$server->Start();