From 091c1bca0340ce7ba31efa4e6146b203cd371a5c Mon Sep 17 00:00:00 2001 From: MeexReay Date: Tue, 22 Apr 2025 00:27:17 +0300 Subject: [PATCH] flush websocket --- src/proto/mod.rs | 6 +++++- src/proto/wrac.rs | 5 +++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/proto/mod.rs b/src/proto/mod.rs index 9dbd4f8..27765a0 100644 --- a/src/proto/mod.rs +++ b/src/proto/mod.rs @@ -100,7 +100,11 @@ pub fn connect(host: &str, ssl: bool, proxy: Option, wrac: bool) -> Resu stream.set_write_timeout(Duration::from_secs(3)); if wrac { - Ok(RacStream::WRAC(tungstenite::accept(stream)?)) + let (client, _) = tungstenite::client( + &format!("ws{}://{host}", if ssl { "s" } else { "" }), + stream + )?; + Ok(RacStream::WRAC(client)) } else { Ok(RacStream::RAC(stream)) } diff --git a/src/proto/wrac.rs b/src/proto/wrac.rs index 2ba7cde..b8a269c 100644 --- a/src/proto/wrac.rs +++ b/src/proto/wrac.rs @@ -11,6 +11,7 @@ pub fn send_message( message: &str ) -> Result<(), Box> { stream.write(Message::Binary(format!("\x01{message}").as_bytes().to_vec().into()))?; + stream.flush()?; Ok(()) } @@ -27,6 +28,7 @@ pub fn register_user( password: &str ) -> Result> { stream.write(Message::Binary(format!("\x03{name}\n{password}").as_bytes().to_vec().into()))?; + stream.flush()?; if let Ok(msg) = stream.read() { Ok(!msg.is_binary() || msg.into_data().get(0).unwrap_or(&0) == &0) } else { @@ -51,6 +53,7 @@ pub fn send_message_auth( message: &str ) -> Result> { stream.write(Message::Binary(format!("\x02{name}\n{password}\n{message}").as_bytes().to_vec().into()))?; + stream.flush()?; if let Ok(msg) = stream.read() { if msg.is_binary() { Ok(0) @@ -76,6 +79,7 @@ pub fn read_messages( chunked: bool ) -> Result, usize)>, Box> { stream.write(Message::Binary(vec![0x00].into()))?; + stream.flush()?; let packet_size = { let msg = stream.read()?; @@ -100,6 +104,7 @@ pub fn read_messages( stream.write(Message::Binary(format!("\x00\x02{}", last_size).as_bytes().to_vec().into()))?; packet_size - last_size }; + stream.flush()?; let msg = stream.read()?; if !msg.is_binary() {