Simplify udp-test

This commit is contained in:
Travis Burtrum 2019-07-14 01:50:51 -04:00
parent d80b238666
commit d456b7a03a
1 changed files with 5 additions and 7 deletions

View File

@ -42,16 +42,14 @@ impl Server {
}
fn start(&self) -> std::io::Result<usize> {
let udp_host = UdpSocket::bind(&self.udp_host)?;
udp_host.set_read_timeout(self.socket_timeout)?;
let udp_socket = UdpSocket::bind(&self.udp_host)?;
udp_socket.set_read_timeout(self.socket_timeout)?;
let udp_target = UdpSocket::bind("127.0.0.1:3401")?;
udp_target.connect(&self.udp_target)?;
udp_target.send(&PONG)?;
let sent = udp_socket.send_to(&PONG, &self.udp_target)?;
assert_eq!(sent, PONG.len());
let mut buf = [0u8; 2048];
match udp_host.recv(&mut buf) {
match udp_socket.recv(&mut buf) {
Ok(len) => {
println!("udp got len: {}", len);
assert_eq!(len, PONG.len());