Step 6 of 8
Network Synchronization
One timeline, several machines, under 5 ms apart. Namespace: OwnaudioNET
Same idea as the master clock, stretched over a LAN. One device is the server and broadcasts its clock; every client follows it and plays its own files against that timeline. Play, pause, stop and seek all come from the server — the clients just obey.
Clock distribution is UDP broadcast. Create and start an AudioMixer before starting the server or client — it is the mixer's clock that gets shared.
Server Mode
The server device broadcasts its MasterClock timeline to all clients. The server controls play, pause, stop, and seek — clients follow automatically.
// Prerequisites: Initialize + Start + Create AudioMixer
await OwnaudioNet.InitializeAsync();
OwnaudioNet.Start();
var mixer = new AudioMixer(OwnaudioNet.Engine!.UnderlyingEngine);
mixer.Start();
// Start server — broadcasts MasterClock to LAN
await OwnaudioNet.StartNetworkSyncServerAsync(port: 9876, useLocalTimeOnly: true);
// From this point, control playback normally:
mixer.Seek(0);
var track = new FileSource("backing.mp3");
track.AttachToClock(mixer.MasterClock);
track.Play();
mixer.AddSource(track);
// Stop network sync when done
OwnaudioNet.StopNetworkSync();Client Mode
Clients synchronize their MasterClock to the server's timeline. Each client plays its own audio files, kept in sync by the shared clock.
await OwnaudioNet.InitializeAsync();
OwnaudioNet.Start();
var mixer = new AudioMixer(OwnaudioNet.Engine!.UnderlyingEngine);
mixer.Start();
// Connect to server (null = UDP auto-discovery)
await OwnaudioNet.StartNetworkSyncClientAsync(
serverAddress: "192.168.1.100", // or null for auto-discovery
port: 9876,
allowOfflinePlayback: true); // continue if server disconnects
// Load client's own audio — clock is controlled by server
var clientTrack = new FileSource("client-audio.mp3");
clientTrack.AttachToClock(mixer.MasterClock);
clientTrack.Play();
mixer.AddSource(clientTrack);Stop Network Sync
OwnaudioNet.StopNetworkSync();Events
OwnaudioNet.NetworkSyncConnectionChanged += (_, e) =>
{
Console.WriteLine($"Network sync state: {e.OldState} → {e.NewState}");
};Use Cases
API Parameters
StartNetworkSyncServerAsync
| Parameter | Type | Default | Description |
|---|---|---|---|
port | int | 9876 | UDP port for clock broadcast. |
useLocalTimeOnly | bool | true | Use local time sync only (no internet NTP required). |
StartNetworkSyncClientAsync
| Parameter | Type | Default | Description |
|---|---|---|---|
serverAddress | string? | null | Server IP address. null = UDP broadcast auto-discovery. |
port | int | 9876 | UDP port to listen on. |
allowOfflinePlayback | bool | true | Continue playback if server connection drops. |