January 2019
Intermediate to advanced
520 pages
14h 32m
English
First, we will implement a StreamHandler instance of the ws::Message messages:
impl StreamHandler<Message, ProtocolError> for NotifyActor { fn handle(&mut self, msg: Message, ctx: &mut Self::Context) { match msg { Message::Ping(msg) => { self.last_ping = Instant::now(); ctx.pong(&msg); } Message::Pong(_) => { self.last_ping = Instant::now(); } Message::Text(_) => { }, Message::Binary(_) => { }, Message::Close(_) => { ctx.stop(); } } }}
This is a basic approach for implementing the WebSocket protocol interaction with actix-web. We will use the ws::start method later to attach a Stream of WebSocket messages to this actor.
The Message type has multiple variants that reflects types of WebSocket messages from RFC 6455 (the official protocol ...
Read now
Unlock full access