mirror of
https://github.com/MeexReay/bRAC.git
synced 2025-05-06 13:38:04 +03:00
flush websocket
This commit is contained in:
parent
73f7c565e1
commit
091c1bca03
@ -100,7 +100,11 @@ pub fn connect(host: &str, ssl: bool, proxy: Option<String>, wrac: bool) -> Resu
|
|||||||
stream.set_write_timeout(Duration::from_secs(3));
|
stream.set_write_timeout(Duration::from_secs(3));
|
||||||
|
|
||||||
if wrac {
|
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 {
|
} else {
|
||||||
Ok(RacStream::RAC(stream))
|
Ok(RacStream::RAC(stream))
|
||||||
}
|
}
|
||||||
|
@ -11,6 +11,7 @@ pub fn send_message(
|
|||||||
message: &str
|
message: &str
|
||||||
) -> Result<(), Box<dyn Error>> {
|
) -> Result<(), Box<dyn Error>> {
|
||||||
stream.write(Message::Binary(format!("\x01{message}").as_bytes().to_vec().into()))?;
|
stream.write(Message::Binary(format!("\x01{message}").as_bytes().to_vec().into()))?;
|
||||||
|
stream.flush()?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -27,6 +28,7 @@ pub fn register_user(
|
|||||||
password: &str
|
password: &str
|
||||||
) -> Result<bool, Box<dyn Error>> {
|
) -> Result<bool, Box<dyn Error>> {
|
||||||
stream.write(Message::Binary(format!("\x03{name}\n{password}").as_bytes().to_vec().into()))?;
|
stream.write(Message::Binary(format!("\x03{name}\n{password}").as_bytes().to_vec().into()))?;
|
||||||
|
stream.flush()?;
|
||||||
if let Ok(msg) = stream.read() {
|
if let Ok(msg) = stream.read() {
|
||||||
Ok(!msg.is_binary() || msg.into_data().get(0).unwrap_or(&0) == &0)
|
Ok(!msg.is_binary() || msg.into_data().get(0).unwrap_or(&0) == &0)
|
||||||
} else {
|
} else {
|
||||||
@ -51,6 +53,7 @@ pub fn send_message_auth(
|
|||||||
message: &str
|
message: &str
|
||||||
) -> Result<u8, Box<dyn Error>> {
|
) -> Result<u8, Box<dyn Error>> {
|
||||||
stream.write(Message::Binary(format!("\x02{name}\n{password}\n{message}").as_bytes().to_vec().into()))?;
|
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 let Ok(msg) = stream.read() {
|
||||||
if msg.is_binary() {
|
if msg.is_binary() {
|
||||||
Ok(0)
|
Ok(0)
|
||||||
@ -76,6 +79,7 @@ pub fn read_messages(
|
|||||||
chunked: bool
|
chunked: bool
|
||||||
) -> Result<Option<(Vec<String>, usize)>, Box<dyn Error>> {
|
) -> Result<Option<(Vec<String>, usize)>, Box<dyn Error>> {
|
||||||
stream.write(Message::Binary(vec![0x00].into()))?;
|
stream.write(Message::Binary(vec![0x00].into()))?;
|
||||||
|
stream.flush()?;
|
||||||
|
|
||||||
let packet_size = {
|
let packet_size = {
|
||||||
let msg = stream.read()?;
|
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()))?;
|
stream.write(Message::Binary(format!("\x00\x02{}", last_size).as_bytes().to_vec().into()))?;
|
||||||
packet_size - last_size
|
packet_size - last_size
|
||||||
};
|
};
|
||||||
|
stream.flush()?;
|
||||||
|
|
||||||
let msg = stream.read()?;
|
let msg = stream.read()?;
|
||||||
if !msg.is_binary() {
|
if !msg.is_binary() {
|
||||||
|
Loading…
Reference in New Issue
Block a user