Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- pub fn send(&self, m: Message<T>, destination_address: &SocketAddrV4) {
- let encoded: Vec<u8> = serialize(&m).expect("Could not serialize the message m");
- self.udp_socket_sender
- .send_to(&encoded[..], destination_address)
- .expect("Could not send data");
- }
- pub fn receive(&self) -> Message<T> {
- let mut data_received = vec![0; 16384];
- let (number_of_bytes, _src_addr) = self
- .udp_socket_receiver
- .recv_from(&mut data_received) // Pass data_received as a mutable slice.
- .expect("Could not receive data");
- deserialize(&data_received[..number_of_bytes]).expect("Could not deserialize received data")
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement