Site icon 时鹏亮的Blog

Swoole WebSocket通信

请知悉:本文最近一次更新为 7年 前,文中内容可能已经过时。

架设很简单啊,参照官网:https://wiki.swoole.com/wiki/page/397.html

$server = new swoole_websocket_server("0.0.0.0", 9501);
$server->on('open', function (swoole_websocket_server $server, $request) {
echo "server: handshake success with fd{$request->fd}n";
});
$server->on('message', function (swoole_websocket_server $server, $frame) {
echo "receive from {$frame->fd}:{$frame->data},opcode:{$frame->opcode},fin:{$frame->finish}n";
$server->push($frame->fd, "this is server");
});
$server->on('close', function ($ser, $fd) {
echo "client {$fd} closedn";
});
$server->start();

就能架设起来,通信怎么搞?我是用的Firefox的插件Simple WebSocket Client做的测试,插件地址:https://addons.mozilla.org/en-US/firefox/addon/simple-websocket-client/


如您从本文得到了有价值的信息或帮助,请考虑扫描文末二维码捐赠和鼓励。

尊重他人劳动成果。转载请务必附上原文链接,我将感激不尽。


与《Swoole WebSocket通信》相关的博文:

Exit mobile version