ssdp

package module
v0.0.0-...-ae8e7a0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 27, 2013 License: MIT Imports: 10 Imported by: 5

README

go-ssdp

A library that implements the client side of SSDP (Simple Service Discovery Protocol).

Please see godoc.org for a detailed API description.

Usage

Get Device for devices on the network
package main

import (
	"github.com/bcurren/go-ssdp"
	"time"
	"fmt"
)

func main() {
	devices, err := ssdp.SearchForDevices("upnp:rootdevice", 3*time.Second)
	if err != nil {
		return
	}

	for _, device := range devices {
		fmt.Println(device.ModelName)
	}
}
Get Responses for Search on the network
package main

import (
	"github.com/bcurren/go-ssdp"
	"time"
	"fmt"
)

func main() {
	responses, err := ssdp.Search("upnp:rootdevice", 3*time.Second)
	if err != nil {
		return
	}

	for _, response := range responses {
		// Do something with the response you discover
		fmt.Println(response)
	}
}

How to contribute

  • Fork
  • Write tests and code
  • Run go fmt
  • Submit a pull request

Documentation

Overview

SSDP (Simple Service Discovery Protocol) package provides an implementation of the SSDP specification.

Index

Constants

View Source
const (
	// The port for SSDP discovery
	Port = 1900

	// The IP for SSDP broadcast
	BroadcastIP = "239.255.255.250"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Device

type Device struct {
	SpecVersion      SpecVersion `xml:"specVersion"`
	URLBase          string      `xml:"URLBase"`
	DeviceType       string      `xml:"device>deviceType"`
	FriendlyName     string      `xml:"device>friendlyName"`
	Manufacturer     string      `xml:"device>manufacturer"`
	ManufacturerURL  string      `xml:"device>manufacturerURL"`
	ModelDescription string      `xml:"device>modelDescription"`
	ModelName        string      `xml:"device>modelName"`
	ModelNumber      string      `xml:"device>modelNumber"`
	ModelURL         string      `xml:"device>modelURL"`
	SerialNumber     string      `xml:"device>serialNumber"`
	UDN              string      `xml:"device>UDN"`
	UPC              string      `xml:"device>UPC"`
	PresentationURL  string      `xml:"device>presentationURL"`
	Icons            []Icon      `xml:"device>iconList>icon"`
}

func SearchForDevices

func SearchForDevices(st string, mx time.Duration) ([]Device, error)

type Icon

type Icon struct {
	MIMEType string `xml:"mimetype"`
	Width    int    `xml:"width"`
	Height   int    `xml:"height"`
	Depth    int    `xml:"depth"`
	URL      string `xml:"url"`
}

type SearchResponse

type SearchResponse struct {
	Control      string
	Server       string
	ST           string
	Ext          string
	USN          string
	Location     *url.URL
	Date         time.Time
	ResponseAddr *net.UDPAddr
}

The search response from a device implementing SSDP.

func Search(st string, mx time.Duration) ([]SearchResponse, error)

Search the network for SSDP devices using the given search string and duration to discover new devices. This function will return an array of SearchReponses discovered.

type SpecVersion

type SpecVersion struct {
	Major int `xml:"major"`
	Minor int `xml:"minor"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL