Local network
Funlink also works between machines: a player on a Steam Deck can offer its OFS API to RustyFunPlayer on the desktop, and a Wi-Fi stroker can offer TCode over UDP. On the local network, peers announce over two transports at once:
- DNS-SD (multicast DNS, what Bonjour and Avahi speak) as
_funlink._udp.local; - the Funlink beacon, the record as JSON in a UDP datagram on port 37420.
Hubs listen on both and merge what they hear. The specification has the wire format; the libraries implement both transports without extra dependencies, and devices without a library follow Announce a Wi-Fi device.
Both sides opt in: a peer only announces on the network, and a hub only listens there, when you turn lan on.
Announce on the network
Turn on lan. Loopback announcing continues as before; the library also writes a network copy of the record in which every endpoint host is 0.0.0.0. Hubs replace that host with the address the packet came from.
import { announce } from "funlink";
const funlink = announce(
{
id: "my-player",
name: "My Player",
services: [{ protocol: "ofs-ws", endpoint: "ws://127.0.0.1:8080/ofs" }],
},
{ lan: true },
);
#![allow(unused)]
fn main() {
use funlink::{Announcement, Announcer, Protocol};
let peer = Announcer::builder(
Announcement::new("my-player", "My Player").service(Protocol::OfsWs, "ws://127.0.0.1:8080/ofs"),
)
.lan(true)
.start()?;
}
await using var peer = FunlinkPeer.Announce(
new Announcement("my-player", "My Player",
[new Service(Protocol.OfsWs, "ws://127.0.0.1:8080/ofs")]),
options: new AnnounceOptions { Lan = true });
try (var funlink = Funlink.announcer(Announcement.of("my-player", "My Player",
Service.of(Protocol.OFS_WS, "ws://127.0.0.1:8080/ofs"))).lan(true).start()) {
// Run your app.
}
The C library always announces on the local network, over the beacon and DNS-SD:
funlink.addService("tcode-udp", 8000);
funlink.begin("sr6-a41c", "SR6", "1.0.0"); // both transports
funlink.begin("sr6-a41c", "SR6", "1.0.0", FUNLINK_TRANSPORT_BEACON); // beacon only, e.g. to keep ESPmDNS
funlink.lan = true
funlink.lan_hosts = ["192.168.2.40"] # optional: hubs on other subnets
Set both before the node enters the tree. Godot cannot share a UDP port, so the add-on never binds port 37420 and answers no queries; hubs find the game by its next announce, within 5 seconds. It announces over the beacon only, not over DNS-SD.
Your service must then listen on the network too, for example on 0.0.0.0:8080, not only on 127.0.0.1. Anyone on the network can connect to it, so protect it as such.
The network record leaves out the icon and services whose endpoints are not network sockets (unix, serial), and carries ext only in the beacon. It must fit in 1200 bytes, each DNS TXT string in 255 bytes, and features must not contain commas; otherwise announcing fails with invalid_announce. Hubs on other machines answer with a status, which appears in the announcer’s list of hubs like a loopback hub’s answer.
Find peers on the network
const hub = await startHub({
name: "My Player",
supports: ["tcode-udp", "ofs-ws"],
lan: true,
queryHosts: ["192.168.2.20"], // optional: peers on another subnet
onEvent: (event) => { /* event.peer.address is set for network peers */ },
});
hub.search(); // ask again now, for a "Search" button
#![allow(unused)]
fn main() {
let hub = Hub::builder("My Player")
.supports([Protocol::TcodeUdp, Protocol::OfsWs])
.lan(true)
.query_hosts(["192.168.2.20".parse()?]) // optional: peers on another subnet
.start(|event| { /* event.peer().address is Some for network peers */ })?;
hub.search();
}
await using var hub = await FunlinkHub.StartAsync(
new HubOptions("My Player", [Protocol.TcodeUdp, Protocol.OfsWs])
{
Lan = true,
QueryHosts = [IPAddress.Parse("192.168.2.20")], // optional: peers on another subnet
},
e => { /* e.Peer.Address is set for network peers */ });
hub.Search();
var options = HubOptions.of("My Player", Protocol.TCODE_UDP, Protocol.OFS_WS)
.withLan(true)
.withQueryHosts(InetAddress.getByName("192.168.2.20")); // optional: peers on another subnet
try (var hub = Funlink.hub(options, event -> { /* peer().address() is present for network peers */ })) {
hub.search();
}
The C library is a peer only: hubs run on a computer. Use one of the four libraries there.
The Godot add-on is a peer only. A Godot .NET project can use the C# library, which also runs hubs.
A network peer’s address is the IP its packets came from, and the endpoints in its services already use that address. Loopback peers have no address. Events, expiry after 15 seconds and setState work as for loopback peers.
What the library checks for you: only loopback, private, link-local and unique-local source addresses count; endpoints always point at the sender; at most 64 network peers and 8 per address; a peer on this machine that also announces over loopback appears once, as a loopback peer.
What your hub must do: ask before connecting, show the peer’s address in the prompt, and remember Always connect and Never ask per address and id. Do not act on ext data that names files, programs or processes; it describes another machine. A peer with Wi-Fi and Ethernet may appear once per address; offer it once.
Firewalls
The network transports need UDP ports 5353 (DNS-SD) and 37420 (beacon) open for incoming packets on the hub’s machine:
- Linux: open both ports, for example with
networking.firewall.allowedUDPPortson NixOS. - macOS: the first start asks for permission to find devices on the local network. A bundled app needs
NSLocalNetworkUsageDescriptionand_funlink._udpinNSBonjourServicesin itsInfo.plist. - Windows: the first start shows a firewall prompt; an installer can add the rule instead.
Guest networks and some routers block traffic between devices. Then only queryHosts with the peer’s address can reach it, if anything does.
Testing
avahi-browse -rt _funlink._udp (Linux) or dns-sd -B _funlink._udp (macOS) lists network peers. Set FUNLINK_LAN_PORT to move the beacon to another port, so experiments do not reach the hubs on your network.