This example demonstrates how to create a simple Sendspin streaming server that broadcasts a test tone to connected players.
- Creates a Sendspin server that streams a 440Hz test tone
- Listens for WebSocket connections from players
- Broadcasts synchronized audio to all connected clients
- Supports mDNS service advertisement for easy discovery
- Handles multiple clients with different codec preferences
cd examples/basic-server
go buildStart server with defaults (192kHz/24-bit stereo):
./basic-serverStart on a different port:
./basic-server -port 9000Configure sample rate and channels:
./basic-server -rate 48000 -channels 2Disable mDNS:
./basic-server -mdns=false-port- Server port (default: 8927)-name- Server name (default: "Basic Server")-rate- Sample rate in Hz (default: 192000)-channels- Number of channels (default: 2)-mdns- Enable mDNS advertisement (default: true)
- Simple setup - Just create a source and start the server
- Test tone generation - Built-in test tone for easy testing
- Automatic client handling - Clients are managed automatically
- Multi-codec support - Automatically negotiates best codec per client
- mDNS discovery - Clients can find the server automatically
// Create audio source (440Hz test tone)
source := sendspin.NewTestTone(192000, 2)
// Create and start server
config := sendspin.ServerConfig{
Port: 8927,
Name: "My Server",
Source: source,
EnableMDNS: true,
}
server, _ := sendspin.NewServer(config)
server.Start()Start the server:
./basic-serverIn another terminal, connect a player:
cd ../..
go run . -server localhost:8927You should hear a 440Hz tone (A4 note) playing.
- See
examples/custom-source/for implementing custom audio sources (files, streams, etc.) - Check out the server CLI (
cmd/sendspin-server/) for a full-featured server with TUI - Modify the test tone frequency or add multiple frequencies for testing