Nimrodda / flutter_nsd

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

Windows desktop support #15

Closed Nimrodda closed 2 years ago

Nimrodda commented 2 years ago

Contributions are welcome (https://github.com/Nimrodda/flutter_nsd/issues/11#issuecomment-973862153)

jnstahl commented 2 years ago

Great, so one question: what is the scope of the API? The windows implementation I use basically scans for 10 seconds then shuts down. If I want to emulate the Andoid Nsd API I would have to repeatedly restart the scan process until stopDiscovery is called. And I am not entirely sure if it is required to support multiple scans for different services in parallel

Nimrodda commented 2 years ago

Awesome progress! 👍 Answering your questions regarding the API scope:

The windows implementation I use basically scans for 10 seconds then shuts down. If I want to emulate the Android Nsd API I would have to repeatedly restart the scan process until stopDiscovery is called.

AFAIK, also iOS keeps scanning until it's stopped. I'd say in this case, if you can get it to scan continuously to match Android and iOS then that would be the preferred way.

And I am not entirely sure if it is required to support multiple scans for different services in parallel

There's no need for multiple parallel scans. Only one service at a time.

jnstahl commented 2 years ago

AFAIK, also iOS keeps scanning until it's stopped. I'd say in this case, if you can get it to scan continuously to match Android and iOS then that would be the preferred way. Yes in further testing I realized that the use case where you scan for a particlular service and it only comes online after you start scanning is currently broken. But at the low level that means one has to repeatedly send multicast requests out to see what comes back.

jnstahl commented 2 years ago

OK I create a PR to merge my fork in to yours. You can take a first look if you want

Nimrodda commented 2 years ago

Done in #16

Nimrodda commented 2 years ago

@jnstahl I'm in the process of setting up a Github Actions workflow to build the example app on all the supported platforms. Windows build fails with the following error:

CMake Error at CMakeLists.txt:47 (add_subdirectory):
Building Windows application...                                 
  add_subdirectory given source "runner" which is not an existing directory.

CMake Error at flutter/generated_plugins.cmake:13 (target_link_libraries):
  Cannot specify link libraries for target "flutter_nsd_example" which is not
  built by this project.
Call Stack (most recent call first):
  CMakeLists.txt:[51](https://github.com/Nimrodda/flutter_nsd/runs/5058998187?check_suite_focus=true#step:5:51) (include)

I haven't had the chance to test the Windows integration so far since I don't have a Windows development machine. Were you able to run the example app on Windows? It would be great if you could fix this issue :pray: The workflow file is located here.

jnstahl commented 2 years ago

Not exactly sure about this workflow. is this running on your local machine or in some CID environment? Any of the windows applications requires VisualStudio to compile

On Thu, Feb 3, 2022 at 2:40 PM Nimrod Dayan @.***> wrote:

@jnstahl https://github.com/jnstahl I'm in the process of setting up a Github Actions workflow to build the example app on all the supported platforms. Windows build fails with the following error:

CMake Error at CMakeLists.txt:47 (add_subdirectory):

Building Windows application...

add_subdirectory given source "runner" which is not an existing directory.

CMake Error at flutter/generated_plugins.cmake:13 (target_link_libraries):

Cannot specify link libraries for target "flutter_nsd_example" which is not

built by this project.

Call Stack (most recent call first):

CMakeLists.txt:51 (include)

I haven't had the chance to test the Windows integration so far since I don't have a Windows development machine. Were you able to run the example app on Windows? It would be great if you could fix this issue 🙏 The workflow file is located here https://github.com/Nimrodda/flutter_nsd/blob/master/.github/workflows/build.yaml#L18 .

— Reply to this email directly, view it on GitHub https://github.com/Nimrodda/flutter_nsd/issues/15#issuecomment-1029468014, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABGPGOVGOCD6UBAJPFPGGTTUZL74LANCNFSM5IPTKKMA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

You are receiving this because you were mentioned.Message ID: @.***>

jnstahl commented 2 years ago

But certainly the example compiles and runs on my machine:

[image: image.png]

On Thu, Feb 3, 2022 at 2:54 PM Johannes Stahl @.***> wrote:

Not exactly sure about this workflow. is this running on your local machine or in some CID environment? Any of the windows applications requires VisualStudio to compile

On Thu, Feb 3, 2022 at 2:40 PM Nimrod Dayan @.***> wrote:

@jnstahl https://github.com/jnstahl I'm in the process of setting up a Github Actions workflow to build the example app on all the supported platforms. Windows build fails with the following error:

CMake Error at CMakeLists.txt:47 (add_subdirectory):

Building Windows application...

add_subdirectory given source "runner" which is not an existing directory.

CMake Error at flutter/generated_plugins.cmake:13 (target_link_libraries):

Cannot specify link libraries for target "flutter_nsd_example" which is not

built by this project.

Call Stack (most recent call first):

CMakeLists.txt:51 (include)

I haven't had the chance to test the Windows integration so far since I don't have a Windows development machine. Were you able to run the example app on Windows? It would be great if you could fix this issue 🙏 The workflow file is located here https://github.com/Nimrodda/flutter_nsd/blob/master/.github/workflows/build.yaml#L18 .

— Reply to this email directly, view it on GitHub https://github.com/Nimrodda/flutter_nsd/issues/15#issuecomment-1029468014, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABGPGOVGOCD6UBAJPFPGGTTUZL74LANCNFSM5IPTKKMA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

You are receiving this because you were mentioned.Message ID: @.***>

Nimrodda commented 2 years ago

It's running on a CI environment (Windows Server 2022) on Github. It is configured with Visual Studio built-in.

What commands do you use to build the example on Windows?

jnstahl commented 2 years ago

Just 'flutter build windows'

For the example I just launch 'example/main.dart' on the local windows target within android Studio

On Thu, Feb 3, 2022, 9:54 PM Nimrod Dayan @.***> wrote:

It's running on a CI environment (Windows Server 2022) on Github. It is configured with Visual Studio built-in.

What commands do you use to build the example on Windows?

— Reply to this email directly, view it on GitHub https://github.com/Nimrodda/flutter_nsd/issues/15#issuecomment-1029682541, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABGPGOQ4O4O5UQWZTRVHK7LUZNSYTANCNFSM5IPTKKMA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

You are receiving this because you were mentioned.Message ID: @.***>

Nimrodda commented 2 years ago

Alright, thanks 👍 I'll investigate this

Nimrodda commented 2 years ago

I got it working now. It seems the example windows project was missing a lot of files (you can see what I mean in this commit 589e10952659b77f1ecc56c4b2530797da94e339). I had to run flutter create to bring the missing files. You said the example worked for you. Did you forget to commit these files?

Anyway, now that I got the example app for Windows build, I ran it on my Windows PC (I use it only for games) and scanned for mock service I ran on my macbook using the command dns-sd -R MyJsonServer1 _example._tcp . 3000 foo=bar. Unfortunately, the service wasn't discovered. I tried to discover it with the Android example app and it worked. So there's an issue on Windows. You mentioned in the README.md that upon first run, Windows should ask for permission to access the network. In my case, I didn't see such request. I tried to manually add the executable to the allowed apps list for accessing the network, but that didn't help.

Could you please try the example Windows build which was made by Github from here and see if it works for you? The app is scanning for _http._tcp..

jnstahl commented 2 years ago

works perfectly:

[image: image.png]

maybe your network is set to public ( as opposed to private)? Windows will impose many security restrictions on public networks

On Sat, Feb 5, 2022 at 5:15 PM Nimrod Dayan @.***> wrote:

I got it working now. It seems the example windows project was missing a lot of files (you can see what I mean in this commit 589e109 https://github.com/Nimrodda/flutter_nsd/commit/589e10952659b77f1ecc56c4b2530797da94e339). I had to run flutter create to bring the missing files. You said the example worked for you. Did you forget to commit these files?

Anyway, now that I got the example app for Windows build, I ran it on my Windows PC (I use it only for games) and scanned for mock service I ran on my macbook using the command dns-sd -R MyJsonServer1 _example._tcp . 3000 foo=bar. Unfortunately, the service wasn't discovered. I tried to discover it with the Android example app and it worked. So there's an issue on Windows. You mentioned in the README.md that upon first run, Windows should ask for permission to access the network. In my case, I didn't see such request. I tried to manually add the executable to the allowed apps list for accessing the network, but that didn't help.

Could you please try the example Windows build which was made by Github from here https://github.com/Nimrodda/flutter_nsd/suites/5191795860/artifacts/158125988 and see if it works for you? The app is scanning for _http._tcp..

— Reply to this email directly, view it on GitHub https://github.com/Nimrodda/flutter_nsd/issues/15#issuecomment-1030706781, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABGPGOQRW45TW4MBQUCJETLUZXDTZANCNFSM5IPTKKMA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

You are receiving this because you were mentioned.Message ID: @.***>

jnstahl commented 2 years ago

And I think I did not add these files in the cherry-picking process as these are generated and somewhat ephemeral

On Sat, Feb 5, 2022 at 5:15 PM Nimrod Dayan @.***> wrote:

I got it working now. It seems the example windows project was missing a lot of files (you can see what I mean in this commit 589e109 https://github.com/Nimrodda/flutter_nsd/commit/589e10952659b77f1ecc56c4b2530797da94e339). I had to run flutter create to bring the missing files. You said the example worked for you. Did you forget to commit these files?

Anyway, now that I got the example app for Windows build, I ran it on my Windows PC (I use it only for games) and scanned for mock service I ran on my macbook using the command dns-sd -R MyJsonServer1 _example._tcp . 3000 foo=bar. Unfortunately, the service wasn't discovered. I tried to discover it with the Android example app and it worked. So there's an issue on Windows. You mentioned in the README.md that upon first run, Windows should ask for permission to access the network. In my case, I didn't see such request. I tried to manually add the executable to the allowed apps list for accessing the network, but that didn't help.

Could you please try the example Windows build which was made by Github from here https://github.com/Nimrodda/flutter_nsd/suites/5191795860/artifacts/158125988 and see if it works for you? The app is scanning for _http._tcp..

— Reply to this email directly, view it on GitHub https://github.com/Nimrodda/flutter_nsd/issues/15#issuecomment-1030706781, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABGPGOQRW45TW4MBQUCJETLUZXDTZANCNFSM5IPTKKMA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

You are receiving this because you were mentioned.Message ID: @.***>

Nimrodda commented 2 years ago

The files are generated by the flutter tool that's correct. But they must be checked in to Git as well.

Thanks for testing this. I'll check my network preferences. What tool do you use for faking a discoverable service? Perhaps I can try the same one, although the service created by dns-sd should be discoverable on any platform. I tested and it is discoverable on the iOS, MacOS and Android example apps, but not on Windows.

I'd like to release a new version of the plugin, but I can't do that until I verify it works and if additional steps are needed, update the docs.

jnstahl commented 2 years ago

I'm not faking anything, these are just printers and things on my network

On Sat, Feb 5, 2022, 10:57 PM Nimrod Dayan @.***> wrote:

The files are generated by the flutter tool that's correct. But they must be checked in to Git as well.

Thanks for testing this. I'll check my network preferences. What tool do you use for faking a discoverable service? Perhaps I can try the same one, although the service created by dns-sd should be discoverable on any platform. I tested and it is discoverable on the iOS, MacOS and Android example apps, but not on Windows.

I'd like to release a new version of the plugin, but I can't do that until I verify it works and if additional steps are needed, update the docs.

— Reply to this email directly, view it on GitHub https://github.com/Nimrodda/flutter_nsd/issues/15#issuecomment-1030765370, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABGPGOTMHCU566L4VZQLZMLUZYLVZANCNFSM5IPTKKMA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

You are receiving this because you were mentioned.Message ID: @.***>

Nimrodda commented 2 years ago

I managed to find my HP printer as well, but the service I'm faking with dns-sd isn't found unlike other platforms which do find it. Any ideas?

I found this tool from Microsoft https://github.com/microsoft/FindDevice/releases/tag/v1.0.0 If I run: FindDevice.exe --service _http._tcp. nothing is found, but if I add local at the end, then it finds both the printer and the fake service. Which is aligned with what I see in the code. I noticed in the code you add "local." to the query.

Nimrodda commented 2 years ago

I finally managed to get the dns-sd service discovered as well. I removed the dot from local. in the querying code. Not sure if that had any effect though. Then I ran the command dns-sd -R TestService _http._tcp . 3000 which then started a fake service on _http._tcp.local.

There's one issue though that I noticed. After clicking the START button, the same services are being discovered again and again. This behavior doesn't match with other platforms where discovered services list is only returned once. Would you be able to fix it so that I can proceed with the release?

example_app

jnstahl commented 2 years ago

I will look into it and get back to you. Where did you remove the dot after local. ?

On Sun, Feb 6, 2022, 2:43 AM Nimrod Dayan @.***> wrote:

I finally managed to get the dns-sd service discovered as well. I removed the dot from local. in the querying code. Not sure if that had any effect though. Then I ran the command dns-sd -R TestService _http._tcp . 3000 which then started a fake service on _http._tcp.local.

That's one issue though that I noticed. After clicking the START button, the same services are being discovered again and again. This behavior doesn't match with other platforms where discovered services list is only returned once. Would you be able to fix it so that I can proceed with the release?

[image: example_app] https://user-images.githubusercontent.com/149684/152677086-be59891a-113a-4d9c-9dd6-7d4619b5a996.JPG

— Reply to this email directly, view it on GitHub https://github.com/Nimrodda/flutter_nsd/issues/15#issuecomment-1030805717, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABGPGOXOLWWMOOBTFEDXZWLUZZGGPANCNFSM5IPTKKMA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

You are receiving this because you were mentioned.Message ID: @.***>

Nimrodda commented 2 years ago

Yes, the dot after local.. Thanks!

jnstahl commented 2 years ago

OK I verified that removing that period after local. does not negatively affect my own use cases either, so it is probably better that way

I added a PR to remove sending of duplicate results.

Nimrodda commented 2 years ago

Thanks a lot for the fix! I tested it and it works great 👍

Nevertheless, I just realized there's another different behavior issue. As you can see in the screenshot I took below from MacOS, the list should only show the service name in the list (in the example app), but on Windows it shows the service name concatenated with the service type. For comparison, check out the Windows screenshot from the previous comments here. Actually service type shouldn't be present in the result at all. Only the service name.

Screenshot 2022-02-07 at 0 10 15

To clarify, what I mean: only the "TestService" text part without the ._http._tcp should be set to name in the result map.

jnstahl commented 2 years ago

ah - I did not pay attention to this as in my use case I con't care or display the name of the service, I only need the hostname...