1
votes
InetSocketAddress ipv4 = ...; // the IPv4 address
InetSocketAddress ipv6 = ...; // the IPv6 address

Socket sock = ...; // initialize a socket

sock.bind(ipv4);
sock.connect(ipv6, 0);

Both sides are IPv4/IPv6 dual stack support.

Can Java support for this kind of connection?

If the JDK could try to translate the binding address into a IPv6 one or translate the target address into a IPv4 one?

I tried case of bind IPv6 while connect to IPv4. JDK translate the binding IPv6 address into a IPv4 one during the connecting process. But when trying bind IPv4 while connect to IPv6 (as I mentioned above), I just got time out exception. I'm not sure if this is not support or some issue of my environment. I guess there should be some exception indicating not support thrown before connecting, not a time out finally.

Any idea? Thanks.

2
This is what IPv4-mapped IPv6 addresses are for, to have an effective IPv4 and IPv6 address to connect to both families.Steve-o

2 Answers

3
votes

IPv4 and IPv6 are different protocols. You cannot mix them. You can only connect from an IPv4 address to another IPv4 address or from an IPv6 address to another IPv6 address.

-1
votes

It is possible to create separate Sockets listen on IPv4 and IPv6 on unix machines. http://msdn.microsoft.com/en-us/library/windows/desktop/bb513665%28v=vs.85%29.aspx