Skip to content

Commit

Permalink
Fixup to e3b2201: fix a typo, minor code simplification
Browse files Browse the repository at this point in the history
  • Loading branch information
ilyagr committed Feb 29, 2024
1 parent e3b2201 commit 2ac3fcb
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions examples/poem/local-server-with-browser/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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;
};

// Now that the acceptor exists, the browser should be able to connect
eprintln!("Listening at {hostname}:{port}.");
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!"),
Expand Down

0 comments on commit 2ac3fcb

Please sign in to comment.