Friday, September 15, 2017

Java & IPv6: ServerSocketChannel.open() throws SocketException

Hello all,
I get the following exception when calling ServerSocketChannel.open():
Exception in thread "main" java.net.SocketException: Invalid argument    at sun.nio.ch.Net.socket0(Native Method)    at sun.nio.ch.Net.serverSocket(Net.java:415)    at sun.nio.ch.ServerSocketChannelImpl.<init>(ServerSocketChannelImpl.java:88)    at sun.nio.ch.SelectorProviderImpl.openServerSocketChannel(SelectorProviderImpl.java:56)    at java.nio.channels.ServerSocketChannel.open(ServerSocketChannel.java:108)
Here's some code to illustrate the issue:    https://github.com/nyg/java-http-server
I do use java.net.preferIPv4Stack=false & co.
Using ServerSocketChannel works as expected when not run on OpenBSD.
Using ServerSocket (and listening to an IPv6 address) instead ofServerSocketChannel works as expected.
I had the same error with the jdk v121. I upgraded to the September 14snapshot and to jdk v144 and still have the issue.

Any help would be greatly appreciated :)Nick

No comments:

Post a Comment