1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
use ws::{connect, CloseCode};
pub struct WsHandler {
pub to: String,
}
impl WsHandler {
pub fn new(to: &str) -> Self {
Self { to: to.to_string() }
}
pub fn out(self) {
connect("http://0.0.0.0:4200", |out| {
out.send("Hello WebSocket").unwrap();
move |msg| {
println!("Got message: {}", msg);
out.close(CloseCode::Normal)
}
})
.unwrap()
}
}