diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..13566b8 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..68fb876 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/php-com-cen.iml b/.idea/php-com-cen.iml new file mode 100644 index 0000000..7dd7874 --- /dev/null +++ b/.idea/php-com-cen.iml @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/php.xml b/.idea/php.xml new file mode 100644 index 0000000..7e8212c --- /dev/null +++ b/.idea/php.xml @@ -0,0 +1,45 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/bin/server.php b/bin/WebSocketServer.php similarity index 60% rename from bin/server.php rename to bin/WebSocketServer.php index 3082ab0..ea68ee9 100644 --- a/bin/server.php +++ b/bin/WebSocketServer.php @@ -1,14 +1,21 @@ connectedUsers[] = $conn; - $conn->send("Connected users: " . count($this->connectedUsers)); + $conn->send("Connected users: " . count($this->connectedUsers) . " (One is you)"); echo "New connection: {$conn->resourceId}\n"; } public function onMessage(ConnectionInterface $from, $msg): void { - $from->send("Resending: $msg"); foreach ($this->connectedUsers as $conn) { if ($from->resourceId !== $conn->resourceId) { $conn->send("From user " . $from->resourceId . ": " . $msg); } } + $from->send("Message sent to others"); } public function onClose(ConnectionInterface $conn): void @@ -51,11 +58,17 @@ class TestServer implements MessageComponentInterface } } +$routes = new RouteCollection(); +$routes->add("login", new Route("/login", ["_controller" => new LoginController()])); +$routes->add("register", new Route("/register", ["_controller" => new RegisterController()])); +$routes->add("ws", new Route("/ws", ["_controller" => new WsServer(new WebSocketServer())])); + $server = IoServer::factory( - new HttpServer(new WsServer(new TestServer())), - 8080 + new HttpServer(new Router(new UrlMatcher($routes, new RequestContext()))), + 8080, + "0.0.0.0" ); -echo "WebSocket server running on ws://localhost:8080\n"; +echo "Server running on http://localhost:8080\n"; $server->run(); \ No newline at end of file diff --git a/public/index.php b/public/index.php index d5ddd76..172f1ce 100644 --- a/public/index.php +++ b/public/index.php @@ -10,7 +10,7 @@ $html->content .= " - Ratchet Hello World + Chat

WebSocket Test

@@ -21,7 +21,7 @@ $html->content .= "