From 06b476b7cd182e78c5d7201497ea65c2ed0c77bc Mon Sep 17 00:00:00 2001 From: GitProtogen Date: Thu, 5 Mar 2026 09:10:33 +0100 Subject: [PATCH] ws works for testing --- bin/server.php | 44 ++++++++++++++++++++++++++++++++++++++++++++ public/index.php | 47 +++++++++++++++++++++++++++++++++++++++++++++++ src/Html/Html.php | 12 ++++++++++++ 3 files changed, 103 insertions(+) create mode 100644 bin/server.php create mode 100644 src/Html/Html.php diff --git a/bin/server.php b/bin/server.php new file mode 100644 index 0000000..cb43faa --- /dev/null +++ b/bin/server.php @@ -0,0 +1,44 @@ +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(); \ No newline at end of file diff --git a/public/index.php b/public/index.php index 10e4919..d5ddd76 100644 --- a/public/index.php +++ b/public/index.php @@ -1,3 +1,50 @@ content .= " + + + + + Ratchet Hello World + + +

WebSocket Test

+
+ + + + + + + +"; +$html->renderContent(); diff --git a/src/Html/Html.php b/src/Html/Html.php new file mode 100644 index 0000000..79d522d --- /dev/null +++ b/src/Html/Html.php @@ -0,0 +1,12 @@ +content; + } +} \ No newline at end of file