示例#1
0
文件: main.go 项目: Gaboose/examples
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
文件: mdns.go 项目: Gaboose/go-pubsub
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
}