Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- fn main() -> Result<()> {
- let listener = TcpListener::bind("127.0.0.1:25565")?;
- for stream in listener.incoming() {
- match stream {
- Ok(mut stream) => {
- println!("{:#?}", stream);
- let mut buf = Vec::new();
- let _bytes_read = stream.read(&mut buf)?;
- println!("Client Response: {:#?}", buf);
- let _bytes_written = stream.write(&pack(&JSON_RESPONSE)?)?;
- sleep(std::time::Duration::from_millis(50));
- }
- Err(e) => println!("Could not connect to client! Error: {}", e),
- }
- }
- Ok(())
- }
- fn pack<T: Serialize>(data: &T) -> Result<Vec<u8>> {
- use bincode::config;
- let mut config = config();
- let bytes = config.big_endian().serialize(&data)?;
- Ok(bytes)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement