tonic
For testing purposes it would be good if there was a way to retrieve the port a server is listening on when it was started without a specified port (ie. with port 0).
Add functionality to obtain the port/local_addr a server is listening on (similar to https://docs.rs/hyper/0.13.5/hyper/server/struct.Server.html#method.local_addr).
This is also very useful when there are multiple servers on the same host, where it is usual to let the OS find a free port by specifying :0.
It may helps.
let addr: SocketAddr = "0.0.0.0:0".parse()?;
let mut listener = tokio::net::TcpListener::bind(addr).await?;
Great, that worked, thanks!
Can we reopen this? Although there is a workaround, it would be great to support this out of the box.
Most helpful comment
https://github.com/hyperium/tonic/blob/f6ecaff0de76de16cb1f680dc3473c8cf2bbaddd/examples/src/autoreload/server.rs#L39-L41
It may helps.