🌈 Socket.io Server implementation for Swoole
Thank you.[Contribute].
$config = new SocketIO\Engine\Server\ConfigPayload();
$config
// server worker_num
->setWorkerNum(2)
// server daemonize
->setDaemonize(0);
$io = new SocketIO\Server(9501, $config, function(SocketIO\Server $io) {
$io->on('connection', function (SocketIO\Server $socket) {
$socket->on('new message', function (SocketIO\Server $socket) {
$socket->broadcast('new message', $socket->getMessage());
});
$socket->on('new user', function (SocketIO\Server $socket) {
$socket->broadcast('login', $socket->getMessage());
});
$socket->on('disconnect', function (SocketIO\Server $socket) {
$socket->broadcast('user left', $socket->getMessage());
});
});
});
$io->start();