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
Asked
Active
Viewed 2,535 times
-1

user207421
- 305,947
- 44
- 307
- 483

lsm
- 17
- 1
- 3
-
1Holy unformatted wall of exception, Batman. Where's the code? Where is the actual question? – user207421 Oct 28 '15 at 07:36
1 Answers
-1
by the following way,i have deal with the problem.
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);
-
4Please code-format this mess and get rid of the blank lines. And tell us what the problem was, and why this fixed it. – user207421 Oct 28 '15 at 10:42