diff --git a/examples/poem/local-server-with-browser/src/main.rs b/examples/poem/local-server-with-browser/src/main.rs index 417456a331..ebf5d59b98 100644 --- a/examples/poem/local-server-with-browser/src/main.rs +++ b/examples/poem/local-server-with-browser/src/main.rs @@ -19,10 +19,10 @@ async fn main() -> Result<(), std::io::Error> { // To test port assignment, run two instances of this example at once. // - // For ports <1024, running with administrator priveleges would be needed on - // Unix. For port 0, the OS would assign a port and we'd need to find out + // For ports <1024, running with administrator priveledges would be needed + // on Unix. For port 0, the OS would assign a port and we'd need to find out // what that port's number is. - let (min_port, max_port) = (8080, 8085); + let (min_port, max_port) = (8080, 8080); // Using 127.0.0.1 instead of 0.0.0.0 for security; a local server should // not, generally, be visible from the network. let hostname = "127.0.0.1"; @@ -32,21 +32,19 @@ async fn main() -> Result<(), std::io::Error> { if port > max_port { return Err(error.unwrap()); } - let listener = TcpListener::bind(format!("{hostname}:{}", port)); + let listener = TcpListener::bind(format!("{hostname}:{port}")); match listener.into_acceptor().await { Ok(a) => break a, - Err(err) => { - // Most likely, another application is bound to this port. - eprintln!("Couldn't bind to port {port}."); - error = Some(err) - } + Err(err) => error = Some(err), }; + // Most likely, another application is bound to this port. + eprintln!("Couldn't bind to port {port}."); port += 1; }; + eprintln!("Listening at {hostname}:{port}."); // Now that the acceptor exists, the browser should be able to connect let http_address = format!("http://{hostname}:{port}/"); - eprintln!("Listening at {http_address}."); eprint!("Trying to launch a browser at {http_address}..."); match open::that(&http_address) { Ok(_) => eprintln!(" Success!"),