Example #1
0
 public function ajax()
 {
     //判断Socket模块是否加载
     if (!extension_loaded('sockets')) {
         die('php sockets extension not loaded!');
     }
     //判断websocket服务器是否已运行, 没有运行则执行下面的代码创建, 防止重复创建websocket
     if (!add_lock('welive')) {
         die('WEBSOCKET server is running ...');
     }
     // socket接受或发送的最大数据限制(字节) 128K
     define('WEBSOCKET_MAX', 1024 * 128);
     // 最大连接数(设置大些, 可能有仅连接不传送信息的非法连接, 无法关闭)
     define('WEBSOCKET_ONLINE', 2048);
     // 屏蔽错误代码
     error_reporting(0);
     // 设置超时时间
     @set_time_limit(0);
     @ignore_user_abort(true);
     //忽略用户断开连接, 服务器脚本仍运行
     // 设置当前脚本可使用的最大内存, 默认为1024M, 同时连接人数太多时,可能不够
     @ini_set('memory_limit', '1024M');
     $websocket = new Websocket(WS_HOST, WS_PORT);
     $websocket->domain = '';
     //允许的域名
     $websocket->run();
     echo socket_strerror($websocket->error());
 }
 function __construct()
 {
     parent::__construct();
     $this->host = 'localhost';
     //хост
     $this->port = 4041;
     //порт
     $this->null = NULL;
     $this->mysqli = new mysqli('localhost', 'vseploshadki', '2YjLzaDKT7PNCDCU', 'adminchat');
     $this->loop = true;
     $this->user_keys = array();
     $this->init();
     $this->loop();
 }
 public function __construct()
 {
     parent::__construct();
     $this->redis_lib = new Redis_lib(__SWOOLE_REDISIP__);
 }
Example #4
0
            $serv->send($msg['from'], json_encode($resMsg));
        }
        //$serv->close( $fd );
    }
}
dl("appnet.so");
$server = new appnetServer("0.0.0.0", 3011);
$server->on('connect', function ($serv, $fd) {
    $pid = posix_getpid();
    echo "Client:Connect:{$fd} pid={$pid} \n";
});
$server->on('receive', function ($serv, $fd, $buffer) {
    echo "Client Recv:[{$buffer}][{$fd}] \n";
    $header = $serv->getHeader();
    if ($header['Protocol'] == "WEBSOCKET") {
        Websocket::onReceive($serv, $fd, $buffer);
    }
});
$server->on('close', function ($serv, $fd) {
    echo "Client Close:{$fd} \n";
});
//on worker run start,you can init env.
$server->on('start', function ($serv) {
    $pid = posix_getpid();
    echo "On Worker Start!! pid={$pid} \n";
    //3000ms means 3second
    $serv->timerAdd(3000, "onTimerCallback", "paramsxxx");
});
//on worker shutdown,you must save data in last time.
$server->on('final', function ($serv) {
    $pid = posix_getpid();
Example #5
0
 public function getWSData($for)
 {
     echo Websocket::getData($for);
 }
Example #6
-2
<?php

ini_set('mbstring.func_overload', "2");
ini_set('mbstring.internal_encoding', "UTF-8");
include_once "config.php";
include_once "Core/Logger.php";
include_once "Core/Websocket.php";
set_time_limit(0);
Logger::getInstance()->Init($arConfig['loglevel']);
Logger::getInstance()->outString("-----------------------------");
Logger::getInstance()->outString("|        Game server        |");
Logger::getInstance()->outString("|    devel f**k the shit    |");
Logger::getInstance()->outString("-----------------------------");
$websocket = new Websocket($arConfig['listen_host'], $arConfig['listen_port']);
$websocket->DoWork();