public function onMessage(\Swoole\WebSocket\Server $server, \Swoole\WebSocket\Frame $frame)
    {
        // echo "[websocket][onmessage]receive from {$frame->fd}:{$frame->data},opcode:{$frame->opcode},fin:{$frame->finish}\n";
        // $server->push($frame->fd, "this is server");
        // print_r(self::$websocketFrameContext);

        if ( empty(self::$websocketFrameContext[$frame->fd]) ) {
            if ( getenv('STDOUT_LOG') ) {
                echo date('Y-m-d H:i:s') . " |\033[31m [ERROR][onMessage] WebSocket has been stoped before frame sending data\033[0m \n";
            }
            return;
        }

        // Save websocket connection Context
        $context = self::$websocketFrameContext[$frame->fd];

        // Restore global data
        $_POST   = $_SERVER = [];
        $_GET    = $_REQUEST = $context['get'];
        $_COOKIE = $context['cookie'];
        $controller_class = $context['controller_class'];

        call_user_func([new $controller_class(), 'onMessage'], $server, $frame);
    }
public function onMessage(\Swoole\WebSocket\Server $server, \Swoole\WebSocket\Frame $frame)
    {
        // echo "[websocket][onmessage]receive from {$frame->fd}:{$frame->data},opcode:{$frame->opcode},fin:{$frame->finish}\n";
        // $server->push($frame->fd, "this is server");
        // print_r(self::$websocketFrameContext);

        if ( empty(self::$websocketFrameContext[$frame->fd]) ) {
            if ( getenv('STDOUT_LOG') ) {
                echo date('Y-m-d H:i:s') . " |\033[31m [ERROR][onMessage] WebSocket has been stoped before frame sending data\033[0m \n";
            }
            return;
        }

        // Save websocket connection Context
        $context = self::$websocketFrameContext[$frame->fd];

        // Restore global data
        $_POST   = $_SERVER = [];
        $_GET    = $_REQUEST = $context['get'];
        $_COOKIE = $context['cookie'];
        $controller_class = $context['controller_class'];

        call_user_func([new $controller_class(), 'onMessage'], $server, $frame);
    }
public function onMessage ( \ Swoole \ WebSocket \ Server $ server , \ Swoole \ WebSocket \ Frame $ frame ) { // echo "[websocket][onmessage]receive from {$frame->fd}:{$frame->data},opcode:{$frame->opcode},fin:{$frame->finish}\n"; // $server->push($frame->fd, "this is server"); // print_r(self::$websocketFrameContext); if ( empty ( self :: $ websocketFrameContext [ $ frame -> fd ] ) ) { if ( getenv ( 'STDOUT_LOG' ) ) { echo date ( 'Y-m-d H:i:s' ) . " |\033[31m [ERROR][onMessage] WebSocket has been stoped before frame sending data\033[0m \n" ; } return ; } // Save websocket connection Context $ context = self :: $ websocketFrameContext [ $ frame -> fd ] ; // Restore global data $ _POST = $ _SERVER = [ ] ; $ _GET = $ _REQUEST = $ context [ 'get' ] ; $ _COOKIE = $ context [ 'cookie' ] ; $ controller_class = $ context [ 'controller_class' ] ; call_user_func ( [ new $ controller_class ( ) , 'onMessage' ] , $ server , $ frame ) ; }
WebSocket on message

@param Swoole\WebSocket\Server $server
@param [type] $frame
@return void
WebSocket on message