use Swoole\WebSocket\Server;
use Swoole\Http\Request;
use Swoole\WebSocket\Frame;
$ws = new Server(0.0.0.0, 9501);
$ws-on('open', function (Server $server, Request $request) {
echo server: handshake success with fd{$request-fd}\n;
});
$ws-on('message', function (Server $server, Frame $frame) {
echo receive from {$frame-fd}:{$frame-data},opcode:{$frame-opcode},fin:{$frame-finish}\n;
$server-push($frame-fd, this is server);
});
$ws-on('close', function ($ser, $fd) {
echo client {$fd} closed\n;
});