You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Send the native NUClearNet logs to the JavaScript logger
The library wrote its logs straight to stderr while our own messages went
through console.error with a [NUClearNet.js] prefix, so turning debug on
gave you two differently formatted streams and the native half ignored
any redirection of console.
NUClear now lets an embedder install a log handler, so hand the native
messages to the same _log path as everything else. The component the
message came from is included as a field.
Also syncs the vendored nuclear subtree from NUClear@b7caa31c, which
brings in the log handler along with the SO_REUSEADDR/SO_REUSEPORT
pairing and member initializer changes made since 18c2877b.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Copy file name to clipboardExpand all lines: README.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,7 +8,7 @@ Node.js module for interacting with the [NUClear](https://github.com/Fastcode/NU
8
8
9
9
Version 2 uses the redesigned **NUClearNet** library from [NUClear PR #190](https://github.com/Fastcode/NUClear/pull/190) (wire protocol **0x03**). It is **not** compatible with 1.x clients or NUClear builds that still use the old `NUClearNetwork` stack (protocol 0x02). Upgrade Node clients and NUClear robots together.
10
10
11
-
The vendored NUClear tree is updated via `git subtree` from the `houliston/nuclearnet-v2` branch (currently [NUClear@18c2877b](https://github.com/Fastcode/NUClear/commit/18c2877b)).
11
+
The vendored NUClear tree is updated via `git subtree` from the `houliston/nuclearnet-v2` branch (currently [NUClear@b7caa31c](https://github.com/Fastcode/NUClear/commit/b7caa31c)).
12
12
13
13
Peer join events may arrive slightly later than in 1.x because connection requires both multicast announce and a unicast CONNECT handshake.
Copy file name to clipboardExpand all lines: src/nuclear/docs/explanation/nuclearnet.md
+63-4Lines changed: 63 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -153,12 +153,46 @@ The connection is only considered "up" once both the announce path and data path
153
153
154
154
### Announce address options
155
155
156
+
The announce address determines how discovery packets are delivered.
157
+
All nodes in a mesh must agree on the same address and port.
158
+
For multi-peer discovery on one host, the address must fan out to every process bound to the shared announce port.
159
+
160
+
#### Socket binding
161
+
162
+
NUClearNet binds the announce socket to **all interfaces** (`INADDR_ANY`) by default, even when the announce address is multicast or broadcast.
163
+
This default is required for broadcast fan-out on macOS.
164
+
An explicit `bind_address` to a specific interface IP can prevent broadcast reception on macOS.
165
+
166
+
#### Reuse options
167
+
168
+
NUClearNet sets **`SO_REUSEADDR`** on all platforms and **`SO_REUSEPORT`** when the platform provides it — the two options are always paired where `SO_REUSEPORT` exists.
169
+
Platforms without `SO_REUSEPORT` use `SO_REUSEADDR` alone.
170
+
Socket setup is consistent; fan-out vs load-balance depends on the announce address and OS stack.
171
+
172
+
#### Address types and multi-peer validity
173
+
156
174
The announce address can be:
157
175
158
176
-**Multicast** (e.g., `239.226.152.162`) — the most common setup.
159
-
All nodes on the same network join the multicast group and hear each other's announcements.
160
-
-**Broadcast** (e.g., `255.255.255.255`) — works on simple LANs without multicast support.
161
-
-**Unicast** — for point-to-point setups or testing.
177
+
All nodes join the multicast group and hear each other's announcements.
178
+
Valid for multi-peer on one host on both Linux and macOS (recommended on macOS).
179
+
-**Subnet broadcast** (e.g., `192.168.1.255`) — all nodes on the subnet receive announce messages.
180
+
Valid for multi-peer on one host on both platforms (requires default `INADDR_ANY` bind on macOS).
181
+
-**Global broadcast** (`255.255.255.255`) — valid for multi-peer on one host on both platforms (noisy; requires default bind on macOS).
182
+
-**Loopback broadcast** (`127.255.255.255`) — valid for multi-peer local dev on **Linux only**.
183
+
macOS does not deliver UDP to this address locally — a macOS stack limitation, not reuse-option behavior.
184
+
-**Unicast** (e.g., `127.0.0.1`, `192.168.1.50`) — for point-to-point setups between two known peers.
185
+
Unicast does not fan out to every socket bound on the shared announce port — **invalid for multi-peer on one host** on both platforms.
Copy file name to clipboardExpand all lines: src/nuclear/docs/how-to/networking.md
+96-1Lines changed: 96 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -55,8 +55,44 @@ public:
55
55
|`name`|`string`| — | Unique name for this node on the network |
56
56
|`announce_address`|`string`|`"239.226.152.162"`| Address for node discovery announcements |
57
57
|`announce_port`|`uint16_t`|`7447`| Port for announce messages |
58
-
|`bind_address`|`string`|`""` (all) | Local interface to bind to |
58
+
|`bind_address`|`string`|`""` (all) | Local interface to bind to (see [Forming a mesh](#forming-a-mesh) — default `INADDR_ANY` is required for broadcast fan-out on macOS)|
59
59
|`mtu`|`uint16_t`|`1500`| Maximum transmission unit (fragments if larger) |
60
+
|`log_level`|`LogLevel`|`UNKNOWN` (off) | Level to log the networking internals at (see [Logging](#logging)) |
61
+
62
+
### Logging
63
+
64
+
NUClearNet logs what it is doing internally — discovery, handshakes, fragmentation, retransmission.
65
+
Set `log_level` on the `NetworkConfiguration` to turn it on:
In unicast mode, each peer announces directly to the other.
111
149
This is useful when multicast/broadcast is unavailable (e.g., across subnets or VPNs).
150
+
Unicast does **not** fan out to every socket bound on the shared announce port, so it cannot form a multi-peer mesh on one host.
151
+
152
+
### Forming a mesh
153
+
154
+
A mesh forms when all nodes share the same `announce_address` and `announce_port`.
155
+
Each node periodically sends discovery packets to that address; every peer that receives them can discover the others and complete a CONNECT handshake.
156
+
157
+
For multi-peer discovery on one machine, announce traffic must reach **every** process bound to the shared announce port.
158
+
Which addresses satisfy that depends on the announce address and OS stack, not on socket option policy.
159
+
160
+
#### Socket binding
161
+
162
+
By default, NUClearNet binds the announce socket to **all interfaces** (`INADDR_ANY`), regardless of the announce address.
163
+
This default is required for broadcast fan-out on macOS.
164
+
Setting `bind_address` to a specific interface IP can prevent broadcast reception on macOS — leave it empty unless you have a specific reason to bind to one interface.
165
+
166
+
#### Reuse options
167
+
168
+
Multiple processes on one host must bind the same UDP announce port.
169
+
NUClearNet sets **`SO_REUSEADDR`** on all platforms and **`SO_REUSEPORT`** when the platform provides it — the two options are always paired where `SO_REUSEPORT` exists.
170
+
Socket setup is consistent everywhere; what varies is which announce addresses fan out to every bound socket vs one socket.
171
+
172
+
#### Valid announce addresses
173
+
174
+
| Address | Linux | macOS |
175
+
| ------- | ----- | ----- |
176
+
|`239.226.152.162` (multicast, default) | Valid — all sockets join the group | Valid — recommended |
177
+
|`127.255.255.255` (loopback broadcast) | Valid — recommended for local dev |**Invalid** — macOS does not deliver UDP to this address locally (stack limitation) |
| Local dev, Linux | `127.255.255.255` (loopback broadcast) or multicast |
198
+
| Local dev, macOS | `239.226.152.162` (multicast) |
199
+
| Two known peers, point-to-point | Unicast to each other's IP (not multi-peer on shared port) |
200
+
201
+
#### Loopback (local development)
202
+
203
+
When running multiple NUClearNet processes on one machine, pick an announce address that fans out to every listener on the shared port (see tables above).
204
+
205
+
On Linux, `127.255.255.255` is the simplest local-dev choice when you want to avoid multicast.
206
+
On macOS, use the default multicast address — loopback broadcast is not delivered locally.
0 commit comments