Closed guyluz11 closed 2 years ago
I have tested this code and time to run the scan is still same because there is no improvement in code. You have just moved pingdata code in another method and collecting all futures in a list and then again await
for the same future. I appreciate your efforts but code does the same thing and no improvements have been seen. Some of the code like creating list and a HostScanner instance is unnecessary.
This is weird, there is clearly something missing here. The old code took 0:03:58.748177, My code took 0:00:01.325691,
The old code
My code
I am calling getHostFromPing for all the IPs at once, they are running in parallel in the background. Then await in the end wait for each of them to finish, but already are running in parallel in the background and the result will be much faster.
I am running only the beginning part in the example
String ip = '192.168.1.1';
// or You can also get ip using network_info_plus package
// final String? ip = await (NetworkInfo().getWifiIP());
final String subnet = ip.substring(0, ip.lastIndexOf('.'));
final stream = HostScanner.discover(subnet,
firstSubnet: 1, lastSubnet: 254, progressCallback: (progress) {});
stream.listen((host) {
//Same host can be emitted multiple times
//Use Set<ActiveHost> instead of List<ActiveHost>
print('Found device HostId: ${host.hostId}');
}, onDone: () {
print('Scan completed');
}); // Don't forget to cancel the stream when not in use.
If you have a discord I will be glad to discuss it with you and take a look.
Please also tell me how you are measuring this time. My discord id is elliot-alderson#5736
I have sent a friend request.
Tested the time using a timer as suggested here
final stopwatch = Stopwatch()..start();
doSomething();
print('doSomething() executed in ${stopwatch.elapsed}');
Sorry, a huge mistake from my side when trying to test your code. I forgot to fetch your code in the pubspec.yaml. Your code works.
…not be shown by default.
Fix for #4