我怎样才能从我的Andr​​oid设备访问我的本地主机?我的、主机、设备、oid

2023-09-11 10:47:32 作者:怪咖

我能够访问使用Android模拟器我的笔记本电脑的Web服务器,现在用 10.0.2.2:portno 效果很好。

Am able to access my laptop web server using the Android emulator, am using 10.0.2.2:portno works well.

但是,当我连接我的真正的Andr​​oid手机,该手机浏览器无法连接到我的笔记本电脑相同的Web服务器。将手机连接到使用USB电缆的笔记本电脑。如果我运行 ADB设备命令,我可以看到我的电话。

But when I connect my real Android phone, the phone browser cannot connect to the same web server on my laptop. The phone is connected to the laptop using a USB cable. If I run the adb devices command, I can see my phone.

我在想什么?

推荐答案

USB不为移动设备提供网络。如果它连接到您的无线网络,然后打你的笔记本电脑地址路由器提供。如果它连接到移动网络,然后先搞清楚你的​​路由器的外部IP地址,然后一些端口转发到10.0.2.2:portno最后你就可以看到该服务器从您的设备。

USB doesn't provide network to mobile device. If it's connected to your wifi, then hit your laptop address provided by the router. If it's connected to your mobile network, then first find out your router external IP address, then forward some port to that 10.0.2.2:portno and finally you'll be able to see that server from your device.