初始化代码

This commit is contained in:
2025-12-22 14:32:54 +08:00
parent e27ab90d9f
commit d02b31a8b9
1459 changed files with 240973 additions and 0 deletions

82
app/im/controller/Tcp.php Normal file
View File

@@ -0,0 +1,82 @@
<?php
// +----------------------------------------------------------------------
// | Longbing [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright Chengdu longbing Technology Co., Ltd.
// +----------------------------------------------------------------------
// | Website http://longbing.org/
// +----------------------------------------------------------------------
// | Sales manager: +86-13558882532 / +86-13330887474
// | Technical support: +86-15680635005
// | After-sale service: +86-17361005938
// +----------------------------------------------------------------------
use Swoole\WebSocket\Server;
use think\facade\Cache;
class Tcp {
public $server;
public $redis;
public $key;
public function __construct() {
if(empty($this->redis)){
$this->redis = new Redis();
$this->redis ->connect('127.0.0.1',6379);
}
//创建Server对象监听 127.0.0.1:9501 端口
$server = new \Swoole\Server('127.0.0.1', 9501);
// $this->server->set(array(
//
// 'reactor_num' => 2, //reactor thread num
//
// 'worker_num' => 4, //worker process num
//
// 'backlog' => 128, //listen backlog
//
// 'max_request' => 50,
//
// 'dispatch_mode' => 1,
//
//// 'daemonize' => 1
//
// ));
//监听连接进入事件
$server->on('Connect', function ($server, $fd) {
echo "Client: Connect.\n";
});
//监听数据接收事件
$server->on('Receive', function ($server, $fd, $reactor_id, $data) {
$server->send($fd, "Server: {$data}");
});
//监听连接关闭事件
$server->on('Close', function ($server, $fd) {
echo "Client: Close.\n";
});
//启动服务器
$server->start();
}
}
new Tcp();