ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
### **示例:** ``` <?php class TcpServer{ public $serv = null; public function __construct(){ $this->serv = new swoole_server("0.0.0.0",9501); $this->serv->set([ 'worker_num'=> 4 ]); $this->serv->on('connect',[$this,'onConnect']); $this->serv->on('receive',[$this,'onReceive']); $this->serv->on('close',[$this,'onClose']); $this->serv->start(); } //监听连接进入事件 public function onConnect($serv,$fd){ echo "Client: Connect.\n"; } //监听数据接收事件 public function onReceive($serv, $fd, $from_id, $data) { $serv->send($fd, "Server: ".$data); } //监听连接关闭事件 public function onClose($serv, $fd) { echo "Client: Close.\n"; } } new TcpServer(); ``` ***** ### **测试:** ``` telnet 127.0.0.1 9501 hello Server: hello ```