Skyost / Bonsoir

A Zeroconf library that allows you to discover network services and to broadcast your own. Based on Apple Bonjour and Android NSD.
http://bonsoir.skyost.eu/
Other
100 stars 43 forks source link

IP Address Return #80

Closed francisyu1012 closed 5 months ago

francisyu1012 commented 5 months ago

Describe the bug When running with Android, I am able to see the the host as an IP address:

flutter (12628): Service resolved : {service.name: zz0138, service.type: _msb._tcp, service.port: 1505, service.attributes: {}, service.host: 192.168.4.126}

However in IOS and Windows, the response only gives me the hostname flutter: Service resolved : {service.name: zz0077, service.type: _msb._tcp, service.port: 1505, service.attributes: {}, service.host: zz0077.local.}

Why the discrepancy and Is it possible to get the IP directly from this service?

To Reproduce Steps to reproduce the behavior: Built in IOS, Android and Windows using this code block

// If you want to listen to the discovery :
discovery.eventStream!.listen((event) { // `eventStream` is not null as the discovery instance is "ready" !
  if (event.type == BonsoirDiscoveryEventType.discoveryServiceFound) {
    print('Service found : ${event.service?.toJson()}');
    event.service!.resolve(discovery.serviceResolver); // Should be called when the user wants to connect to this service.
  } else if (event.type == BonsoirDiscoveryEventType.discoveryServiceResolved) {
    print('Service resolved : ${event.service?.toJson()}');
  } else if (event.type == BonsoirDiscoveryEventType.discoveryServiceLost) {
    print('Service lost : ${event.service?.toJson()}');
  }
});

// Start the discovery **after** listening to discovery events :
await discovery.start();

Expected behavior A clear and concise description of what you expected to happen.

Desktop (please complete the following information):

Smartphone (please complete the following information):

Skyost commented 5 months ago

Hey,

Why do you absolutely want the IP address instead of the hostname ? You're not using 140.82.121.4 to go on github.com, aren't you ?

francisyu1012 commented 5 months ago

It was more of a curiosity question regarding the discrepancy between scanning with Android vs. IOS and WIndows... Given the shift of using HTTPS which does not allow direct connection with IP's and .local, we will probably just use this to scan if the devices are in the same LAN. Thanks!

Skyost commented 5 months ago

It was more of a curiosity question regarding the discrepancy between scanning with Android vs. IOS and WIndows...

Understood. On Darwin platforms, Bonsoir rely on NWBrowser / DNSServiceResolve which only gives you the hostname. It should be possible to find the IP address using gethostbyname or getaddrinfo tho, as stated here.