# README
SSDP library
Based on https://tools.ietf.org/html/draft-cai-ssdp-v1-03.
Examples
There are tiny snippets for example. See also examples/ directory for working examples.
Respond to search
import "github.com/koron/go-ssdp"
ad, err := ssdp.Advertise(
"my:device", // send as "ST"
"unique:id", // send as "USN"
"http://192.168.0.1:57086/foo.xml", // send as "LOCATION"
"go-ssdp sample", // send as "SERVER"
1800) // send as "maxAge" in "CACHE-CONTROL"
if err != nil {
panic(err)
}
// run Advertiser infinitely.
quit := make(chan bool)
<-quit
Send alive periodically
import "time"
aliveTick := time.Tick(300 * time.Second)
for {
select {
case <-aliveTick:
ad.Alive()
}
}
Send bye when quiting
import (
"os"
"os/signal"
)
// to detect CTRL-C is pressed.
quit := make(chan os.Signal, 1)
signal.Notify(quit, os.Interrupt)
loop:
for {
select {
case <-aliveTick:
ad.Alive()
case <-quit:
break loop
}
}
// send/multicast "byebye" message.
ad.Bye()
// teminate Advertiser.
ad.Close()
Limitate interfaces to multicast
go-ssdp will send multicast messages to all IPv4 interfaces as default. When you want to limitate interfaces, see below snippet.
import (
"github.com/koron/go-ssdp"
"net"
)
en0, err := net.InterfaceByName("en0")
if err != nil {
panic(err)
}
ssdp.Interfaces = []net.Interface{*en0}
go-ssdp will send multicast message only "en0" after this.
# Packages
No description provided by the author
# Functions
Advertise starts advertisement of service.
AdvertiseHost returns as Option that add HOST header to response for M-SEARCH requests.
AnnounceAlive sends ssdp:alive message.
AnnounceBye sends ssdp:byebye message.
OnlySystemInterface returns as Option that using only a system assigned multicast interface.
Search searches services by SSDP.
SetMulticastRecvAddrIPv4 updates multicast address where to receive packets.
SetMulticastSendAddrIPv4 updates a UDP address to send multicast packets.
TTL returns as Option that set TTL for multicast packets.
# Constants
All is a search type to search all services and devices.
RootDevice is a search type to search UPnP root devices.
# Variables
Interfaces specify target interfaces to multicast.
Logger is default logger for SSDP module.
# Structs
Advertiser is a server to advertise a service.
AliveMessage represents SSDP's ssdp:alive message.
ByeMessage represents SSDP's ssdp:byebye message.
Monitor monitors SSDP's alive and byebye messages.
SearchMessage represents SSDP's ssdp:discover message.
Service is discovered service.
# Interfaces
LocationProvider provides address for Location header which can be reached from "from" address network.
Option is option set for SSDP API.
# Type aliases
AliveHandler is handler of Alive message.
ByeHandler is handler of Bye message.
LocationProviderFunc type is an adapter to allow the use of ordinary functions are location providers.
SearchHandler is handler of Search message.