我是 Android 开发的新手,希望您能帮助我。
我在 Linux 中使用 android studio 来开发一个 UPnP 应用程序。
在我的电脑上,有 2 个网络,1 个通过 eth0 连接到互联网,另一个通过 eth1 连接到专用网络。
当我启动我的应用程序时,它可以找到位于网络中连接到 eth0 但不是连接到 eth1 的 UPnP 服务器。
通过查看 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
问题是不可能将协议(protocol) tcp 从端口 80 重定向到流视频。
我的问题是:
1-有没有办法告诉android模拟器听eth1而不是eth0。或者如果可能的话,同时收听 eth0 和 eth1。
2-如果没有,我如何重定向端口 80 以便使用我的应用程序流式传输视频?
谢谢你的帮助。
最佳答案
我以前也遇到过类似的问题。 (但那个时候最终在VM上改为Android到x86。)
对于问题 1:
1- is there a way to tell android emulator listen on eth1 and not eth0. Or if possible to listen to both eth0 and eth1.
只是一些想法,
做
sudo ip link set eth0 down
然后启动安卓模拟器,我猜模拟器应该绑定(bind)到eth1
, 然后开始 eth0
再次。抱歉,我不在 Linux 上工作,无法验证。2- if not, how can I redirect port 80 in order to streaming video with my app?
您的 linux PC 上似乎正在使用 80 端口,因此请确定正在使用哪个进程,然后暂时停止它。
做
sudo netstat -nlp | grep 80
, 并且可能是 nginx
或 apache
我认为。之后 sudo killall YOUR_SERVER
, redir add tcp:80:80
可能工作。此外,如果
eth0
效果很好,您可能不需要打扰redir
.只需使用 iptables
并从 eth0
设置必要的转发至eth1
反而。以下链接可能会有所帮助:https://help.ubuntu.com/community/IptablesHowTo
关于android-studio - 安卓工作室 : connect Android emulator to private network,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31289635/