oleksandr / bonjour Goto Github PK
View Code? Open in Web Editor NEWmDNS/DNS-SD (also known as Apple Bonjour) library for Go (in pure Go)
License: MIT License
mDNS/DNS-SD (also known as Apple Bonjour) library for Go (in pure Go)
License: MIT License
I just noticed that in the examples, if there are no results, the channel is never closed and the goroutine never ends. You can check it out with this script
package main
import (
"github.com/oleksandr/bonjour"
"log"
"os"
"runtime"
// "runtime/pprof"
"time"
)
func main() {
for {
resolver, err := bonjour.NewResolver(nil)
if err != nil {
log.Println("Failed to initialize resolver:", err.Error())
os.Exit(1)
}
results := make(chan *bonjour.ServiceEntry)
go func(results chan *bonjour.ServiceEntry, exitCh chan<- bool) {
for e := range results {
log.Printf("%s", e.Instance)
exitCh <- true
time.Sleep(1e9)
}
}(results, resolver.Exit)
err = resolver.Browse("_foobar._tcp", "local.", results)
if err != nil {
log.Println("Failed to browse:", err.Error())
}
log.Println("Stack info")
log.Println(runtime.NumGoroutine())
time.Sleep(1e9)
// close(results)
}
}
Of course it's not a bug, just a documentation issue
enviroment:
if close the Wifi, with only the use ethernet connected, every is OK
if Wifi is connected to another network, no result return.
Hey @oleksandr,
first thank you for creating this package :)
I've got a service running somewhere that is perfectly detected once I run my code and if I restart said service it gets detected again, but without an IP:
See this example:
https://gist.github.com/stroborobo/5cc5db74af28706f8e7e
&{{DoomBox\ Uno _mpd._tcp local } raspberrypi.local. 6600 [] 120 192.168.0.63 fe80::aea1:3a28:a896:1e64}
&{{DoomBox\ Uno _mpd._tcp local } raspberrypi.local. 6600 [] 4500 <nil> <nil>}
Is that my bad? This is the first time I'm building something around bonjour, so I hope I didn't misunderstand something.
Hello!
I'm not sure if this is an issue with the lib itself or if i'm doing something wrong/misunderstanding.
I am, with this library, registering two services with the same name on two different computers. Then, again with this library, i am doing a resolver.Lookup
call with the following code:
resolver, err := bonjour.NewResolver(nil)
if err != nil {
log.Println("Failed to initialize resolver:", err.Error())
os.Exit(1)
}
results := make(chan *bonjour.ServiceEntry)
go func(results chan *bonjour.ServiceEntry, exitCh chan<- bool) {
discover := true
for discover {
select {
case res := <-results:
log.Printf("Found service: %s, %s", res.Instance, res.Text)
case <-time.After(time.Second * time.Duration(timeout)):
log.Print("ServiceDiscovery timed out")
exitCh <- true
discover = false
}
}
}(results, resolver.Exit)
err = resolver.Lookup("iobox", "_iobox._tcp", "", results)
if err != nil {
log.Println("Failed to lookup:", err.Error())
}
However i only get one result printed before the timeout(currently set to 30 seconds). I wish to list all devices with an iobox-service. Is there something wrong with my code, or is this not supported?
I'm very new to Go so maybe i'm doing something wrong in this part:
for discover {
select {
...
discover = false
}
}
I feel that maybe this isn't the right way to do it. I wish to continue receiving data from the channels until i've timed out.
Does anyone know why it isn't working?
Kind regards,
Is this project dead?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.