DatagramSocket GetLocalAddress() Example

Gets the local address to which the socket is bound.


DatagramSocketclass GetLocalAddress() method example. This example shows you how to use GetLocalAddress() method.This method Gets the local address to which the socket is bound.

Here is the code:-

/**
 * @Program that Gets the local address to which the socket is bound.
 * GetLocalAddress.java 
 * Author:-RoseIndia Team
 * Date:-20-jun-2008
 */
import java.net.*;

public class GetLocalAddress {

    public static void main(String[] argsthrows Exception {
        DatagramSocket ds = new DatagramSocket(8080);
        ds.connect(new InetSocketAddress(9090));
        //Gets the local address to which the socket is bound.
        InetAddress i = ds.getLocalAddress();
        System.out.println("Local address to which the socket is bound is: " + i);
    }
}

Output of the program:-
 Local address to which the socket is bound is: /0:0:0:0:0:0:0:1

Post Comment
Name:
E-mail:
Contact no :
Comments:
  Refresh Image
Verify Image:
 
 
Your Comment's
 
 
 

HOME | COPYRIGHT | CONTACT US