Created
January 30, 2014 00:08
-
-
Save armon/8699965 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"github.com/armon/mdns" | |
"os" | |
"time" | |
) | |
func main() { | |
// Setup our service export | |
host, _ := os.Hostname() | |
service := &mdns.MDNSService{ | |
Instance: host, | |
Service: "_foobar._tcp", | |
Addr: []byte{127, 0, 0, 1}, | |
Port: 8000, | |
Info: "My awesome service", | |
} | |
service.Init() | |
// Create the mDNS server, defer shutdown | |
server, _ := mdns.NewServer(&mdns.Config{Zone: service}) | |
defer server.Shutdown() | |
// Make a channel for results and start listening | |
entriesCh := make(chan *mdns.ServiceEntry, 4) | |
go func() { | |
for entry := range entriesCh { | |
fmt.Printf("Got new entry: %v\n", entry) | |
} | |
}() | |
// Start the lookup | |
for { | |
fmt.Printf("Starting lookup...\n") | |
mdns.Lookup("_foobar._tcp", entriesCh) | |
time.Sleep(5 * time.Second) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment