Socket getLocalAddress Example
Socket class getLocalAddress example. This example shows you how to use getLocalAddress method.
Socket class getLocalAddress example. public InetAddress getLocalAddress() Gets the local address to which the socket is bound.
Here is the code
/*
* @ # GetLocalAddress.java
* A class repersenting use to getLocalAddress method
* of NumberFormat class in java.text package
* version 17 June 2008
* author Rose India
*/
import java.net.*;
public class GetLocalAddress {
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));
InetAddress inetAddress = socket.getLocalAddress();
String s = inetAddress.getHostAddress();
System.out.println(s);
//close socket
socket.close();
}
} |
|