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 .= " + + +
+ +