File tree Expand file tree Collapse file tree 2 files changed +11
-2
lines changed
Expand file tree Collapse file tree 2 files changed +11
-2
lines changed Original file line number Diff line number Diff line change @@ -264,7 +264,7 @@ impl Network for TcpStream {
264264
265265 fn new ( ) -> Self {
266266 let std_listener =
267- std:: net:: TcpListener :: bind ( "127 .0.0.1 :0" ) . expect ( "Failed to bind TCP listener" ) ;
267+ std:: net:: TcpListener :: bind ( "0 .0.0.0 :0" ) . expect ( "Failed to bind TCP listener" ) ;
268268 std_listener. set_nonblocking ( true ) . unwrap ( ) ;
269269 let listener = TcpListener :: from_std ( std_listener) . unwrap ( ) ;
270270 let local_addr = listener. local_addr ( ) . unwrap ( ) ;
Original file line number Diff line number Diff line change @@ -99,9 +99,18 @@ async fn main() {
9999 info ! ( "Successfully connected to {}" , peer) ;
100100 }
101101
102+ let local_addr = runtime. network ( ) . local_addr ( ) ;
103+ let display_addr = if local_addr. ip ( ) . is_unspecified ( ) {
104+ // If bound to 0.0.0.0, the "local_addr" will show 0.0.0.0.
105+ // In a real app we'd resolve the primary LAN IP, but here we'll just hint it.
106+ format ! ( "<YOUR_LAN_IP>:{}" , local_addr. port( ) )
107+ } else {
108+ local_addr. to_string ( )
109+ } ;
110+
102111 println ! ( "========================================" ) ;
103112 println ! ( " Welcome to Arbiter Chat, {}!" , args. name) ;
104- println ! ( " Your node is listening on: {}" , runtime . network ( ) . local_addr ( ) ) ;
113+ println ! ( " Your node is listening on: {}" , display_addr ) ;
105114 println ! ( " Type your messages below. /quit to exit." ) ;
106115 println ! ( "========================================" ) ;
107116
You can’t perform that action at this time.
0 commit comments