You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am cloning the Senders and sending them to another thread. Sending messages to the websockets works fine, but once the websocket is closed, calling sender.send("message") still returns Ok(()). How do I change it so that calling send() on the Sender of a dead websocket returns an error? Also, where do the messages go after the websocket is closed? Do they just get discarded?
Here is an isolated example:
use std::thread;use std::sync::mpsc;use ws::{listen,Handler,Handshake,CloseCode,Result};structServer{out: ws::Sender,tx: mpsc::Sender<ws::Sender>}implHandlerforServer{fnon_open(&mutself, _:Handshake) -> Result<()>{self.tx.send(self.out.clone()).unwrap();Ok(())}}fnmain(){let(tx, rx) = mpsc::channel();
thread::spawn(move || {loop{let out: ws::Sender = rx.recv().unwrap();
out.send("Hello").unwrap();
out.close(CloseCode::Normal).unwrap();////////////MY ISSUE////Why doesn't this unwrap() panic, and what happens to the "Hey" message - is it discarded?
out.send("Hey").unwrap();}});listen("127.0.0.1:3012", |out| {Server{out: out,tx: tx.clone()}}).unwrap();}
How do I detect whether or not the websocket connected to the Sender has been closed?
The text was updated successfully, but these errors were encountered:
ghost
changed the title
Send channel stays open after websocket is closed
Sender sends messages to closed websocket
Mar 17, 2020
I am cloning the
Sender
s and sending them to another thread. Sending messages to the websockets works fine, but once the websocket is closed, callingsender.send("message")
still returnsOk(())
. How do I change it so that callingsend()
on the Sender of a dead websocket returns an error? Also, where do the messages go after the websocket is closed? Do they just get discarded?Here is an isolated example:
How do I detect whether or not the websocket connected to the Sender has been closed?
The text was updated successfully, but these errors were encountered: