All Projects → koron → go-ssdp

koron / go-ssdp

Licence: MIT license
SSDP library

Programming Languages

go
31211 projects - #10 most used programming language
Makefile
30231 projects

Labels

Projects that are alternatives of or similar to go-ssdp

UPnP Generic
A simple library that implements port mappings to router using UPnP SSDP for Arduino boards, running on nRF52, SAMD21/SAMD51, STM32F/L/H/G/WB/MP1, Teensy, RP2040-based boards, WT32_ETH01, Portenta_H7, etc. besides ESP8266/ESP32, using ESP WiFi, WiFiNINA, Ethernet W5x00, ESP8266/ESP32 AT-command WiFi, Portenta_H7 Murata WiFi or Vision-shield Ethe…
Stars: ✭ 14 (-83.53%)
Mutual labels:  ssdp
bigfoot
🐾 Quickly connect IoT devices with a great UX
Stars: ✭ 55 (-35.29%)
Mutual labels:  ssdp
ssdp-client
The most lightweight asynchronous Java SSDP (Simple Service Discovery Protocol) Client
Stars: ✭ 46 (-45.88%)
Mutual labels:  ssdp
ytcast
cast YouTube videos to your smart TV from command-line
Stars: ✭ 674 (+692.94%)
Mutual labels:  ssdp
ssdp
Python asyncio library for Simple Service Discovery Protocol (SSDP).
Stars: ✭ 25 (-70.59%)
Mutual labels:  ssdp
ssdp-responder
SSDP responder for Linux, InternetGatewayDevice icon in Windows :)
Stars: ✭ 41 (-51.76%)
Mutual labels:  ssdp

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.

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.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].