Simplify udp-test
This commit is contained in:
parent
d80b238666
commit
d456b7a03a
@ -42,16 +42,14 @@ impl Server {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn start(&self) -> std::io::Result<usize> {
|
fn start(&self) -> std::io::Result<usize> {
|
||||||
let udp_host = UdpSocket::bind(&self.udp_host)?;
|
let udp_socket = UdpSocket::bind(&self.udp_host)?;
|
||||||
udp_host.set_read_timeout(self.socket_timeout)?;
|
udp_socket.set_read_timeout(self.socket_timeout)?;
|
||||||
|
|
||||||
let udp_target = UdpSocket::bind("127.0.0.1:3401")?;
|
let sent = udp_socket.send_to(&PONG, &self.udp_target)?;
|
||||||
udp_target.connect(&self.udp_target)?;
|
assert_eq!(sent, PONG.len());
|
||||||
|
|
||||||
udp_target.send(&PONG)?;
|
|
||||||
|
|
||||||
let mut buf = [0u8; 2048];
|
let mut buf = [0u8; 2048];
|
||||||
match udp_host.recv(&mut buf) {
|
match udp_socket.recv(&mut buf) {
|
||||||
Ok(len) => {
|
Ok(len) => {
|
||||||
println!("udp got len: {}", len);
|
println!("udp got len: {}", len);
|
||||||
assert_eq!(len, PONG.len());
|
assert_eq!(len, PONG.len());
|
||||||
|
Loading…
Reference in New Issue
Block a user