Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SocketException in example/lib/scan/mdns_scan.dart #192

Open
xmlspyspring opened this issue Mar 26, 2024 · 4 comments
Open

SocketException in example/lib/scan/mdns_scan.dart #192

xmlspyspring opened this issue Mar 26, 2024 · 4 comments

Comments

@xmlspyspring
Copy link

I ran example/lib/scan/mdns_scan.dart and got the following error:

C:/a_dev/flutter-sdk/bin/cache/dart-sdk/bin/dart.exe --enable-asserts C:\Users\xmlspyspring\IdeaProjects\network_tools\example\lib\scan\mdns_scan.dart
Unhandled exception:
SocketException: Failed to create datagram socket (OS Error: 在其上下文中,该请求的地址无效。---> In its context, the requested address is invalid 
, errno = 10049), address = , port = 5353
#0      _NativeSocket.bindDatagram (dart:io-patch/socket_patch.dart:1051:7)
<asynchronous suspension>
#1      _RawDatagramSocket.bind.<anonymous closure> (dart:io-patch/socket_patch.dart:2558:15)
<asynchronous suspension>
#2      MDnsClient.start (package:multicast_dns/multicast_dns.dart:135:40)
<asynchronous suspension>
#3      MdnsScannerServiceImpl.findingMdnsWithAddress (package:network_tools/src/services/impls/mdns_scanner_service_impl.dart:73:5)
<asynchronous suspension>

Process finished with exit code 255

My Environment: windows 10 chinese

PS C:\Users\xmlspyspring\IdeaProjects\network_tools> dart --version
Dart SDK version: 3.3.1 (stable) (Wed Mar 6 13:09:19 2024 +0000) on "windows_x64"
@xmlspyspring
Copy link
Author

I know what the reason is, but I can't change it. This is caused by a bug in the multicast_dns.

The file in this library multicast_dns - 0.3.2 + 6\ lib\ multicast_dns.dart line 63 gets all NetInterfaces, but I have two NetworkInterfaces that are closed, so using a socket to connect the two NetInterfaces makes an error.

  Future<Iterable<NetworkInterface>> allInterfacesFactory(
      InternetAddressType type) {
    return NetworkInterface.list(  // --->   here
      includeLinkLocal: true,
      type: type,
      includeLoopback: true,
    );
  }

@xmlspyspring
Copy link
Author

xmlspyspring commented Mar 27, 2024

I found a solution, but I don't know if it's right.

in file lib/src/services/impls/mdns_scanner_service_impl.dart line 73
change

await client.start();

to

await client.start(interfacesFactory: (InternetAddressType type){
  return NetworkInterface.list(
    includeLinkLocal: false,  //  old is true
    type: type,
    includeLoopback: true,
  );
},);

or

    await client.start(interfacesFactory: (InternetAddressType type){
      return NetworkInterface.list(
        includeLinkLocal: true,  
        type: type,
        includeLoopback: true,
      ).then((List<NetworkInterface> list){
        list.removeWhere((item){
          if(ping item is not ok) return true;   // remove this item
          return false;  // ping item is ok 
        });
        return list;
      });
    },);

@git-elliot
Copy link
Collaborator

includeLinkLocal: false will exclude interfaces for everyone. You have 2 interfaces closed but others can have open. If we can determine if a network interface is not closed then we fix this. Probably you can to clone this repo and raise a PR for the fix.

@git-elliot
Copy link
Collaborator

But I don't think that this is the right place to fix it. If we can fix it in package multicast_dns then it would be better. Can you open the same issue in multicast_dns also and let's see if they can fix it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: No status
Development

No branches or pull requests

2 participants