Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot discover service - how to debug? #34

Open
cecchisandrone opened this issue Mar 30, 2018 · 1 comment
Open

Cannot discover service - how to debug? #34

cecchisandrone opened this issue Mar 30, 2018 · 1 comment

Comments

@cecchisandrone
Copy link

cecchisandrone commented Mar 30, 2018

I'm exposing a service using Python zeroconf library but I'm not able to discover it in the client written in Go with this library. I'm able to discover the Python service using avahi-browse on Linux, Bonjour Browser for Windows and Discovery for iOS. I've tried to run it on the same machine or on different machines (Linux, Windows), no way. Do you have any hint to debug this issue?
This is the source code I written:

Server:

import logging
import socket
import sys
from time import sleep
import netifaces as ni

from zeroconf import ServiceInfo, Zeroconf

if __name__ == '__main__':
    logging.basicConfig(level=logging.DEBUG)
    if len(sys.argv) > 1:
        assert sys.argv[1:] == ['--debug']
        logging.getLogger('zeroconf').setLevel(logging.DEBUG)
    
    desc = {'path': '/~paulsm/'}

    info = ServiceInfo("_http._tcp.local.",
                       "A web server._http._tcp.local.",
                       socket.inet_aton("192.168.1.101"), 80, 1,10,
                       desc, "webserver.local.")

    zeroconf = Zeroconf()
    print("Registration of a service, press Ctrl-C to exit...")
    zeroconf.register_service(info)
    try:
        while True:
            sleep(0.1)
    except KeyboardInterrupt:
        pass
    finally:
        print("Unregistering...")
        zeroconf.unregister_service(info)
        zeroconf.close()

Client:

package main

import (
	"context"
	"flag"
	"log"
	"time"
	"fmt"
	"github.com/grandcat/zeroconf"
)

func main() {
	// Discover all services on the network (e.g. _workstation._tcp)
	resolver, err := zeroconf.NewResolver(nil)
	if err != nil {
		log.Fatalln("Failed to initialize resolver:", err.Error())
	}

	entries := make(chan *zeroconf.ServiceEntry)
	go func(results <-chan *zeroconf.ServiceEntry) {
		for entry := range results {
			str := fmt.Sprintf("Service: %s - Text: %s - Address: %s - Hostname: %s - Domain: %s", entry.Service, entry.Text, entry.AddrIPv4, entry.HostName, entry.Domain)
			log.Println(str)
		}
		log.Println("No more entries.")
	}(entries)

	ctx, cancel := context.WithTimeout(context.Background(), time.Second*15)
	defer cancel()
	err = resolver.Browse(ctx, "_http._tcp", "local.", entries)
	if err != nil {
		log.Fatalln("Failed to browse:", err.Error())
	}
	<-ctx.Done()
}

Thanks for your help.

@bbusse
Copy link

bbusse commented Aug 10, 2022

I can confirm that this is a problem with the NSEC record. Leaving it out completely makes the discovery with github.com/grandcat/zeroconf work. But as outlined above probably an issue with python-zeroconf

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants