我试图在NCM0接口上接收UDP广播。通过USB成功建立NCM连接,但我没有收到任何东西。
我一直试图将Socket绑定到NCM接口,但我得到了无效的参数异常:
ArrayList<NetworkInterface> allInterfaces = Collections.list(NetworkInterface.getNetworkInterfaces());
for(Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); en.hasMoreElements();){
NetworkInterface intf = en.nextElement();
if (intf.getName().equals("ncm0")){
InetSocketAddress addr = new InetSocketAddress(intf.getInetAddresses(), 28500);
}
DatagramSocket socket = new DatagramSocket();
socket.bind(addr);
socket.setBroadcast(true);
我一直试图收到这样的数据报:
byte[] buf = new byte[1024];
DatagramPacket packet = new DatagramPacket(buf, buf.length);
socket.receive(packet);
我做错了什么?