<?php $ws = new swoole_websocket_server("0.0.0.0",9502); $ws->on('open', function ($ws, $request) { var_dump($request->fd, $request->get, $request->server); $ws->push($request->fd, '{"data":"socket server connected"}'); }); $ws->on('message', function ($ws, $frame) { echo "<pre>"; print_r($frame); foreach($ws->connections as $fd){ $ws->push($fd, "{$frame->data}"); } }); $ws->on('close', function ($ws, $fd) { echo "client-{$fd} is closed\n"; }); $ws->start(); ?>
转载请注明原文地址: https://www.6miu.com/read-2632576.html