通过USB访问开发机本地主机 [英] Access dev machine localhost via usb

查看:222
本文介绍了通过USB访问开发机本地主机的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的活动需要与位于我开发计算机Java服务器进行通信。事实上,使用模拟器,我可以通过特殊的10.0.2.2地址访问服务器套接字。现在我想测试我的手机通过USB连接我的应用程序,但似乎我不能用10.0.2.2来访问我开发计算机本地主机了。 当然使用的是无线路由器和适当的LAN解决的伎俩,但我需要使用USB连接来代替。任何提示?

My activity needs to communicate with a java server located on my dev machine. Actually, using the emulator, I can access the server socket via the special 10.0.2.2 address. Now I'd like to test my app on my phone connected via usb, but it seems like I can't use 10.0.2.2 to access my dev machine localhost anymore. Naturally using a wifi router and a proper lan addressing does the trick, but I need to use usb connection instead. Any hint ?

编辑:
只需添加不同的场景,让大家更好地了解:

edit:
Just added different scenarios to let everyone understand better:

1。仿真器为基础的情景:

  • 在标准的Java服务器上的我的电脑运行@localhost:15000
  • 在我的模拟器运行Android的Java客户端。

在Android应用程序需要联系其使用10.0.2.2:15000等指定<服务器一href="http://developer.android.com/intl/fr/guide/developing/tools/emulator.html#emulatornetworking">here. 一切工作正常。

When the android app needs to contact the server it uses 10.0.2.2:15000 like specified here. Everything works fine.

2。适当的无线方案与物理连接设备:

  • 在标准的Java服务器上的我的电脑@ 192.168.1.10运行:15000
  • 在我与分配192.168.1.11地址的设备上运行Android的Java客户端。

在Android应用程序需要联系其使用192.168.1.10:15000服务器,一切工作正常了。

When the android app needs to contact the server it uses 192.168.1.10:15000 and everything works fine too.

3。期望中的场景:

  • 在我的电脑@localhost运行标准的Java服务器:15000
  • 在我通过USB线连接的设备上运行Android的Java客户端。没有网络是活动的。

在Android应用程序需要联系它会尝试连接到10.0.2.2:15000而是抛出一个异常服务器(网络无法访问)。这似乎是特别的地址10.0.2.2仅适用于仿真器实例。

When the android app needs to contact the server it tries to connect to 10.0.2.2:15000 but instead an exception is thrown (Network unreachable). It seems like special address 10.0.2.2 works only for emulator instances.

我只是想知道,在亚洲开发银行/ ADT套房有一种方法来通过USB电缆连接的设备访问PC地址。 我希望它更清楚一点了。 谢谢你。

I just wonder if in the adb/adt suite there's a way to access pc address from the device connected via usb cable. I hope it's a bit more clear now. Thanks.

推荐答案

好像没有办法让场景#3的正常工作,因为USB接口是不是一个真正的网络连接,并且没有通过电话联系到它的IP

It seems like there's no way to let scenario #3 work properly, because usb connection is not a real network connection and there's no ip associated to it by the phone.

其实我的解决办法是用我的手机和我的PC之间的ad-hoc无线网络连接。这种情况类似于#2,但没有路由器或DHCP。不幸的是我的英雄不能处理即席连接本机由于这个问题。因此,我不得不铲除我的设备和手动更改一些配置脚本。我希望这样的功能,可以在接下来的版本中提供。

Actually my solution is to use an ad-hoc wifi connection between my phone and my pc. This scenario is similar to #2, but without router or dhcp. Unfortunately my Hero can't handle ad-hoc connections natively because of this issue. So I had to root my device and to change manually some config script. I hope functionality like this can be available in next releases.

这篇关于通过USB访问开发机本地主机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆