androidreact-nativenetwork-programmingexpozeroconf

Starting service discovery failed with code: 0


I'm trying to use react-native-zeroconf library inside a .jsx page using Expo. I need it to scan every device on the same network everytime I enter the page and I made it like this:

useEffect(() => {
    const zeroconf = new Zeroconf();

    zeroconf.on('start', () => {
      console.log("Scanning started");
    });

    zeroconf.on('resolved', (service) => {
      console.log("Service found:", service);
      setDevices((prevDevices) => [...prevDevices, service]);
    });

    zeroconf.on('error', (err) => {
      console.error("Error during the scan:", err);
    });

    zeroconf.scan('_http._tcp.', 'local.');

    return () => {
      zeroconf.stop();
    };
  }, []);

Apparently, I'm running everytime into the same error which says

Error during the scan: Error: Starting service discovery failed with code: 0

I also already set permissions on app.json like this:

"android": {
      "permissions": [
        "android.permission.ACCESS_WIFI_STATE",
        "android.permission.ACCESS_NETWORK_STATE",
        "android.permission.CHANGE_WIFI_MULTICAST_STATE",
        "android.permission.CHANGE_WIFI_STATE",
        "android.permission.INTERNET"
      ],
    }

But i just keep getting that error, no matter what I try


Solution

  • So, I just followed step by step this guide and now it works perfectly