From 1fe92ec2d0797036ee6bf1ea573cf371d5a751ed Mon Sep 17 00:00:00 2001 From: Benjamin Loison Date: Tue, 31 Jan 2023 01:05:09 +0100 Subject: [PATCH] Make a WebSocket example work with `crawler.yt.lemnoslife.com` --- website/index.php | 3 +-- website/websocket.php | 16 +++++----------- 2 files changed, 6 insertions(+), 13 deletions(-) diff --git a/website/index.php b/website/index.php index 255922d..acb3d19 100644 --- a/website/index.php +++ b/website/index.php @@ -13,8 +13,7 @@ See Search diff --git a/website/websocket.php b/website/websocket.php index 9dc5a28..e06dc3a 100644 --- a/website/websocket.php +++ b/website/websocket.php @@ -7,8 +7,7 @@ use Ratchet\ConnectionInterface; require __DIR__ . '/vendor/autoload.php'; /** - * chat.php - * Send any incoming messages to all connected clients (except sender) + * Send any incoming messages to all connected clients */ class MyChat implements MessageComponentInterface { @@ -26,11 +25,7 @@ class MyChat implements MessageComponentInterface public function onMessage(ConnectionInterface $from, $msg) { - foreach ($this->clients as $client) { - if ($from != $client) { - $client->send($msg); - } - } + $from->send($msg); } public function onClose(ConnectionInterface $conn) @@ -44,8 +39,7 @@ class MyChat implements MessageComponentInterface } } -// Run the server application through the WebSocket protocol on port 8080 -$app = new Ratchet\App('localhost', 8080); -$app->route('/chat', new MyChat(), array('*')); -$app->route('/echo', new Ratchet\Server\EchoServer(), array('*')); +// Run the server application through the WebSocket protocol on port 4430 +$app = new Ratchet\App('crawler.yt.lemnoslife.com', 4430); +$app->route('/websocket', new MyChat(), array('*')); $app->run();