Giter Site home page Giter Site logo

go-ssdp's Introduction

SSDP library

PkgGoDev 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.

go-ssdp's People

Contributors

chadlwm avatar enen92 avatar koron avatar mattn avatar pulento avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

go-ssdp's Issues

change IP address

Hi, In the XML sent to Plex is it possible to change the URLbase for an IP address different then localhost? Telly is on a different VM.

image

support context.Context

Check list:

  • advertise.go
    • Advertise(): no need. it starts goroutines but it can be terminated with Close().
  • announce.go
    • AnnounceAlive(): no need. it will take short time.
    • AnnounceBye(): no need. it will take short time.
  • doc.go: no need
  • interface.go: no need
  • log.go: no need
  • monitor.go:
    • Start(): no need. it starts goroutines but it can be terminated with Close().
  • multicast.go: no need.
  • search.go
    • Search(): no need. it takes duration to timeout.
  • udp.go: no need.

Send bye message when closing advertiser

This is a follow-up to #14. When the advertiser starts, it automatically sends the announce message. However, when the advertiser is stopped, the bye message is not sent automatically. I‘d suggest to always send the bye message if it has not already been sent from client code when stopping the advertiser.

ssdp:byebye not sent

ssdp:byebye is not sent if called right before Close()
A workaround is to add a Sleep() call before close.
Example:

ssdpAdvertiser.Bye()
time.Sleep(100 * time.Millisecond)
ssdpAdvertiser.Close()

Error when installing

When running go get github.com/koron/go-ssdp I get the following in return.

go/src/github.com/koron/go-ssdp/monitor.go:47:20: undefined: errors.Is

Any guidance appreciated.

unable to build my project with go-ssdp v0.0.2

Hi Koron,

Thanks for your effort on this project. I tried to import this project and build my project, then got output here:

$ go build cmd/main.go 
# golang.org/x/sys/unix
../../../pkg/mod/golang.org/x/[email protected]/unix/syscall_darwin.1_13.go:25:3: //go:linkname must refer to declared function or variable
../../../pkg/mod/golang.org/x/[email protected]/unix/zsyscall_darwin_amd64.1_13.go:27:3: //go:linkname must refer to declared function or variable
../../../pkg/mod/golang.org/x/[email protected]/unix/zsyscall_darwin_amd64.1_13.go:40:3: //go:linkname must refer to declared function or variable
../../../pkg/mod/golang.org/x/[email protected]/unix/zsyscall_darwin_amd64.go:28:3: //go:linkname must refer to declared function or variable
../../../pkg/mod/golang.org/x/[email protected]/unix/zsyscall_darwin_amd64.go:43:3: //go:linkname must refer to declared function or variable
../../../pkg/mod/golang.org/x/[email protected]/unix/zsyscall_darwin_amd64.go:59:3: //go:linkname must refer to declared function or variable
../../../pkg/mod/golang.org/x/[email protected]/unix/zsyscall_darwin_amd64.go:75:3: //go:linkname must refer to declared function or variable
../../../pkg/mod/golang.org/x/[email protected]/unix/zsyscall_darwin_amd64.go:90:3: //go:linkname must refer to declared function or variable
../../../pkg/mod/golang.org/x/[email protected]/unix/zsyscall_darwin_amd64.go:105:3: //go:linkname must refer to declared function or variable
../../../pkg/mod/golang.org/x/[email protected]/unix/zsyscall_darwin_amd64.go:121:3: //go:linkname must refer to declared function or variable
../../../pkg/mod/golang.org/x/[email protected]/unix/zsyscall_darwin_amd64.go:121:3: too many errors

Just curious go-ssdp have not support to build with go 1.18 yet?

Thanks,
Yulan

Advertise messages do not have HOST: field

The missing field is causing SmartThings to ignore the advertisements from go-ssdp.. Not sure which one is not following the spec, but all the other devices on my network do include that field. only the go-ssdp responses do not. The field missing is..

HOST: 239.255.255.250:1900

Looks like the Alive messages do have the field though

"Interfaces" global variable is racy -> panics

Concurrent calls to search may cause application panics because the Interfaces variable is read while writing at https://github.com/koron/go-ssdp/blob/master/interface.go#L10

==================
WARNING: DATA RACE
Read at 0x0000025c0e10 by goroutine 108:
  github.com/koron/go-ssdp.multicastListen()
      /home/hector/go/pkg/mod/github.com/koron/[email protected]/interface.go:10 +0xde
  github.com/koron/go-ssdp.Search()
      /home/hector/go/pkg/mod/github.com/koron/[email protected]/search.go:71 +0x7c
  github.com/libp2p/go-nat.discoverUPNP_GenIGDev.func1()
      /home/hector/go/pkg/mod/github.com/libp2p/[email protected]/upnp.go:154 +0x99

Previous write at 0x0000025c0e10 by goroutine 48:
  github.com/koron/go-ssdp.multicastListen()
      /home/hector/go/pkg/mod/github.com/koron/[email protected]/interface.go:11 +0x3bf
  github.com/koron/go-ssdp.Search()
      /home/hector/go/pkg/mod/github.com/koron/[email protected]/search.go:71 +0x7c
  github.com/libp2p/go-nat.discoverUPNP_GenIGDev.func1()
      /home/hector/go/pkg/mod/github.com/libp2p/[email protected]/upnp.go:154 +0x99

Goroutine 108 (running) created at:
  github.com/libp2p/go-nat.discoverUPNP_GenIGDev()
      /home/hector/go/pkg/mod/github.com/libp2p/[email protected]/upnp.go:151 +0x7d
  github.com/libp2p/go-nat.DiscoverNATs.func1()
      /home/hector/go/pkg/mod/github.com/libp2p/[email protected]/nat.go:53 +0x14c

Goroutine 48 (running) created at:
  github.com/libp2p/go-nat.discoverUPNP_GenIGDev()
      /home/hector/go/pkg/mod/github.com/libp2p/[email protected]/upnp.go:151 +0x7d
  github.com/libp2p/go-nat.DiscoverNATs.func1()
      /home/hector/go/pkg/mod/github.com/libp2p/[email protected]/nat.go:53 +0x14c

Support for IPv6

It seems that the IPv4 address and udp4 protocol are hardcoded at the moment. This makes it impossible to run go-ssdp on a modern IPv6-enabled network. Are there any plans to support IPv6?

dynamic interfaces

デフォルトで利用する interface を動的に決定する。

#2 の修正は link-up しないインターフェースを対象に含めないようにするもの。
対象は初回にリストアップされ次回以降キャッシュされてしまうので、
以下のようなケースでは SSDP が機能しない懸念がある。

  1. LANケーブルは繋がずに電源を入れる
  2. go-ssdp を使ったプログラムが起動
  3. LANケーブルに繋ぐ

組み込み機器等では普通にありそうなシナリオで困りそう。

そこで対象となる interface を動的に決定することで、それを回避しようという算段。
interface 一覧を監視して、自動で再接続という手もありか。

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.