微信小程序嵌入swoole,连接与监听
服务端
on('Open', function ($ws, $request) {
$ws->push($request->fd, "hello, welcome/n");
});
//监听WebSocket消息事件
$ws->on('Message', function ($ws, $frame) {
echo "Message: {$frame->data}/n";
$ws->push($frame->fd, $frame->data);
});
//监听WebSocket连接关闭事件
$ws->on('Close', function ($ws, $fd) {
echo "client-{$fd} is closed/n";
});
$ws->start();
小程序端
var socketOpen =
共有 0 条评论