Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

java && IPv6

2 views
Skip to first unread message

Matthias Apitz

unread,
May 28, 2013, 8:01:24 AM5/28/13
to

Hello,

I'm a C-programmer and want to do something in Java now;

I want to write an IPv6 server in java which should do what my C written
IPv6-server does:

- create the two sockets for IPv4 and IPv6
- bind, listen
- monitor the sockets with "poll" and accept the connection on the
socket which is ready to be accepted;

see the C-source at http://www.unixarea.de/ipv6-server.c.txt
it can be compiled and run and creates LISTEN on the two sockets, see
netstat output:

~/c]$ gcc ipv6-server.c
~/c]$ ./a.out
family: 28 (PF_INET6) sin6_addr: [::]
LISTEN: IPv6 ...
family: 2 (PF_INET) sin_addr: [0.0.0.0]
LISTEN: IPv4 ...

~/c]$ netstat -an | fgrep 39999
tcp4 0 0 *.39999 *.* LISTEN
tcp6 0 0 *.39999 *.* LISTEN

when I do something similar on the same FreeBSD host in Java, I can't
manage to create the IPv6 LISTEN on the IP addr "::"; IPv4 works fine,
when I use as addr 'null';
the source is here: http://www.unixarea.de/ipv6.java.txt

~/java]$ javac ipv6.java
~/java]$ java -version
java version "1.6.0_03-p4"
Java(TM) SE Runtime Environment (build 1.6.0_03-p4-guru_22_apr_2011_14_10-b00)
Java HotSpot(TM) Client VM (build 1.6.0_03-p4-guru_22_apr_2011_14_10-b00, mixed mode)
~/java]$ java -Djava.net.preferIPv6Stack=true ipv6
java.net.SocketException: Protocol family unavailable
at java.net.PlainSocketImpl.socketBind(Native Method)
at java.net.PlainSocketImpl.bind(PlainSocketImpl.java:359)
at java.net.ServerSocket.bind(ServerSocket.java:319)
at java.net.ServerSocket.<init>(ServerSocket.java:185)
at ipv6$1.run(ipv6.java:18)
at java.lang.Thread.run(Thread.java:619)

Any Java guru out here? Any comments on my Java class? Thanks

matthias

--
Sent from my FreeBSD netbook

Matthias Apitz | - No system with backdoors like Apple/Android
E-mail: gu...@unixarea.de | - Never being an iSlave
WWW: http://www.unixarea.de/ | - No proprietary attachments, no HTML/RTF in E-mail
phone: +49-170-4527211 | - Respect for open standards
_______________________________________________
freebs...@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-java
To unsubscribe, send any mail to "freebsd-java...@freebsd.org"

Alexander Yerenkow

unread,
May 28, 2013, 8:06:08 AM5/28/13
to
Did your jdk built with ipv6 support?


2013/5/28 Matthias Apitz <gu...@unixarea.de>
--
Regards,
Alexander Yerenkow

Matthias Apitz

unread,
May 28, 2013, 8:09:01 AM5/28/13
to
El día Tuesday, May 28, 2013 a las 03:06:08PM +0300, Alexander Yerenkow escribió:

> Did your jdk built with ipv6 support?

I do not remember and the host where the ports have been build in 2011
has gone; how can I check this?

Matthias Apitz

unread,
May 28, 2013, 8:26:57 AM5/28/13
to
El día Tuesday, May 28, 2013 a las 03:06:08PM +0300, Alexander Yerenkow escribió:

> Did your jdk built with ipv6 support?

I've checked the same class with openjdk7 on my 10-CURRENT netbook:

$ java -version
openjdk version "1.7.0_17"
OpenJDK Runtime Environment (build 1.7.0_17-b02)
OpenJDK Client VM (build 23.7-b01, mixed mode)

$ netstat -an | fgrep 39999
tcp46 0 0 *.39999 *.* LISTEN

the 'tcp46' let me think, that the LISTEN is for both, IPv4 and IPv6,
and I can reach the server with

$ telnet ::1 39999
Trying ::1...
Connected to localhost.

and with

$ telnet 127.0.0.1 39999
Trying 127.0.0.1...
Connected to localhost.

Seems to work fine now.

Btw: How do they do this internally having only one Socket for both
families?

Ronald Klop

unread,
May 28, 2013, 9:30:35 AM5/28/13
to
On Tue, 28 May 2013 14:01:24 +0200, Matthias Apitz <gu...@unixarea.de>
wrote:
Your Java is really really really old. ;-) I guess it was this one:
http://www.freshports.org/java/jdk16/
It is even removed from the ports tree already.
It is advised to use the more recent openjdk6 or openjdk7 ports.

Ronald.
0 new messages