Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 1 of 1

Thread: Bind Exception when trying with Ipv6 and DatagramPackets

  1. #1
    Junior Member
    Join Date
    Sep 2011
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Bind Exception when trying with Ipv6 and DatagramPackets

    Hello everyone ,

    I am trying to do a program with IPv6 socket, when i tried to bind the socket with TCP , i was getting no problem , but when trying to bind with UDP (DatagramSocket ) i am getting exception as java.net.SocketException: already bound ( what ever port im giving im getting same problem ).
    I m unable to solve this ....can any one help regarding this ....Thanks in advance.

    The code is

    import java.net.DatagramSocket;
    import java.net.Inet6Address;
    import java.net.InetAddress;
    import java.net.InetSocketAddress;
    import java.net.ServerSocket;
     
    class Post {
        static public void main(String[] s) {
            try {
                byte[] addr = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,1};
     
                InetAddress inetAddr = Inet6Address.getByAddress(addr);
                System.out.println(inetAddr.getHostAddress());
                InetSocketAddress addr_8501 = new InetSocketAddress(inetAddr,8501);
                ServerSocket serverSocket = new ServerSocket();
                serverSocket.bind(addr_8501); // This works fine 
     
                for ( ; ; )
                {
                	serverSocket.accept();
    	    }
     
            } catch (Throwable t) {
                t.printStackTrace();
            }
        }
    }

    this code worked fine when used with TCP connections ..... but when used Datagram Sockets(UDP) getting problem .....

     
    import java.net.DatagramSocket;
    import java.net.Inet6Address;
    import java.net.InetAddress;
    import java.net.InetSocketAddress;
    import java.net.ServerSocket;
     
    class Post {
        static public void main(String[] s) {
            try {
                byte[] addr = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,1};
     
                InetAddress inetAddr = Inet6Address.getByAddress(addr);
                System.out.println(inetAddr.getHostAddress());
                InetSocketAddress addr_8502 = new InetSocketAddress(inetAddr,8502);
     
                DatagramSocket serverSocket = new DatagramSocket();
                serverSocket.bind(addr_8502); 
     
            } catch (Throwable t) {
                t.printStackTrace();
            }
        }
    }

    getting exception as

    java.net.SocketException: already bound
    at java.net.DatagramSocket.bind(Unknown Source)
    at Post.main(Post.java:23)
    Last edited by immadisetty; September 13th, 2011 at 12:38 AM.


Similar Threads

  1. Replies: 5
    Last Post: September 5th, 2011, 10:31 AM
  2. How to bind soap header using jax-rpc
    By jadeite100 in forum What's Wrong With My Code?
    Replies: 0
    Last Post: December 5th, 2010, 02:54 PM
  3. help needed to bind component
    By furqankhan in forum AWT / Java Swing
    Replies: 1
    Last Post: June 25th, 2010, 07:01 AM
  4. Compress Ipv6 Addresses
    By abhay8nitt in forum Java Networking
    Replies: 5
    Last Post: May 20th, 2010, 06:58 AM
  5. IPv6 validation
    By subhvi in forum Java Networking
    Replies: 1
    Last Post: November 27th, 2009, 07:19 AM