websocket: demonstrating send message in Rust code.

This commit is contained in:
Dave Hrycyszyn
2019-12-14 17:09:00 +00:00
parent 13d14cff95
commit 631827f5eb
+8 -4
View File
@@ -7,7 +7,7 @@ struct Server {
impl Handler for Server {
fn on_message(&mut self, msg: Message) -> Result<()> {
foomp();
foomp(msg.clone());
// Echo the message back
self.out.send(msg)
}
@@ -16,7 +16,9 @@ impl Handler for Server {
match code {
CloseCode::Normal => println!("The client is done with the connection."),
CloseCode::Away => println!("The client is leaving the site."),
_ => println!("The client encountered an error: {}", reason),
_ => {
println!("The client encountered an error: {}", reason);
}
}
}
}
@@ -25,6 +27,8 @@ pub fn start(socket_address: SocketAddr) {
listen(socket_address, |out| Server { out: out }).unwrap()
}
fn foomp() {
println!("FOOOOOOOOOOOOOOOOOOOOOOOOMMMMMMMMMMMMPPPPPPPPPPPPPPPPP");
// Proves we can call Rust methods from the websocket listener. Re-route it to wherever JS puts
// the `send_message` functionality.
fn foomp(msg: Message) {
println!("Foomp!: {:?}", msg);
}