8000 Published ZeroConf Services are not Discoverable on Android React Native But Visible in Bonjour Browser. · Issue #1387 · python-zeroconf/python-zeroconf · GitHub
[go: up one dir, main page]

Skip to content

Published ZeroConf Services are not Discoverable on Android React Native But Visible in Bonjour Browser. #1387

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

Open
Tauqeer-Ahmed-99 opened this issue Aug 7, 2024 · 2 comments

Comments

@Tauqeer-Ahmed-99
Copy link
Tauqeer-Ahmed-99 commented Aug 7, 2024

Hello Team,
I am a University Student and Working on My Dissertation, I was exploring some libraries to connect to RPi's local Node/Python server.

I am using python to publish a zeroconf service on local network on RPi 4 Model B

from zeroconf import ServiceInfo, Zeroconf

PORT=8080

zeroconf = Zeroconf()
wsInfo = ServiceInfo('_http._tcp.local.',
                     "myhost._http._tcp.local.",
                     PORT, 0, 0, {"random_key": "1234", "answer": "42"})
zeroconf.register_service(wsInfo)

import time
time.sleep(1000);

After Registering this service, It is visible on the Bonjour Browser.
My Host is the service name.
but the same is not visible in the react native app using react-native-zeroconf.

image

React Native Code

/**
 * Sample React Native App
 * https://github.com/facebook/react-native
 *
 * @format
 */

import React, {useEffect} from 'react';
import {
  SafeAreaView,
  ScrollView,
  StatusBar,
  Text,
  useColorScheme,
  View,
} from 'react-native';
import Zeroconf from 'react-native-zeroconf';
import {Colors} from 'react-native/Libraries/NewAppScreen';

const zeroconf = new Zeroconf();

function App(): React.JSX.Element {
  const isDarkMode = useColorScheme() === 'dark';

  const backgroundStyle = {
    backgroundColor: isDarkMode ? Colors.darker : Colors.lighter,
  };

  useEffect(() => {
    const handleStart = () => console.log('The scan has started.');
    const handleFound = name => console.log('Service found:', name);
    const handleResolved = service => {
      console.log('Service resolved:', service);
      // setServices(prevServices => [...prevServices, service]);
    };
    const handleError = err => console.log('Error:', err);
    const handleStop = () => console.log('The scan has stopped.');

    zeroconf.on('start', handleStart);
    zeroconf.on('found', handleFound);
    zeroconf.on('resolved', handleResolved);
    zeroconf.on('error', handleError);
    zeroconf.on('stop', handleStop);

    // Start the service scan
    setTimeout(() => {
      zeroconf.scan('http', 'tcp');
      console.log('Started scanning...');
    }, 1000);

    // Cleanup on component unmount
    return () => {
      zeroconf.off('start', handleStart);
      zeroconf.off('found', handleFound);
      zeroconf.off('resolved', handleResolved);
      zeroconf.off('error', handleError);
      zeroconf.off('stop', handleStop);
      zeroconf.stop();
    };
  }, []);

  return (
    <SafeAreaView style={backgroundStyle}>
      <StatusBar
        barStyle={isDarkMode ? 'light-content' : 'dark-content'}
        backgroundColor={backgroundStyle.backgroundColor}
      />
      <ScrollView
        contentInsetAdjustmentBehavior="automatic"
        style={backgroundStyle}>
        <View>
          <Text>My Better RN NETWORK</Text>
        </View>
      </ScrollView>
    </SafeAreaView>
  );
}

export default App;

My WiFi Router's Services are visible in the console but not this one.

image

Can someone please help me making my zeroconf service discoverable in react native code....
The same is True with nodejs server usng 'bonjour' package.

I have added these permissions in AndroidManifest.xml

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
    <uses-permission android:name="android.permission.CHANGE_WIFI_MULTICAST_STATE" />

@bdraco @PaarthShah @jstasiak @scop @dtantsur @andrewbonney @

@Lauorez
Copy link
Lauorez commented Mar 27, 2025

I am having the same problem. Have you found a solution?

@Tauqeer-Ahmed-99
Copy link
Author

Unfortunately not 😔

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

No branches or pull requests

2 participants
0