2 Replies Latest reply: Nov 9, 2012 12:31 AM by 852650 RSS

    JNI_CreateJavaVM and IPV6

    852650
      Hi all,

      I met the error on Linux.
      Here is the scenario:

      My C-code will create a JVM, it find method from a Java Class to execute.
      My Java Class create a DatagramSocket with ipv6 address, but it throw a exception:"Exception creating server socket: java.net.SocketException: Protocol family unavailable".

      I can not find out the solution to fix this. please help me.
      These are some VM options that I add when create JVM
      JVM Options:
      -Denv.class.path=/opt/abc/xyz
      -Djava.class.path=/opt/jre/lib/rt.jar:/opt/jre/lib/i18n.jar:/opt/jre/lib/sunrsasign.jar:/opt/jre/lib/classes:/opt/jre/lib/javaplugin.jar
      -Djava.compiler=NONE
      -Dapplication.home=/opt/abc
      -DDaemon=true
      -Djava.net.preferIPv6Addresses=true
      vfprintf

      =====-DDaemon=====
      -DDaemon=true to start upon new Thread (option &)

      thanks,
      ndt

      Edited by: 849647 on Nov 8, 2012 4:00 AM
        • 1. Re: JNI_CreateJavaVM and IPV6
          jschellSomeoneStoleMyAlias
          Post the entire stack trace.
          • 2. Re: JNI_CreateJavaVM and IPV6
            852650
            sorry, this is the full stack trace

            java.net.SocketException: Protocol family unavailable
            java.net.PlainDatagramSocketImpl.bind0(Native Method)
            java.net.AbstractPlainDatagramSocketImpl.bind(AbstractPlainDatagramSocketImpl.java:95)
            java.net.DatagramSocket.bind(DatagramSocket.java:376)
            java.net.DatagramSocket.<init>(DatagramSocket.java:231)
            java.net.DatagramSocket.<init>(DatagramSocket.java:284)
            com.lucent.qtek.common.util.Debug$DebugListener.run(Debug.java:237)
            java.lang.Thread.run(Thread.java:722)
            java.net.SocketException: Protocol family unavailable
                 at java.net.PlainDatagramSocketImpl.bind0(Native Method)
                 at java.net.AbstractPlainDatagramSocketImpl.bind(AbstractPlainDatagramSocketImpl.java:95)
                 at java.net.DatagramSocket.bind(DatagramSocket.java:376)
                 at java.net.DatagramSocket.<init>(DatagramSocket.java:231)
                 at java.net.DatagramSocket.<init>(DatagramSocket.java:284)
                 at com.lucent.qtek.common.util.Debug$DebugListener.run(Debug.java:237)
                 at java.lang.Thread.run(Thread.java:722)


            And this is my source code

            public void run() {
                           try {                    
                                String localaddress = "127.0.0.1";
                                if(SystemIPAddrType() == 6)
                                {
                                     localaddress = "::1";
                                }
                                DatagramSocket serv = new DatagramSocket(0, InetAddress.getByName(localaddress));
                                serv.setReceiveBufferSize(ReceiveBufferSize);
            }
            }

            It run ok with IPV4 address (127.0.0.1) but throw exception if I use IPV6 addresss ("::1")

            ====fork()==========
            I forked a new process before create a JVM in my C code, if I dont fork new process, it run ok, but i need to fork to run many server services (listening).

            The problem: JNI_CreateJavaVM in forked process and supporting IPV6

            thanks,
            ndt

            Edited by: 849647 on Nov 8, 2012 6:30 PM

            Edited by: 849647 on Nov 8, 2012 6:36 PM

            Edited by: 849647 on Nov 8, 2012 7:55 PM

            Edited by: 849647 on Nov 8, 2012 10:30 PM