1- use futures:: { Sink , SinkExt , StreamExt } ;
1+ use futures:: { SinkExt , StreamExt } ;
22use hyper:: { Body , Request , Response , Server } ;
33use routerify:: prelude:: * ;
44use routerify:: { Middleware , Router , RouterService } ;
5- use routerify_websocket:: { upgrade_ws, upgrade_ws_with_config , Message , WebSocket , WebSocketConfig } ;
5+ use routerify_websocket:: { upgrade_ws, WebSocket } ;
66use serde:: { Deserialize , Serialize } ;
77use std:: { convert:: Infallible , net:: SocketAddr } ;
8- use tokio_tungstenite:: {
9- tungstenite:: protocol:: { frame:: coding:: CloseCode , CloseFrame , Message as ClientMessage } ,
10- WebSocketStream ,
11- } ;
8+ use tokio_tungstenite:: tungstenite:: protocol:: Message as ClientMessage ;
129
1310#[ derive( Serialize , Deserialize , Debug ) ]
1411struct User {
@@ -19,7 +16,7 @@ struct User {
1916async fn ws_handler ( ws : WebSocket ) {
2017 println ! ( "new websocket connection: {}" , ws. remote_addr( ) ) ;
2118
22- let ( mut tx , mut rx) = ws. split ( ) ;
19+ let ( _tx , mut rx) = ws. split ( ) ;
2320
2421 while let Some ( msg) = rx. next ( ) . await {
2522 let msg = msg. unwrap ( ) ;
@@ -60,7 +57,7 @@ async fn main() {
6057 let server = Server :: bind ( & addr) . serve ( service) ;
6158
6259 tokio:: spawn ( async move {
63- tokio:: time:: delay_for ( tokio:: time:: Duration :: from_secs ( 3 ) ) . await ;
60+ tokio:: time:: sleep ( tokio:: time:: Duration :: from_secs ( 3 ) ) . await ;
6461
6562 let ( mut ws, resp) = tokio_tungstenite:: connect_async ( "ws://127.0.0.1:3001/ws" )
6663 . await
@@ -73,7 +70,7 @@ async fn main() {
7370
7471 ws. close ( None ) . await . unwrap ( ) ;
7572
76- tokio:: time:: delay_for ( tokio:: time:: Duration :: from_secs ( 3 ) ) . await ;
73+ tokio:: time:: sleep ( tokio:: time:: Duration :: from_secs ( 3 ) ) . await ;
7774 } ) ;
7875
7976 println ! ( "App is running on: {}" , addr) ;
0 commit comments