osociety / network_tools

Networking Tools library which can help you discover open ports, devices on subnet and many other things.
https://pub.dev/packages/network_tools
BSD 3-Clause "New" or "Revised" License
42 stars 13 forks source link

When use Isolate - DartPingIOS.register() should be executed inside Isolate #205

Closed kostadin24 closed 1 month ago

kostadin24 commented 1 month ago

HostScannerService.instance.getAllPingableDevicesAsync doesn not work on iOS. On Android is fine. According to logs:

[ERROR:flutter/runtime/dart_isolate.cc(1107)] Unhandled exception:
UnimplementedError: iOS support has not been enabled. Please see the docs at https://pub.dev/packages/dart_ping
#0      new Ping (package:dart_ping/src/ping_interface.dart:97:9)
#1      HostScannerServiceImpl.getHostFromPing (package:network_tools/src/services/impls/host_scanner_service_impl.dart:110:43)
#2      HostScannerServiceImpl.getAllSendablePingableDevices (package:network_tools/src/services/impls/host_scanner_service_impl.dart:74:11)
<asynchronous suspension>
#3      HostScannerServiceImpl._startSearchingDevices (package:network_tools/src/services/impls/host_scanner_service_impl.dart:264:9)
<asynchronous suspension>

DartPingIOS.register() is not executed since Ping code is executed in separate Isolate and Ping.iosFactory is NULL.

I see DartPingIOS.register() is called in many places in network_tools and network_tools_flutter, but it shouild be called inside the work fuction of Isolate also.

git-elliot commented 1 month ago

Whoever is using network_tools should call DartPingIOS.register() inside their main function. This is how it works in flutter. If I call this method inside spawned isolate it gives me exception mentioned in this issue I raised earlier that has currently no fix - https://github.com/point-source/dart_ping/issues/48