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

Not discovering services on my local network #9

Open
capJavert opened this issue Jan 17, 2022 · 9 comments
Open

Not discovering services on my local network #9

capJavert opened this issue Jan 17, 2022 · 9 comments

Comments

@capJavert
Copy link

I have the simple setup from the README.

Service.js:

import Bonjour from 'bonjour-service'

// some code to get my http server up and running

const instance = new Bonjour()

instance.publish({ name: 'My Web Server', type: 'http', port: 3000 })

Client.js:

import Bonjour from 'bonjour-service'

instance.find({ type: 'http' }, function (service) {
  console.log('Found an HTTP server:', service) // this never triggers
})

When I publish and search services on the same computer (i am on macOS 12.1) they are discovered. But when I run the above code on two different machines eg. One computer is running Service.js and another one is running Client.js the find callback never triggers and no services are found.

I can confirm that my HTTP server is visible if I manually input the computer address and go for example to the GET /api endpoint on another computer so they definitely see each other.

Any tips on debugging this?

@capJavert
Copy link
Author

After additional testing I found out that my service will be discovered if the up event happens while browser is searching for services eg:

  1. I start the search with bonjour.find
  2. I publish my service with bonjour.publish
  3. browser finds the service eg. up callback is triggered

If the publish happens before search is initiated the service never gets discovered.

@mdidon
Copy link
Member

mdidon commented Jan 26, 2022

Hi @capJavert, out of interest, if you restart both machines then start Service.js followed by Client.js does it work?

@capJavert
Copy link
Author

Nope

@mdidon
Copy link
Member

mdidon commented Jan 27, 2022

Interesting, we've been unable to replicate this issue across two Macs on a network.
We personally use the publish then find method in another project, cross platform with out any issue so I'm wondering if this is a setup specific issue.

I'll leave this open for now and update if we find anything.
Thanks

@capJavert
Copy link
Author

If you need any more info from me or you have questions about the setup please do tell. I am open to dig into this.

@hrueger
Copy link

hrueger commented May 19, 2022

I just had a similar problem: My Windows PC would detect devices on the network (Blackmagic ATEMs and HyperDecks) if I disconnect those devices from the network and reconnect them or if I repower them. However, if I just start the bonjour browser with the devices already running, they would not be found.

Strangely, I could solve this problem by restarting the Windows machine... I have no idea what causes this ;-)

@eclazi
Copy link

eclazi commented Jul 21, 2023

@capJavert did you manage to resolve this?

@capJavert
Copy link
Author

@eclazi nope, I created my own protocol over thin UDP/TCP implementation. Using it for my app for quite some time.

@joeltroughton
Copy link

joeltroughton commented Apr 28, 2024

I'm running into this issue too: Devices announcing themselves on the network whilst the bonjour browser is running are picked up, but go undetected otherwise.

I did some digging in Wireshark to see if the expected traffic was being sent, and found none when monitoring the expected network interface (Ethernet). However, when monitoring a different interface (eg, vEthernet for WSL, or "Loopback Pseudo-Interface"), I can see the MDNS queries going out.

It seems the selection of the correct interface, or the broadcasting to multiple interfaces isn't working as expected. In multicast-dns I see the same behaviour (perhaps Node-related?), but there is an ability to force the interface, which makes things work more predictably. My minimum example code for testing here:

import { Bonjour } from 'bonjour-service';
import os from 'os';

var networkInterfaces = os.networkInterfaces();
console.log(networkInterfaces);

const bonjourInstance = new Bonjour({});

console.log("Starting network discovery");
let browser = bonjourInstance.find({ type: 'minismu', protocol: 'tcp' });

browser.on('up', service => {
  console.log('Device up:', service);
});

browser.on('down', service => {
  console.log('Device down:', service);
});

browser.on('error', err => {
  console.error('Error occurred:', err);
});

browser.start();

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

5 participants