DatagramSocket GetLocalSocketAddress() Example
Returns the address of the endpoint this socket is bound to, or null if it is not bound yet.
DatagramSocketclass GetLocalSocketAddress() method example. This example shows you how to use GetLocalSocketAddress() method.This method Returns the address of the endpoint this socket is bound to, or null if it is not bound yet.
Here is the code:-
/**
* @Program that Returns the port number on the local host to which this socket
* is bound
* GetLocalSocketAddress.java
* Author:-RoseIndia Team
* Date:-20-jun-2008
*/
import java.net.*;
public class GetLocalSocketAddress {
public static void main(String[] args) throws Exception {
DatagramSocket ds = new DatagramSocket();
ds.connect(new InetSocketAddress(9090));
SocketAddress sa = ds.getLocalSocketAddress();
System.out.println("Local host to which this socket is bound: " + sa);
}
} |
Output of the program:-
| Local host to which this socket is bound: /0:0:0:0:0:0:0:1:33611 |
|