1
0
mirror of https://github.com/actix/actix-extras.git synced 2024-11-24 07:53:00 +01:00

minor fix examples/websocket-chat

This commit is contained in:
ami44 2017-12-30 16:50:49 +01:00
parent df393df547
commit 87188e1505
3 changed files with 18 additions and 16 deletions

View File

@ -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"] }

View File

@ -9,7 +9,6 @@ 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:
@ -18,8 +17,7 @@ Chat server listens for incoming tcp connections. Server can access several type
* `\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
* 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`
@ -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/)

View File

@ -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<ws::Message> 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::<ProcessSignals>();
signals.send(Subscribe(addr.subscriber()));
println!("Started http server: 127.0.0.1:8080");
let _ = sys.run();
}