简体   繁体   English

通过Android设备上的USB电缆连接到PC的本地主机

[英]Connect to the PC's local host through usb cable on android device

I'm debuging an android application using my android smartphone (Sony Experia) and I need to connect to the computer's local host through the android app I'm developing. 我正在使用我的Android智能手机(Sony Experia)调试一个Android应用程序,我需要通过正在开发的Android应用程序连接到计算机的本地主机。 I tried several methods (USB tethering, Wifi hotspot) but I couldn't achieve it. 我尝试了几种方法(USB绑定,Wifi热点),但无法实现。 Please support me with a solution. 请给我一个解决方案。 I know that simply 10.0.2.2 is working well on the android AVD but I've no idea about real devices. 我知道,仅10.0.2.2在android AVD上运行良好,但我对真实设备一无所知。

I'm using Microsoft Internet Information Services (IIS) as my server and the web application is also running well. 我使用Microsoft Internet信息服务(IIS)作为服务器,并且Web应用程序也运行良好。 I don't know whether the firewall is blocking the port or not. 我不知道防火墙是否阻止了端口。

This should work: 这应该工作:

  • Unplug all the network cables on the computer and turn off your wifi. 拔下计算机上的所有网络电缆,然后关闭wifi。

  • Turn off the wifi on your Xperia. 关闭Xperia上的wifi。

  • Connect your Xperia to your computer via USB Turn on "USB Tethering" in the android menu. 通过USB将Xperia连接到计算机。在android菜单中打开“ USB Tethering”。 (Under networks-> more...-> Tethering and portable hotspot") (在网络下->更多...->网络共享和便携式热点”)

  • Get the IP of your computer that has been assigned by the USB tether cable. 获取USB系绳电缆分配的计算机IP。 (open command prompt and type "ipconfig" then look for the IP that the USB network adapter has assigned, It is Under 'Ethernet Adapter Local Area Connection' title. The Value for the IPv4 address is the One you need.) (打开命令提示符并键入“ ipconfig”,然后查找USB网络适配器已分配的IP,它位于“以太网适配器本地连接”标题下。IPv4地址的值是您需要的IP地址。)

  • Open a browser on the PC using the IP address found instead of localhost to test. 使用找到的IP地址而不是localhost打开PC上的浏览器进行测试。 ie

      http://192.168.1.1/myWebSite 
  • Open a browser on the android and it should work. 在android上打开浏览器,它应该可以工作。

If it is working on your PC but not in your device, You have to allow your http through firewall. 如果它在您的PC上运行但不在您的设备上运行,则必须允许http通过防火墙。

Follow How to enable sharing of web site on localhost? 关注如何在本地主机上启用网站共享? to do it. 去做吧。

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

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