Skip to content
This repository has been archived by the owner on Sep 1, 2020. It is now read-only.

Latest commit

 

History

History
26 lines (18 loc) · 841 Bytes

2.3.47 - open_websocket_close_frame.md

File metadata and controls

26 lines (18 loc) · 841 Bytes

open_websocket_close_frame

启用websocket协议中关闭帧(opcode为0x08的帧)在onMessage回调中接收,默认为false。

开启后,可在WebSocketServer中的onMessage回调中接收到客户端或服务端发送的关闭帧,开发者可自行对其进行处理。

示例:

$server = new swoole_websocket_server("0.0.0.0", 9501);

$server->set(array("open_websocket_close_frame" => true));

$server->on('open', function (swoole_websocket_server $server, $request) {});

$server->on('message', function (swoole_websocket_server $server, $frame) {
    if ($frame->opcode == 0x08) {
        echo "Close frame received: Code {$frame->code} Reason {$frame->reason}\n";
    } else {
        echo "Message received: {$frame->data}\n";
    }
});

$server->on('close', function ($ser, $fd) {});

$server->start();