sockets - Java DatagramChannel Multicast Defaults to IPv6 -
i'm trying write abstract class inherited 3 classes:
- udpserver
- multicastserver
- tcpserver
multicastserver 1 having issues. of now, udp only. when connection received, hand socket predefined consumer<*sockettype*>
stored in member m_handler
. i'm using selector
this.
the main issue i'm running @ time seems default ipv6. i'm getting message:
java.lang.illegalargumentexception: ipv6 socket cannot join ipv4 multicast group
// m_chan member instance of channel type. datagramchannel multicast. if(tcpmode) // true if generic socket type passed serversocket ((serversocketchannel)m_chan).socket().bind(sa); else{ if(multicast) // true if generic socket type passed multicastsocket ((datagramchannel)m_chan).join(inet4address.getbyname(m_host), getipaddr()); else ((datagramchannel)m_chan).socket().bind(sa); }
and here code getipaddr()
:
static networkinterface getipaddr() throws socketexception, unknownhostexception{ inetaddress iaddr = inetaddress.getlocalhost(); networkinterface iface = networkinterface.getbyinetaddress(iaddr); return iface; }
i've tried adding this:
system.setproperty("java.net.preferipv4stack" , "true");
to no avail.
i'm using ipv4.
the following works fine me. same exception describe, when change standardprotocolfamily.inet standardprotocolfamily.inet6, assume somehow used wrong option when creating datagramchannel?
public class test { public static void main(string[] args) throws ioexception { networkinterface ni = networkinterface.getnetworkinterfaces().nextelement(); datagramchannel server = datagramchannel.open(standardprotocolfamily.inet) .setoption(standardsocketoptions.so_reuseaddr, true) .bind(new inetsocketaddress(5000)) .setoption(standardsocketoptions.ip_multicast_if, ni); server.join(inet4address.getbyname("225.4.5.6"), ni); } }
Comments
Post a Comment