Nimrodda / flutter_nsd

A Flutter plugin that enables Network Service Discovery (mDNS) on various platforms via their native APIs.
Apache License 2.0
34 stars 8 forks source link

Some windows hosts cannot resolve hostnames returned by MDNS #19

Closed jnstahl closed 3 years ago

jnstahl commented 3 years ago

the current Windows implementation returns hostnames, such as 'Android-5.local' when provided by the MDNS query results. However some windows hosts do not have the ability to resolve such a hostname and to establish a connection (apparently this ability relies on 3rd party packages such as Bonjour being installed).

Suggested fix:

jnstahl commented 3 years ago

val hostname = this?.host?.canonicalHostName <==== canonicalHostName will return either IP address or hostname on the android implementation

Nimrodda commented 3 years ago

the current Windows implementation returns hostnames, such as 'Android-5.local' when provided by the MDNS query results. However some windows hosts do not have the ability to resolve such a hostname and to establish a connection (apparently this ability relies on 3rd party packages such as Bonjour being installed).

Suggested fix:

  • short-term: Windows implementation will always return an IP address string for hostname
  • long-term: the NsdServiceInfo object can be expanded to include:

    • ipv4
    • ipv6 in addition to hostname and port

Sounds like a plan 👍

val hostname = this?.host?.canonicalHostName <==== canonicalHostName will return either IP address or hostname on the android implementation

OK. That's good to know. How about the iOS/MacOS implementation?

Nimrodda commented 3 years ago

This comment is just for tracking what's done: Short term solution introduced in PR #21

jnstahl commented 3 years ago

the current Windows implementation returns hostnames, such as 'Android-5.local' when provided by the MDNS query results. However some windows hosts do not have the ability to resolve such a hostname and to establish a connection (apparently this ability relies on 3rd party packages such as Bonjour being installed). Suggested fix:

  • short-term: Windows implementation will always return an IP address string for hostname
  • long-term: the NsdServiceInfo object can be expanded to include:

    • ipv4
    • ipv6 in addition to hostname and port

Sounds like a plan 👍

val hostname = this?.host?.canonicalHostName <==== canonicalHostName will return either IP address or hostname on the android implementation

OK. That's good to know. How about the iOS/MacOS implementation?

One would have to test. But on iOS presumably it won't matter as MDNS is native to iOS and the hostname will always be resolvable. this particular complication is specific to Windows. I found out even more - the hostname may be resolvable within the Flutter app but when opened in an external browser (Chrome) is still not resolvable. Or Flutter may resolve it to an ipv6 which cannot be loaded into chrome either. So now for the purpose of opening external browsers I force resolve it to an ipv4 inside my app before constructing the url. But that is independent from the plugin.