From 0865071dd785ab66e688134bde0021fc4cf3e041 Mon Sep 17 00:00:00 2001 From: Nikolay Kim Date: Sat, 21 Oct 2017 02:08:07 -0700 Subject: [PATCH] use threads for websocket example --- README.md | 6 ++++++ examples/websocket-chat/README.md | 7 +++++++ examples/websocket-chat/src/main.rs | 14 ++++++++++---- 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 211880e9e..6ed397799 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,7 @@ Actix web is licensed under the [Apache-2.0 license](http://opensource.org/licen * Keep-alive and slow requests support * [WebSockets support](https://fafhrd91.github.io/actix-web/actix_web/ws/index.html) * [Configurable request routing](https://fafhrd91.github.io/actix-web/actix_web/struct.RoutingMap.html) + * Multipart streams ## Usage @@ -29,6 +30,11 @@ actix-web = { git = "https://github.com/fafhrd91/actix-web.git" } ## Example +* [Mulitpart support](https://github.com/fafhrd91/actix-web/tree/master/examples/multipart) +* [Simple websocket example](https://github.com/fafhrd91/actix-web/tree/master/examples/websocket) +* [Tcp/Websocket chat](https://github.com/fafhrd91/actix-web/tree/master/examples/websocket-chat) + + ```rust extern crate actix; extern crate actix_web; diff --git a/examples/websocket-chat/README.md b/examples/websocket-chat/README.md index cf7bfa754..3d0fa69fb 100644 --- a/examples/websocket-chat/README.md +++ b/examples/websocket-chat/README.md @@ -3,6 +3,12 @@ This is extension of the [actix chat example](https://github.com/fafhrd91/actix/tree/master/examples/chat) +Added features: + +* Browser WebSocket client +* Chat server runs in separate thread +* Tcp listener runs in separate thread + ## Server @@ -10,6 +16,7 @@ Chat server listens for incoming tcp connections. Server can access several type * `\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 diff --git a/examples/websocket-chat/src/main.rs b/examples/websocket-chat/src/main.rs index 2a0b0ad63..f646b8690 100644 --- a/examples/websocket-chat/src/main.rs +++ b/examples/websocket-chat/src/main.rs @@ -204,11 +204,17 @@ fn main() { let _ = env_logger::init(); let sys = actix::System::new("websocket-example"); - // Start chat server actor - let server: SyncAddress<_> = server::ChatServer::default().start(); + // Start chat server actor in separate thread + let server: SyncAddress<_> = + Arbiter::start(|_| server::ChatServer::default()); - // Start tcp server - session::TcpServer::new("127.0.0.1:12345", server.clone()); + // Start tcp server in separate thread + let srv = server.clone(); + Arbiter::new("tcp-server").send::( + msgs::Execute::new(move || { + session::TcpServer::new("127.0.0.1:12345", srv); + Ok(()) + })); // Websocket sessions state let state = WsChatSessionState { addr: server };