Skip to content

Commit a029b49

Browse files
committed
fix: LAN
1 parent f0f7c61 commit a029b49

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

arbiter/src/network/tcp.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff 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();

examples/chat/src/main.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff 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

0 commit comments

Comments
 (0)