Skip to content

Conversation

@guyluz11
Copy link

Fix: #40

@point-source
Copy link
Owner

point-source commented Jan 21, 2023

Thanks for the PR! What is the purpose of supporting web in this case? You can't ping local net devices from a browser so even if it builds, it won't actually function.

@guyluz11
Copy link
Author

guyluz11 commented Jan 21, 2023

I can think of several reasons that adding a web support may help us.

  1. Flutter is in the process of changing web-based programs from JavaScript to webassembly, this means that there's a chance pinging will work even for browser without changing anything if we support the platform.
  2. It use the exactly same functions and have the same functionality but on top of that it will show support in pub.dev page for one more platform. This means that this package will be more popular.
  3. My app is using this dependency and it is crashing on build to browser. I'm suspecting that fixing that will help more users by giving them the option to compile the app to the browser and see the errors as they go along (and catch them) and not just in the build process.

@point-source
Copy link
Owner

There are a handful of ways to send a ping request:

  • Bind to a raw socket and construct an ICMP packet and send it over the socket
  • Link to a library that is already capable of sending ICMP packets
  • Command/run an executable that is already capable of sending ICMP packets

All the research I've done on this topic up till now suggests the following:

  • Browsers will not allow code (js or wasm) to bind to a native udp or tcp socket on the host system (seemingly for valid security reasons)
  • Browsers provide a limited api which js and wasm can use and it does not provide a way to import or link libraries/binaries on the host system that are not provided explicitly or natively by the browser's engine
  • Browsers will not allow js or wasm to arbitrarily execute a binary on the host computer via shell or process

Given these deliberate limitations which are there to ensure the security of the host, it is not currently feasible to "ping" from any application running inside a web browser. Neither js or wasm is capable of this at this time.

Additionally, since this dart_ping library makes use of host system binaries (with the exception of iOS) to ping other systems, it does not contain any code capable of constructing an ICMP packet. Even if we managed to compile this library to js or wasm, it would be useless because there is no "ping binary for web" that it can call.

As for point 2 of your post, I intentionally do not want this package to show web support because of the reasons above. If this were to show support for web, it would technically be misinformation as far as pub.dev is concerned because this package does not and cannot function on web even if it compiles without error. I would rather not mislead the community on this point.

Regarding your app and web support, I would love for your app to support web and simply inform the user that the ping function is not available in web mode. It seems you should be able to make use of conditional imports to avoid importing this package when compiling for web (much as universal_io, etc do). That way, you can manage how your app deals with the feature incompatibility without affecting the specifications of this package.

Thoughts?

@guyluz11
Copy link
Author

Yep you are right

AI have searched and found the same result
https://stackoverflow.com/questions/69120994/using-ping-class-in-blazor-webassembly

It seems like web assembly will not support ping from the reason that you mentioned.
It was shocking for me because I hear a lot the phrase web apps will replace native desktop apps, but it seems that they miss this piece of knowledge.

I will remove universal_io from the pr.

@guyluz11
Copy link
Author

guyluz11 commented Jan 23, 2023

Removed universal_io from pr.

Pr contains only the relevant parts which are mostly updating the packages.

@point-source
Copy link
Owner

Thanks. Since most of these dependencies are not major version increments, they should be forward compatible. Are you having any dependency resolution issues at the moment? And if so, which deps?

@guyluz11
Copy link
Author

No dependency resolution issue at the moment.

@point-source point-source mentioned this pull request Feb 6, 2023
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

Successfully merging this pull request may close these issues.

Moving to universal_io

2 participants