Mathias Gottschlag 5 anni fa
parent
commit
1c3dae7000
2 ha cambiato i file con 11 aggiunte e 6 eliminazioni
  1. 5
    2
      src/bin/client.rs
  2. 6
    4
      src/bin/server.rs

+ 5
- 2
src/bin/client.rs Vedi File

@@ -2,9 +2,9 @@ use std::fs::create_dir_all;
2 2
 use std::io;
3 3
 use std::sync::{Arc, Mutex};
4 4
 
5
+use tokio::io::{AsyncReadExt, AsyncWriteExt};
5 6
 use tokio::net::{UnixListener, UnixStream};
6 7
 use tokio::stream::StreamExt;
7
-use tokio::io::{AsyncWriteExt, AsyncReadExt};
8 8
 
9 9
 use twfss::Database;
10 10
 
@@ -61,7 +61,10 @@ async fn main() {
61 61
                     Err(e) => {
62 62
                         // Log error and try to send it to the stream.
63 63
                         // TODO
64
-                        stream.write_all(format!("Error: {:?}", e).as_bytes()).await.ok();
64
+                        stream
65
+                            .write_all(format!("Error: {:?}", e).as_bytes())
66
+                            .await
67
+                            .ok();
65 68
                     }
66 69
                 };
67 70
             }

+ 6
- 4
src/bin/server.rs Vedi File

@@ -1,13 +1,13 @@
1
+use std::fs::create_dir_all;
1 2
 use std::net::SocketAddr;
2 3
 use std::sync::{Arc, Mutex};
3
-use std::fs::create_dir_all;
4 4
 
5 5
 use async_tungstenite::accept_async;
6
+use futures::sink::SinkExt;
7
+use futures_tokio_compat::Compat;
6 8
 use log::*;
7 9
 use tokio::net::{TcpListener, TcpStream};
8 10
 use tokio::stream::StreamExt;
9
-use futures_tokio_compat::Compat;
10
-use futures::sink::SinkExt;
11 11
 
12 12
 use twfss::Database;
13 13
 
@@ -65,7 +65,9 @@ async fn main() {
65 65
 // TODO: Robust error handling.
66 66
 
67 67
 async fn accept_connection(peer: SocketAddr, stream: TcpStream) {
68
-    let mut ws_stream = accept_async(Compat::new(stream)).await.expect("Failed to accept");
68
+    let mut ws_stream = accept_async(Compat::new(stream))
69
+        .await
70
+        .expect("Failed to accept");
69 71
 
70 72
     info!("New WebSocket connection from {}.", peer);
71 73
 

Loading…
Annulla
Salva