通过USB访问开发机本地主机

编程入门 行业动态 更新时间:2024-10-28 18:23:22
本文介绍了通过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等指定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访问开发机本地主机

本文发布于:2023-10-07 12:26:13,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1469385.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:主机   USB

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!