Advertisement
Guest User

Untitled

a guest
Oct 24th, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. fn main() -> Result<()> {
  2. let listener = TcpListener::bind("127.0.0.1:25565")?;
  3.  
  4. for stream in listener.incoming() {
  5. match stream {
  6. Ok(mut stream) => {
  7. println!("{:#?}", stream);
  8.  
  9. let mut buf = Vec::new();
  10.  
  11. let _bytes_read = stream.read(&mut buf)?;
  12.  
  13. println!("Client Response: {:#?}", buf);
  14.  
  15. let _bytes_written = stream.write(&pack(&JSON_RESPONSE)?)?;
  16.  
  17. sleep(std::time::Duration::from_millis(50));
  18. }
  19. Err(e) => println!("Could not connect to client! Error: {}", e),
  20. }
  21. }
  22.  
  23. Ok(())
  24. }
  25.  
  26. fn pack<T: Serialize>(data: &T) -> Result<Vec<u8>> {
  27. use bincode::config;
  28.  
  29. let mut config = config();
  30.  
  31. let bytes = config.big_endian().serialize(&data)?;
  32.  
  33. Ok(bytes)
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement