ws works for testing

This commit is contained in:
GitProtogen
2026-03-05 09:10:33 +01:00
parent c08937b613
commit 06b476b7cd
3 changed files with 103 additions and 0 deletions
+44
View File
@@ -0,0 +1,44 @@
<?php
require __DIR__ . '/../vendor/autoload.php';
use Ratchet\MessageComponentInterface;
use Ratchet\ConnectionInterface;
use Ratchet\Server\IoServer;
use Ratchet\Http\HttpServer;
use Ratchet\WebSocket\WsServer;
class TestServer implements MessageComponentInterface
{
public function onOpen(ConnectionInterface $conn): void
{
$conn->send('Hello World!');
echo "New connection: {$conn->resourceId}\n";
}
public function onMessage(ConnectionInterface $from, $msg): void
{
$from->send("You said: $msg");
}
public function onClose(ConnectionInterface $conn): void
{
echo "Connection {$conn->resourceId} closed\n";
}
public function onError(ConnectionInterface $conn, \Exception $e): void
{
echo "Error: {$e->getMessage()}\n";
$conn->close();
}
}
$server = IoServer::factory(
new HttpServer(new WsServer(new TestServer())),
8080
);
echo "WebSocket server running on ws://localhost:8080\n";
$server->run();