diff --git a/examples/websocket-chat/Cargo.toml b/examples/websocket-chat/Cargo.toml index 2a5c9292..6ca5f0ad 100644 --- a/examples/websocket-chat/Cargo.toml +++ b/examples/websocket-chat/Cargo.toml @@ -24,5 +24,5 @@ serde = "1.0" serde_json = "1.0" serde_derive = "1.0" -actix = "^0.3.1" -actix-web = { git = "https://github.com/actix/actix-web.git" } +actix = { version = "^0.3.5" } +actix-web = { git = "https://github.com/actix/actix-web", features=["signal"] } diff --git a/examples/websocket-chat/README.md b/examples/websocket-chat/README.md index 2e75343b..28d734dd 100644 --- a/examples/websocket-chat/README.md +++ b/examples/websocket-chat/README.md @@ -1,6 +1,6 @@ # Websocket chat example -This is extension of the +This is extension of the [actix chat example](https://github.com/actix/actix/tree/master/examples/chat) Added features: @@ -9,18 +9,16 @@ Added features: * Chat server runs in separate thread * Tcp listener runs in separate thread - ## Server Chat server listens for incoming tcp connections. Server can access several types of message: - * `\list` - list all available rooms - * `\join name` - join room, if room does not exist, create new one - * `\name name` - set session name - * `some message` - just string, send messsage to all peers in same room - * client has to send heartbeat `Ping` messages, if server does not receive a heartbeat - message for 10 seconds connection gets droppped - +* `\list` - list all available rooms +* `\join name` - join room, if room does not exist, create new one +* `\name name` - set session name +* `some message` - just string, send messsage to all peers in same room +* client has to send heartbeat `Ping` messages, if server does not receive a heartbeat message for 10 seconds connection gets droppped + To start server use command: `cargo run --bin server` ## Client @@ -29,7 +27,6 @@ Client connects to server. Reads input from stdin and sends to server. To run client use command: `cargo run --bin client` - ## WebSocket Browser Client -Open url: http://localhost:8080/ +Open url: [http://localhost:8080/](http://localhost:8080/) diff --git a/examples/websocket-chat/src/main.rs b/examples/websocket-chat/src/main.rs index 8d0d55d9..39936b35 100644 --- a/examples/websocket-chat/src/main.rs +++ b/examples/websocket-chat/src/main.rs @@ -17,6 +17,8 @@ use std::time::Instant; use actix::*; use actix_web::*; +use actix::Arbiter; +use actix::actors::signal::{ProcessSignals, Subscribe}; mod codec; mod server; @@ -175,7 +177,6 @@ impl StreamHandler for WsChatSession } } - fn main() { let _ = env_logger::init(); let sys = actix::System::new("websocket-example"); @@ -192,9 +193,8 @@ fn main() { Ok(()) })); - // Create Http server with websocket support - HttpServer::new( + let addr = HttpServer::new( move || { // Websocket sessions state let state = WsChatSessionState { addr: server.clone() }; @@ -216,5 +216,10 @@ fn main() { .bind("127.0.0.1:8080").unwrap() .start(); + // Subscribe to unix signals + let signals = Arbiter::system_registry().get::(); + signals.send(Subscribe(addr.subscriber())); + + println!("Started http server: 127.0.0.1:8080"); let _ = sys.run(); }