udp 转发到模拟器 [英] udp forwarding to emulator
问题描述
我的主机上有一个 java 应用程序,可以将 UDP 数据包发送到一个端口:例如8888.
我有一个 Android 应用程序,它监听这个端口并简单地显示数据.
I have a java application on my host that sends UDP packets to a port: e.g. 8888.
And I have an Android application that listens to this port and simply displays the data.
这适用于真实设备(通过 WiFi 连接到同一网络),但我无法在模拟器中使用它.
This works fine with a real device (which is connected via WiFi to the same network), but I cannot get this working in the Emulator.
一些信息:
- 我在 Ubuntu 16.10 上工作
- 我已停用 Ubuntu 防火墙
- 通过 IntelliJ 启动 Android 模拟器应用程序
- 模拟器的 API 级别为 25
Android 应用程序中连接端口的代码:
the code in the Android app to connect to the port:
final DatagramSocket udpSocket = new DatagramSocket(8888);
这是发送广播的服务器的(伪)代码:
here's the (pseudo) code of the server that sends the broadcast:
String data = "test"; InetAddress broadcastAddress = Inet4Address.getByName("255.255.255.255"); DatagramSocket udpSocket = new DatagramSocket(); udpSocket.setBroadcast(true); byte[] dataBytes = data.getBytes(); DatagramPacket datagramPacket = new DatagramPacket(dataBytes, dataBytes.length, broadcastAddress, 8888); udpSocket.send(datagramPacket);
我错过了什么?
推荐答案
由于 Android 中的错误,这不起作用:问题#207602:模拟器不重定向 UDP 数据包
This does not work because of a bug in Android: Issue#207602: Emulator does not redirect UDP packets
解决方法:
- 在终端中:
- 获取您的 avd 列表:
emulator -list-avds
- 使用其中一个 avds 启动模拟器并添加
-engine classic
参数:emulator -avd Nexus_6_API_25_GER -engine classic
这篇关于udp 转发到模拟器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
- 获取您的 avd 列表: