From 87188e1505686d5a2ec73155121e2df8a85e3e6c Mon Sep 17 00:00:00 2001 From: ami44 Date: Sat, 30 Dec 2017 16:50:49 +0100 Subject: [PATCH] minor fix examples/websocket-chat --- examples/websocket-chat/Cargo.toml | 4 ++-- examples/websocket-chat/README.md | 19 ++++++++----------- examples/websocket-chat/src/main.rs | 11 ++++++++--- 3 files changed, 18 insertions(+), 16 deletions(-) diff --git a/examples/websocket-chat/Cargo.toml b/examples/websocket-chat/Cargo.toml index 2a5c92925..6ca5f0ad3 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 2e75343b1..28d734dd3 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 8d0d55d98..39936b358 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(); }