简体   繁体   English

无法从Android设备上的本机应用程序连接到meteor后端

[英]Can't connect to meteor backend from react native app at android device

I have a meteor webapp and I need to connect to its backend from react native app.我有一个流星 web 应用程序,我需要从 React Native 应用程序连接到它的后端。 I set up sdk, connected my android device and run react-native start and react-native run-android , app gets loaded and client side works, except connection to meteor.我设置了 sdk,连接了我的 android 设备并运行react-native startreact-native run-android ,应用程序被加载并且客户端工作,除了连接到meteor。 I'm using this package https://github.com/inProgress-team/react-native-meteor and trying to connect to my locally running meteor backend with Meteor.connect , using ws://192.168.xxx.xx.x (my local ip address) but it doesn't connect.我正在使用这个包https://github.com/inProgress-team/react-native-meteor并尝试使用ws://192.168.xxx.xx.x使用Meteor.connect连接到我本地运行的流星后端(我的本地 IP 地址)但它没有连接。 I've checked iptables and they seem to be clean.我检查过 iptables,它们似乎很干净。 What could prevent that connection?什么可以阻止这种联系? What else could I try or check?我还能尝试或检查什么? I'm using Ubuntu 16.04.我正在使用 Ubuntu 16.04。

I had the same issue and found that for the android emulator, you have to use a specific IP which it maps to localhost instead of localhost:我遇到了同样的问题,发现对于 android 模拟器,您必须使用它映射到 localhost 而不是 localhost 的特定 IP:

ws://10.0.2.2:3000/websocket instead of ws://localhost:3000/websocket ws://10.0.2.2:3000/websocket而不是ws://localhost:3000/websocket

Please check the updated sample repo herehttps://github.com/spencercarli/react-native-meteor-boilerplate请在此处查看更新的示例存储库https://github.com/spencercarli/react-native-meteor-boilerplate

Be sure that meteor application is running and allow the port if you have firewall.如果您有防火墙,请确保meteor 应用程序正在运行并允许该端口。 Use your machine IP and connect in the same Access Point.使用您的机器 IP 并在同一接入点中连接。 Please follow the structure above which is created by spencercarli.请遵循上面由 spencercarli 创建的结构。

For Android connection to meteor server you have to check your ip of the machine where your meteor server is running you can do this by running commmand ifconfig (Linux Ubuntu) then use this ip in your web socket URL ws://IP:Meteorserverport/websocket and your android device must be connected to internet using same network that you machine is connected with eg WIFI Only then it will run.对于到流星服务器的 Android 连接,您必须检查运行流星服务器的机器的 ip,您可以通过运行 commmand ifconfig (Linux Ubuntu) 来完成此操作,然后在您的网络套接字 URL ws://IP:Meteorserverport/ 中使用此 ip websocket 和您的 android 设备必须使用与您的机器连接的相同网络连接到互联网,例如 WIFI 只有这样它才会运行。 Note: for production app this is not required.注意:对于生产应用程序,这不是必需的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM