mirror of
https://github.com/actix/actix-extras.git
synced 2024-11-28 01:32:57 +01:00
minor fix examples/websocket-chat
This commit is contained in:
parent
df393df547
commit
87188e1505
@ -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"] }
|
||||
|
@ -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/)
|
||||
|
@ -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();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user