fix compression mb
This commit is contained in:
parent
9f34891b8a
commit
8058a05876
4 changed files with 119 additions and 134 deletions
File diff suppressed because one or more lines are too long
38
examples/test_compression.rs
Normal file
38
examples/test_compression.rs
Normal file
|
@ -0,0 +1,38 @@
|
|||
use std::{net::TcpListener, sync::{atomic::AtomicBool, atomic::Ordering}, thread};
|
||||
use std::sync::mpsc::channel;
|
||||
use rust_mc_proto::{DataBufferReader, DataBufferWriter, MCConn, MCConnTcp, MinecraftConnection, Packet, ProtocolError};
|
||||
|
||||
const LONG_TEXT: &str = "some_long_text_wow_123123123123123123123123";
|
||||
|
||||
fn main() {
|
||||
let (tx, rx) = channel::<()>();
|
||||
|
||||
let server_tx = tx.clone();
|
||||
thread::spawn(move || {
|
||||
let listener = TcpListener::bind("localhost:44447").unwrap();
|
||||
|
||||
server_tx.send(()).unwrap();
|
||||
|
||||
for stream in listener.incoming() {
|
||||
let mut stream = MCConnTcp::new(stream.unwrap());
|
||||
stream.set_compression(2);
|
||||
|
||||
let packet = stream.read_packet().unwrap();
|
||||
stream.write_packet(&packet).unwrap();
|
||||
}
|
||||
});
|
||||
|
||||
rx.recv().unwrap();
|
||||
|
||||
let mut conn = MCConnTcp::connect("localhost:44447").unwrap();
|
||||
conn.set_compression(2);
|
||||
|
||||
let mut packet = Packet::empty(0x12);
|
||||
packet.write_string(LONG_TEXT).unwrap();
|
||||
conn.write_packet(&packet).unwrap();
|
||||
|
||||
let mut packet = conn.read_packet().unwrap();
|
||||
if packet.id == 0x12 && packet.read_string().unwrap() == LONG_TEXT {
|
||||
println!("success");
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue