Пример #1
0
func lookup(tag string) {
	// 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
	mdns.Lookup(tag, entriesCh)
	close(entriesCh)
}
Пример #2
0
func LookupMDNS() []*gway.PeerInfo {
	// Collect channel messages to a slice
	prs := []*gway.PeerInfo{}
	ch := make(chan *mdns.ServiceEntry, 4)
	go func() {
		for e := range ch {
			p := &gway.PeerInfo{
				ID:     e.Info,
				MAddrs: MultiaddrsFromServiceEntry(e),
			}
			prs = append(prs, p)
		}
	}()

	// Start the lookup
	mdns.Lookup(ServiceTag, ch)
	close(ch)
	return prs
}