View RSS Feed

Java Socket

Class InetAddress

Rate this Entry
by , 04-25-2012 at 10:27 PM (518 Views)
Certain methods are provided by this class to access the IP addresses & hostnames.
InetAddress objects are created by using these methods.

Static InetAddress getLocalHost() throws UnknownHostException For the local machine, InetAddress is returned by this method.

Static InetAddress getByName(String host) throws UnknownHostException For specified hostname, InetAddress object is returned by this method. Hostname could either be an IP like 121.1.28.54 or pneumonic identifier like “www.Java.com” Client can only use this method to obtain the details of remote hosts.

From InetAddress object, information is extracted by using these methods.

byte[] getAddress() An array of bytes is returned by this method corresponding to the IP address, that is present in the InetAddress object. The array is in high byte first or network byte order and should be converted into a string, before it is displayed to the screen.

String getHostName()Host name is returned which is present in InetAddress object. If unknown host name is present, efforts are made to look up, however if it doesn’t succeed then as a string IP addresses are returned.

Exception Errors


UnknownHostException This is IOException subclass which shows that the host name is not identified successfully.

SecurityException When Java security manager restricts the actions to take place, this kind of error is being thrown. Currently, an InetAddress object might be created by Applet for the host from which it originated. For another host, creation of InetAddress object will be throwing this exception.

Submit "Class InetAddress" to Facebook Submit "Class InetAddress" to Digg Submit "Class InetAddress" to del.icio.us Submit "Class InetAddress" to StumbleUpon Submit "Class InetAddress" to Google

Categories
Tutorial

Comments