DatagramSocket getInetAddress() Example
Returns the address to which this socket is connected.
DatagramSocketclass getInetAddress() method example. This example shows you how to use getInetAddress() method.This method Returns the address to which this socket is connected.Here is the code:-
Here is the code:-
/**
* @Program that Returns the address to which this socket is connected.
* GetInetAddress.java
* Author:-RoseIndia Team
* Date:-20-jun-2008
*/
import java.net.*;
public class GetInetAddress {
public static void main(String[] args) throws Exception {
DatagramSocket ds = new DatagramSocket();
InetAddress i = InetAddress.getByName("girish-desktop");
//Returns the address to which this socket is connected.
ds.connect(i, 8080);
System.out.println("Address to which this socket is connected: " + ds.getInetAddress());
}
} |
Output of the program:-
Address to which this socket is connected: girish-desktop/127.0.1.1
|
|