comparison src/bin/client.rs @ 19:ba09079686a0

Add support for different endianness between client and server.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Thu, 26 Aug 2021 23:43:36 +0200
parents 3f7b7a3ad8fe
children
comparison
equal deleted inserted replaced
18:3f7b7a3ad8fe 19:ba09079686a0
64 let address = "127.0.0.1:16150"; 64 let address = "127.0.0.1:16150";
65 let socket = Arc::new(Mutex::new(UdpSocket::bind("127.0.0.1:4321").unwrap())); 65 let socket = Arc::new(Mutex::new(UdpSocket::bind("127.0.0.1:4321").unwrap()));
66 println!("opened {:?}", socket); 66 println!("opened {:?}", socket);
67 67
68 let send = move |event: &Event| { 68 let send = move |event: &Event| {
69 // TODO: Yolo-alignment. 69 let buf = bincode::serialize(event).unwrap();
70 let buf: &[u8; std::mem::size_of::<Event>()] = unsafe { std::mem::transmute(event) };
71 let socket = socket.lock().unwrap(); 70 let socket = socket.lock().unwrap();
72 let amount = socket.send_to(buf, address).unwrap(); 71 let amount = socket.send_to(&buf, address).unwrap();
73 assert_eq!(amount, std::mem::size_of::<Event>()); 72 assert_eq!(amount, std::mem::size_of::<Event>());
74 }; 73 };
75 let send2 = send.clone(); 74 let send2 = send.clone();
76 let send3 = send.clone(); 75 let send3 = send.clone();
77 let send4 = send.clone(); 76 let send4 = send.clone();