Giter VIP home page Giter VIP logo

dnssd's Introduction

DNS-SD

Build Status

This library implements Multicast DNS and DNS-Based Service Discovery to provide zero-configuration operations. It lets you announce and find services in a specific link-local domain.

Usage

Create a mDNS responder

The following code creates a service with name "My Website._http._tcp.local." for the host "My Computer" which has the IP "192.168.0.123" on port "12345". The service is added to a responder.

import (
	"context"
	"github.com/brutella/dnssd"
)

cfg := dnssd.Config{
    Name:   "My Website",
    Type:   "_http._tcp",
    Domain: "local",
    Host:   "My Computer",
    IPs:    []net.IP{net.ParseIP("192.168.0.123")},
    Port:   12345,
}
sv, _ := dnssd.NewService(cfg)

In most cases you only need to specify the name, type and port of the service.

cfg := dnssd.Config{
    Name:   "My Website",
    Type:   "_http._tcp",
    Port:   12345,
}
sv, _ := dnssd.NewService(cfg)

Then you create a responder and add the service to it.

rp, _ := dnssd.NewResponder()
hdl, _ := rp.Add(sv)

ctx, cancel := context.WithCancel(context.Background())
defer cancel()

rp.Respond(ctx)

When calling Respond the responder probes for the service instance name and host name to be unqiue in the network. Once probing is finished, the service will be announced.

Update TXT records

Once a service is added to a responder, you can use the hdl to update properties.

hdl.UpdateText(map[string]string{"key1": "value1", "key2": "value2"}, rsp)

Examples

There are examples in the _cmd directory to register services, resolve service instances and to browse for service types.

Conformance

This library passes the multicast DNS tests of Apple's Bonjour Conformance Test.

TODO

  • Support hot plugging
  • Support negative responses (RFC6762 6.1)
  • Handle txt records case insensitive
  • Remove outdated services from cache regularly
  • Make sure that hostnames are FQDNs

Contact

Matthias Hochgatterer

Github: https://github.com/brutella

Twitter: https://twitter.com/brutella

License

dnssd is available under the MIT license. See the LICENSE file for more info.

dnssd's People

Contributors

brutella avatar dubo-dubon-duponey avatar erwanmas avatar jamessanford avatar lhecker avatar ripienaar avatar stapelberg avatar

Watchers

 avatar

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.