diff --git a/examples/websocket/src/client.rs b/examples/websocket/src/client.rs index 45c3a712..06dad542 100644 --- a/examples/websocket/src/client.rs +++ b/examples/websocket/src/client.rs @@ -30,7 +30,7 @@ fn main() { }) .map(|(reader, writer)| { let addr: SyncAddress<_> = ChatClient::create(|ctx| { - ctx.add_stream(reader); + ChatClient::add_stream(reader, ctx); ChatClient(writer) }); @@ -68,7 +68,7 @@ impl Actor for ChatClient { } fn stopping(&mut self, _: &mut Context) -> bool { - println!("Disconnected"); + println!("Stopping"); // Stop application on disconnect Arbiter::system().send(actix::msgs::SystemExit(0)); @@ -96,13 +96,21 @@ impl Handler for ChatClient { } /// Handle server websocket messages -impl Handler> for ChatClient { - type Result = (); +impl StreamHandler for ChatClient { - fn handle(&mut self, msg: Result, ctx: &mut Context) { + fn handle(&mut self, msg: Message, ctx: &mut Context) { match msg { - Ok(Message::Text(txt)) => println!("Server: {:?}", txt), + Message::Text(txt) => println!("Server: {:?}", txt), _ => () } } + + fn started(&mut self, ctx: &mut Context, _: SpawnHandle) { + println!("Connected"); + } + + fn finished(&mut self, err: Option, ctx: &mut Context, _: SpawnHandle) { + println!("Server disconnected"); + ctx.stop() + } }