make the UDP socket specifiable on command line

this makes the bindings work on things other than localhost
This commit is contained in:
bunnie 2022-02-21 01:26:04 +08:00
parent 760957154e
commit 271fd4d559

View file

@ -212,13 +212,13 @@ impl<'a> ShellCmdApi<'a> for NetCmd {
if let Some(udp_socket) = &self.udp { if let Some(udp_socket) = &self.udp {
write!(ret, "Socket listener already installed on {:?}.", udp_socket.socket_addr().unwrap()).unwrap(); write!(ret, "Socket listener already installed on {:?}.", udp_socket.socket_addr().unwrap()).unwrap();
} else { } else {
let port = if let Some(tok_str) = tokens.next() { let socket = if let Some(tok_str) = tokens.next() {
if let Ok(n) = tok_str.parse::<u16>() { n } else { 6502 } tok_str
} else { } else {
6502 "127.0.0.1:6502"
}; };
let mut udp = net::UdpSocket::bind_xous( let mut udp = net::UdpSocket::bind_xous(
format!("127.0.0.1:{}", port), socket,
Some(UDP_TEST_SIZE as u16) Some(UDP_TEST_SIZE as u16)
).unwrap(); ).unwrap();
udp.set_read_timeout(Some(Duration::from_millis(1000))).unwrap(); udp.set_read_timeout(Some(Duration::from_millis(1000))).unwrap();
@ -228,7 +228,7 @@ impl<'a> ShellCmdApi<'a> for NetCmd {
[Some(NetCmdDispatch::UdpTest1.to_usize().unwrap()), None, None, None] [Some(NetCmdDispatch::UdpTest1.to_usize().unwrap()), None, None, None]
); );
self.udp = Some(udp); self.udp = Some(udp);
write!(ret, "Created UDP socket listener on port {}", port).unwrap(); write!(ret, "Created UDP socket listener on socket {}", socket).unwrap();
} }
} }
"udpclose" => { "udpclose" => {