DatagramSocket GetRemoteSocketAddress() Example

Returns a SocketAddress representing the remote endpoint of this socket, or null if it is not connected yet.


DatagramSocketclass GetRemoteSocketAddress() method example. This example shows you how to use GetRemoteSocketAddress() method.This method Returns a SocketAddress representing the remote endpoint of this socket, or null if it is not connected yet.

Here is the code:-

/**
 * @Program that Returns the address of the endpoint this socket is connected to.
 * GetRemoteSocketAddress.java 
 * Author:-RoseIndia Team
 * Date:-20-jun-2008
 */
import java.net.*;

public class GetRemoteSocketAddress {

    public static void main(String[] argsthrows Exception {
        DatagramSocket ds = new DatagramSocket();
        ds.connect(new InetSocketAddress(9090));
        //Returns the address of the endpoint this socket is connected to.
        SocketAddress s = ds.getRemoteSocketAddress();
        System.out.println(s);
    }
}

Output of the program:-
 0.0.0.0/0.0.0.0:9090

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

HOME | COPYRIGHT | CONTACT US