This commit is contained in:
Asim
2016-04-29 23:53:34 +01:00
parent feb0629af0
commit 3590a367d8
7 changed files with 167 additions and 17 deletions

1
examples/client/.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
client

17
examples/client/README.md Normal file
View File

@@ -0,0 +1,17 @@
# client
[Run the service first](../service)
Then, compile + run:
```
go build
./client
```
Check out other services:
```
./client <service-tag>
./client _foobarbaz._tcp
```

41
examples/client/main.go Normal file
View File

@@ -0,0 +1,41 @@
package main
import (
"fmt"
"os"
"os/signal"
"github.com/micro/mdns"
)
func main() {
serviceTag := "_foobar._tcp"
if len(os.Args) > 1 {
serviceTag = os.Args[1]
}
// Make a channel for results and start listening
entriesCh := make(chan *mdns.ServiceEntry, 8)
defer close(entriesCh)
go func() {
for entry := range entriesCh {
fmt.Printf("Got new entry: %v\n", entry)
}
}()
// Start the lookups
err := mdns.Lookup(serviceTag, entriesCh)
if err != nil {
fmt.Println(err)
}
wait()
}
func wait() {
ch := make(chan os.Signal)
signal.Notify(ch, os.Interrupt, os.Kill)
<-ch
}