Advertisement
Guest User

Untitled

a guest
Dec 27th, 2018
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Rust 0.71 KB | None | 0 0
  1.     pub fn send(&self, m: Message<T>, destination_address: &SocketAddrV4) {
  2.         let encoded: Vec<u8> = serialize(&m).expect("Could not serialize the message m");
  3.         self.udp_socket_sender
  4.             .send_to(&encoded[..], destination_address)
  5.             .expect("Could not send data");
  6.     }
  7.  
  8.     pub fn receive(&self) -> Message<T> {
  9.         let mut data_received = vec![0; 16384];
  10.  
  11.         let (number_of_bytes, _src_addr) = self
  12.             .udp_socket_receiver
  13.             .recv_from(&mut data_received) // Pass data_received as a mutable slice.
  14.             .expect("Could not receive data");
  15.  
  16.         deserialize(&data_received[..number_of_bytes]).expect("Could not deserialize received data")
  17.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement