Socket getInetAddress Example
Socket class getInetAddress example. This example shows you how to use getInetAddress method.
Socket class getInetAddress example. public InetAddress getInetAddress() Returns the address to which the socket is connected.
Here is the code
/*
* @ # getInetAddress.java
* A class repersenting use to getInetAddress method
* of Socket class in java.net package
* version 19 June 2008
* author Rose India
*/
import java.net.*;
public class getInetAddress {
public static void main(String args[]) throws Exception {
Socket socket = new Socket();
//Connects this socket to the server.
socket.connect(new InetSocketAddress("192.168.10.80", 9090));
//return getInetAddress
InetAddress inetaddress = socket.getInetAddress();
System.out.println("Inet Address is " + inetaddress);
//close socket
socket.close();
}
} |
Output
| Inet Address is /192.168.10.80 |
|