diff --git a/examples/client.rs b/examples/client.rs index 144696a..5dd988e 100644 --- a/examples/client.rs +++ b/examples/client.rs @@ -25,35 +25,34 @@ async fn main() -> Result<(), Box> { // sleep to avoid racing the server on startup when using cargo watch sleep(Duration::from_millis(200)).await; - if let Some(connect_addr) = env::args().nth(1) { - let url = url::Url::parse(&connect_addr)?; + let connect_addr = env::args() + .nth(1) + .unwrap_or_else(|| "ws://127.0.0.1:8080".to_string()); + let url = url::Url::parse(&connect_addr)?; - let (stdin_tx, stdin_rx) = futures_channel::mpsc::unbounded(); - tokio::spawn(read_stdin(stdin_tx)); + let (stdin_tx, stdin_rx) = futures_channel::mpsc::unbounded(); + tokio::spawn(read_stdin(stdin_tx)); - let (ws_stream, res) = connect_async(url).await?; + let (ws_stream, res) = connect_async(url).await?; - println!( - "WebSocket handshake has been successfully completed\n{:#?}", - res - ); + println!( + "WebSocket handshake has been successfully completed\n{:#?}", + res + ); - let (sink, stream) = ws_stream.split(); + let (sink, stream) = ws_stream.split(); - let stdin_to_ws = stdin_rx.map(Ok).forward(sink); + let stdin_to_ws = stdin_rx.map(Ok).forward(sink); - let ws_to_stdout = { - stream.for_each(|message| async { - let data = message.unwrap().into_data(); - tokio::io::stdout().write_all(&data).await.unwrap(); - }) - }; + let ws_to_stdout = { + stream.for_each(|message| async { + let data = message.unwrap().into_data(); + tokio::io::stdout().write_all(&data).await.unwrap(); + }) + }; - pin_mut!(stdin_to_ws, ws_to_stdout); - future::select(stdin_to_ws, ws_to_stdout).await; - } else { - eprintln!("This program requires at least one argument!") - } + pin_mut!(stdin_to_ws, ws_to_stdout); + future::select(stdin_to_ws, ws_to_stdout).await; Ok(()) }