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[] args) throws 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);
}
} |
|