From 2aa4a82499d4becd2284cdb482213d541b8804dd Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 28 Apr 2024 16:29:10 +0200 Subject: Adding upstream version 86.0.1. Signed-off-by: Daniel Baumann --- third_party/rust/ws/examples/server.rs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 third_party/rust/ws/examples/server.rs (limited to 'third_party/rust/ws/examples/server.rs') diff --git a/third_party/rust/ws/examples/server.rs b/third_party/rust/ws/examples/server.rs new file mode 100644 index 0000000000..fd9f5ae671 --- /dev/null +++ b/third_party/rust/ws/examples/server.rs @@ -0,0 +1,26 @@ +extern crate env_logger; +/// Simple WebSocket server with error handling. It is not necessary to setup logging, but doing +/// so will allow you to see more details about the connection by using the RUST_LOG env variable. +extern crate ws; + +use ws::listen; + +fn main() { + // Setup logging + env_logger::init(); + + // Listen on an address and call the closure for each connection + if let Err(error) = listen("127.0.0.1:3012", |out| { + // The handler needs to take ownership of out, so we use move + move |msg| { + // Handle messages received on this connection + println!("Server got message '{}'. ", msg); + + // Use the out channel to send messages back + out.send(msg) + } + }) { + // Inform the user of failure + println!("Failed to create WebSocket due to {:?}", error); + } +} -- cgit v1.2.3