【问题标题】:Android studio: connect Android emulator to private networkAndroid studio:将Android模拟器连接到专用网络
【发布时间】:2015-07-08 10:13:41
【问题描述】:

我是 Android 开发新手,希望您能帮助我。

我在 Linux 中使用 android studio 来开发一个 UPnP 应用程序。 在我的电脑上,有 2 个网络,1 个通过 eth0 连接到互联网,另一个通过 eth1 连接到私有网络。

当我启动我的应用程序时,它可以找到位于网络中连接到 eth0 的 UPnP 服务器,但找不到连接到 eth1 的服务器。

通过查看Setting up Redirection through the Emulator Console,我找到了一种将网络从端口 1900 重定向到 Android 模拟器的方法,我的应用程序现在可以在专用网络中找到 UPnP 服务器。

Android Console: type 'help' for a list of commands
OK
redir add udp:1900:1900
OK
redir add udp:51844:51844
OK
redir add tcp:80:80
KO: can't setup redirection, port probably used by another program on host

问题是无法将协议 tcp 从端口 80 重定向到流视频。

我的问题是:

1- 有没有办法告诉 android 模拟器监听 eth1 而不是 eth0。或者如果可能的话,同时收听 eth0 和 eth1。

2- 如果没有,我如何重定向端口 80 以便通过我的应用流式传输视频?

感谢您的帮助。

【问题讨论】:

    标签: android-studio android-emulator upnp


    【解决方案1】:

    我以前也遇到过类似的问题。 (但那个时候终于在VM上改为Android到x86了。)

    对于问题 1:

    1- 有没有办法告诉 android 模拟器监听 eth1 而不是 eth0。或者如果可能的话,同时收听 eth0 和 eth1。

    只是一些想法, 做sudo ip link set eth0 down,然后启动Android Emulator,我猜模拟器应该绑定到eth1,然后再次启动eth0。抱歉,我不在 Linux 上工作,无法验证。

    2- 如果没有,我如何重定向端口 80 以便通过我的应用流式传输视频?

    你的 linux PC 上似乎正在使用 80 端口,所以请找出正在使用的进程,然后暂时停止它。

    sudo netstat -nlp | grep 80,我想可能是nginxapache。在sudo killall YOUR_SERVER 之后,redir add tcp:80:80 可能会起作用。

    此外,如果eth0 运行良好,您可能不需要打扰redir。只需使用iptables 并设置从eth0eth1 的必要转发。 以下链接可能会有所帮助:https://help.ubuntu.com/community/IptablesHowTo

    【讨论】:

      猜你喜欢
      • 2015-07-13
      • 2015-12-19
      • 2011-06-18
      • 1970-01-01
      • 1970-01-01
      • 2016-10-24
      • 2017-03-20
      • 2014-08-12
      • 2013-02-20
      相关资源
      最近更新 更多