Files
Testing/wss/ratchet1.php
sean 0e8a8b3028
Some checks are pending
deploy-testing / deploy (push) Waiting to run
Initial testing snapshot
2026-11-17 16:15:01 -05:00

58 lines
1.6 KiB
PHP

<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
use Ratchet\MessageComponentInterface;
use Ratchet\ConnectionInterface;
class MyChat implements MessageComponentInterface {
protected $clients;
public function __construct() {
$this->clients = new \SplObjectStorage;
}
public function onOpen(ConnectionInterface $conn) {
$this->clients->attach($conn);
}
public function onMessage(ConnectionInterface $from, $msg) {
foreach ($this->clients as $client) {
if ($from != $client) {
$client->send($msg);
}
}
}
public function onClose(ConnectionInterface $conn) {
$this->clients->detach($conn);
}
public function onError(ConnectionInterface $conn, \Exception $e) {
$conn->close();
}
}
// Make sure composer dependencies have been installed
// require __DIR__ . '/vendor/autoload.php';
require '../vendor/autoload.php';
$app = new \Ratchet\Http\HttpServer(
new \Ratchet\WebSocket\WsServer(
new MyChat()
)
);
$loop = \React\EventLoop\Factory::create();
$secure_websockets = new \React\Socket\Server('99.192.174.19:8080', $loop);
$secure_websockets = new \React\Socket\SecureServer($secure_websockets, $loop, [
'local_cert' => '/etc/letsencrypt/live/mojo.bateworld.com-0001/cert.pem',
'local_pk' => '/etc/letsencrypt/live/mojo.bateworld.com-0001/privkey.pem',
'verify_peer' => false
]);
$secure_websockets_server = new \Ratchet\Server\IoServer($app, $secure_websockets, $loop);
$secure_websockets_server->run();