2015-10-28 58 views
0
10-28 14:40:11.530: W/System.err(11802): java.net.SocketException: setsockopt failed: ENODEV (No such device) 
10-28 14:40:11.530: W/System.err(11802): at libcore.io.IoBridge.setSocketOption(IoBridge.java:324) 
10-28 14:40:11.530: W/System.err(11802): at java.net.PlainDatagramSocketImpl.setOption(PlainDatagramSocketImpl.java:186) 
10-28 14:40:11.530: W/System.err(11802): at java.net.PlainDatagramSocketImpl.join(PlainDatagramSocketImpl.java:126) 
10-28 14:40:11.530: W/System.err(11802): at java.net.MulticastSocket.joinGroup(MulticastSocket.java:149) 
10-28 14:40:11.530: W/System.err(11802): at com.lsm.activity.TestActivity$MySendThread.run(TestActivity.java:145) 
10-28 14:40:11.530: W/System.err(11802): Caused by: libcore.io.ErrnoException: setsockopt failed: ENODEV (No such device) 
10-28 14:40:11.530: W/System.err(11802): at libcore.io.Posix.setsockoptGroupReq(Native Method) 
10-28 14:40:11.530: W/System.err(11802): at libcore.io.ForwardingOs.setsockoptGroupReq(ForwardingOs.java:125) 
10-28 14:40:11.530: W/System.err(11802): at libcore.io.IoBridge.setSocketOptionErrno(IoBridge.java:397) 
10-28 14:40:11.530: W/System.err(11802): at libcore.io.IoBridge.setSocketOption(IoBridge.java:322) 
10-28 14:40:11.530: W/System.err(11802): ... 4 more 
+0

圣洁无格式的例外墙,蝙蝠侠。代码在哪里?真正的问题在哪里? – EJP

回答

0

通过以下方式,我已经处理了这个问题。

Enumeration enumeration = NetworkInterface.getNetworkInterfaces(); 

NetworkInterface eth0 = null; 

while (enumeration.hasMoreElements() { 

eth0 = enumeration.nextElement() 
if (eth0.getName().equals("eth0")) { 

    //there is probably a better way to find ethernet interface 
    break; 
} 

} 

InetAddress group = InetAddress.getByName(IP); 

MulticastSocket s = new MulticastSocket(PORT); 

s.setSoTimeout(10000); 

//s.joinGroup(group); 
//this will throw "No such device" exception 

s.joinGroup(new InetSocketAddress(group, PORT), eth0); 

// this works just fine 

for (int i = 0; i < 10; ++i) { 

byte[] buf = new byte[8096]; 

DatagramPacket recv = new DatagramPacket(buf, buf.length); 

s.receive(recv); 

System.out.println("Recieved " + recv.getLength() + " bytes."); 

} 

s.leaveGroup(group); 
+1

请将此混乱编码格式并摆脱空白行。并告诉我们问题是什么,以及为什么这个问题解决了。 – EJP

相关问题