Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/koron/go-ssdp
SSDP library
https://github.com/koron/go-ssdp
go golang ssdp
Last synced: 22 days ago
JSON representation
SSDP library
- Host: GitHub
- URL: https://github.com/koron/go-ssdp
- Owner: koron
- License: mit
- Created: 2016-05-23T08:11:54.000Z (over 8 years ago)
- Default Branch: main
- Last Pushed: 2024-04-23T19:01:54.000Z (7 months ago)
- Last Synced: 2024-10-23T05:28:59.071Z (28 days ago)
- Topics: go, golang, ssdp
- Language: Go
- Homepage:
- Size: 146 KB
- Stars: 110
- Watchers: 8
- Forks: 27
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# SSDP library
[![PkgGoDev](https://pkg.go.dev/badge/github.com/koron-go/go-ssdp)](https://pkg.go.dev/github.com/koron-go/go-ssdp)
[![Actions/Go](https://github.com/koron/go-ssdp/workflows/Go/badge.svg)](https://github.com/koron/go-ssdp/actions?query=workflow%3AGo)
[![Go Report Card](https://goreportcard.com/badge/github.com/koron/go-ssdp)](https://goreportcard.com/report/github.com/koron/go-ssdp)Based on .
## Examples
There are tiny snippets for example. See also examples/ directory for working
examples.### Respond to search
```go
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
```go
import "time"aliveTick := time.Tick(300 * time.Second)
for {
select {
case <-aliveTick:
ad.Alive()
}
}
```### Send bye when quiting
```go
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.```go
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.