简体   繁体   English

为什么我的 android 模拟器无法连接到我的本地服务器?

[英]Why can't I get my android emulator to connect to my local server?

I am developing an app using React Native and made my server with node.js.我正在使用 React Native 开发一个应用程序,并使用 node.js 制作我的服务器。 For websocket connections I use socket.io对于 websocket 连接,我使用 socket.io

The thing is if I install the app to my android device and my android emulator, only my android device can connect to my local server.问题是如果我将应用程序安装到我的 android 设备和我的 android 模拟器,只有我的 android 设备可以连接到我的本地服务器。 They both run the same code.它们都运行相同的代码。 I checked and the emulator has an active internet connection.我检查过,模拟器有一个活动的互联网连接。 Weird thing is I have an other app inside the emulator that connects to the same server without any problems using the same connection methods.奇怪的是我在模拟器中有一个其他应用程序,它使用相同的连接方法连接到同一台服务器,没有任何问题。

Do you guys have any idea why there is a problem like this?你们知道为什么会出现这样的问题吗?

Android emulators have a built in IP to use when connecting to something on your local machine. Android 模拟器有一个内置 IP,可以在连接到本地机器上的某些内容时使用。

If the socket is running on localhost, you want to connect to using the IP address 10.0.2.2 in the emulator.如果套接字在 localhost 上运行,您希望在模拟器中使用 IP 地址 10.0.2.2 进行连接。

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

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