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",
"unique:id",
"http://192.168.0.1:57086/foo.xml",
"go-ssdp sample",
1800)
if err != nil {
panic(err)
}
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"
)
quit := make(chan os.Signal, 1)
signal.Notify(quit, os.Interrupt)
loop:
for {
select {
case <-aliveTick:
ad.Alive()
case <-quit:
break loop
}
}
ad.Bye()
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.