mirror of
https://github.com/actix/actix-extras.git
synced 2024-11-24 16:02:59 +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_json = "1.0"
|
||||||
serde_derive = "1.0"
|
serde_derive = "1.0"
|
||||||
|
|
||||||
actix = "^0.3.1"
|
actix = { version = "^0.3.5" }
|
||||||
actix-web = { git = "https://github.com/actix/actix-web.git" }
|
actix-web = { git = "https://github.com/actix/actix-web", features=["signal"] }
|
||||||
|
@ -9,17 +9,15 @@ Added features:
|
|||||||
* Chat server runs in separate thread
|
* Chat server runs in separate thread
|
||||||
* Tcp listener runs in separate thread
|
* Tcp listener runs in separate thread
|
||||||
|
|
||||||
|
|
||||||
## Server
|
## Server
|
||||||
|
|
||||||
Chat server listens for incoming tcp connections. Server can access several types of message:
|
Chat server listens for incoming tcp connections. Server can access several types of message:
|
||||||
|
|
||||||
* `\list` - list all available rooms
|
* `\list` - list all available rooms
|
||||||
* `\join name` - join room, if room does not exist, create new one
|
* `\join name` - join room, if room does not exist, create new one
|
||||||
* `\name name` - set session name
|
* `\name name` - set session name
|
||||||
* `some message` - just string, send messsage to all peers in same room
|
* `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
|
* client has to send heartbeat `Ping` messages, if server does not receive a heartbeat message for 10 seconds connection gets droppped
|
||||||
message for 10 seconds connection gets droppped
|
|
||||||
|
|
||||||
To start server use command: `cargo run --bin server`
|
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`
|
To run client use command: `cargo run --bin client`
|
||||||
|
|
||||||
|
|
||||||
## WebSocket Browser 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::*;
|
||||||
use actix_web::*;
|
use actix_web::*;
|
||||||
|
use actix::Arbiter;
|
||||||
|
use actix::actors::signal::{ProcessSignals, Subscribe};
|
||||||
|
|
||||||
mod codec;
|
mod codec;
|
||||||
mod server;
|
mod server;
|
||||||
@ -175,7 +177,6 @@ impl StreamHandler<ws::Message> for WsChatSession
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let _ = env_logger::init();
|
let _ = env_logger::init();
|
||||||
let sys = actix::System::new("websocket-example");
|
let sys = actix::System::new("websocket-example");
|
||||||
@ -192,9 +193,8 @@ fn main() {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
|
||||||
// Create Http server with websocket support
|
// Create Http server with websocket support
|
||||||
HttpServer::new(
|
let addr = HttpServer::new(
|
||||||
move || {
|
move || {
|
||||||
// Websocket sessions state
|
// Websocket sessions state
|
||||||
let state = WsChatSessionState { addr: server.clone() };
|
let state = WsChatSessionState { addr: server.clone() };
|
||||||
@ -216,5 +216,10 @@ fn main() {
|
|||||||
.bind("127.0.0.1:8080").unwrap()
|
.bind("127.0.0.1:8080").unwrap()
|
||||||
.start();
|
.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();
|
let _ = sys.run();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user