ewe.net
Class InetAddress

java.lang.Object
  extended byewe.net.InetAddress

public class InetAddress
extends Object

An InetAddress represents a host name and IP address. Since a host may have more than one IP address there may be multiple InetAddresses with the same host but with different addresses.

There is no public constructor for InetAddress, you must get one by looking up a host by name or by address.

Note that InetAddresses are not necessary for using sockets but they provide more control for connections and listening (for ServerSockets).


Field Summary
static String INFRA_RED
           
 
Method Summary
 boolean equals(Object other)
          Two InetAddresses are equal if getAddress() called on each one returns precisely the same sequence of bytes.
 byte[] getAddress()
          Returns the raw IP address of this InetAddress object.
static InetAddress[] getAllByName(String hostName)
          Return an array of InetAddress objects associated with the host name.
static IOHandle getAllByName(String name, IOHandle h)
          This attempts to get all the InetAddresses for a particular host.
static InetAddress getByName(String name)
          This gets one address associated with a name.
 String getHostAddress()
          Return the address in the dotted form.
 String getHostName()
          Return the host name.
static InetAddress getLocalHost()
          Return an address for the local host.
static String getLocalHostName()
          This returns the local host name.
 int hashCode()
          Returns a hashCode for the object.
static boolean isANetAddress(String name)
           
 String toString()
          Return a String representation of this object.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass
 

Field Detail

INFRA_RED

public static final String INFRA_RED
See Also:
Constant Field Values
Method Detail

getAllByName

public static IOHandle getAllByName(String name,
                                    IOHandle h)
This attempts to get all the InetAddresses for a particular host. The name can be a computer name or an Internet dotted address (e.g. 123.45.67.89) It is completely non-blocking.

If the IOHandle reports success then the returnValue member of the handle will be an array of InetAddress objects representing all host-ip pairings for the specified name/address. See the doc on getByName(String name) to see how you should use it.


getAllByName

public static InetAddress[] getAllByName(String hostName)
                                  throws UnknownHostException
Return an array of InetAddress objects associated with the host name.

Parameters:
hostName - The name to look for.
Returns:
an array of InetAddress objects associated with the host name.
Throws:
UnknownHostException - if no addresses could be found.

getByName

public static InetAddress getByName(String name)
                             throws UnknownHostException
This gets one address associated with a name. It will block the current Coroutine. Here is the source code for it:
 public static InetAddress getByName(String name){
 	IOHandle h = getAllByName(name,null);
 	if (!h.waitOnFlags(h.Success,TimeOut.Forever)) return null;
 	InetAddress [] ret = (InetAddress [])h.returnValue;
 	return ret[0];
 }
	

Parameters:
name - The host name to look for.
Returns:
an InetAddress associated with the host name.
Throws:
UnknownHostException - if no IP address could be found.

isANetAddress

public static boolean isANetAddress(String name)

getLocalHostName

public static String getLocalHostName()
This returns the local host name. The form of this name depends on the underlying address - it may be a dotted name or it may be a single name. In any case it will always be resolvable to an address by using getAllByName() or getByName().


getLocalHost

public static InetAddress getLocalHost()
                                throws UnknownHostException
Return an address for the local host.

Returns:
an address for the local host.
Throws:
UnknownHostException - If an address for the local host could not be found.

toString

public String toString()
Description copied from class: Object
Return a String representation of this object.

Overrides:
toString in class Object
Returns:
a String representing this object.

getHostName

public String getHostName()
Return the host name.


getHostAddress

public String getHostAddress()
Return the address in the dotted form.


getAddress

public byte[] getAddress()
Returns the raw IP address of this InetAddress object. The result is in network byte order: the highest order byte of the address is in getAddress()[0].

Returns:
the raw IP address of this InetAddress object;

equals

public boolean equals(Object other)
Two InetAddresses are equal if getAddress() called on each one returns precisely the same sequence of bytes.

Overrides:
equals in class Object
Parameters:
other - another InetAddress
Returns:
true if the other object is considered equal to this one.

hashCode

public int hashCode()
Description copied from class: Object
Returns a hashCode for the object. The general contract of hashCode is:
  • An object must return the same hash code for its entire existence.
  • If two objects are considered equal by the equals() method, they should return the same hash code. Not all Objects will do this and you should only use hashCode() from Objects which declare an overrided version of hashCode(). The only Objects which provide consistent and correct hash codes under Ewe are Object, String and Class.

    Overrides:
    hashCode in class Object