status-go/vendor/github.com/koron/go-ssdp
Richard Ramos b1a6607dbb chore: upgrade libp2p 2023-05-30 10:49:52 -04:00
..
internal chore: upgrade libp2p 2023-05-30 10:49:52 -04:00
.gitignore chore: bump go-waku (#2404) 2021-10-19 09:43:41 -04:00
LICENSE
Makefile chore: upgrade libp2p 2023-05-30 10:49:52 -04:00
README.md chore: bump go-waku (#2404) 2021-10-19 09:43:41 -04:00
advertise.go chore: upgrade libp2p 2023-05-30 10:49:52 -04:00
announce.go chore: upgrade libp2p 2023-05-30 10:49:52 -04:00
doc.go chore: upgrade libp2p 2023-05-30 10:49:52 -04:00
location.go chore: upgrade libp2p 2023-05-30 10:49:52 -04:00
monitor.go chore: upgrade libp2p 2023-05-30 10:49:52 -04:00
search.go chore: upgrade libp2p 2023-05-30 10:49:52 -04:00
ssdp.go chore: upgrade libp2p 2023-05-30 10:49:52 -04:00
staticcheck.conf chore: bump go-waku (#2404) 2021-10-19 09:43:41 -04:00

README.md

SSDP library

GoDoc Actions/Go Go Report Card

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.

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.