hypercast
Class INETv4OnePort

java.lang.Object
  |
  +--hypercast.INETv4OnePort
All Implemented Interfaces:
I_Address, I_NetworkAddress, I_PhysicalAddress, I_UnderlayAddress

public class INETv4OnePort
extends java.lang.Object
implements I_PhysicalAddress, I_UnderlayAddress

This class implements a physical address which works on the TCP/IP networks. It contains a IP version 4 address and a port number.


Field Summary
static int ADDRESS_SIZE
          The size of INETv4OnePort type physical address when carried in the packet.
static int INETv4_ADDRESS_SIZE
          The size of IP address when carried in the packet.
static int MAX_PORT
           
static int MIN_PORT
           
static int PORT_NUMBER_SIZE
          The size of port number when carried in the packet.
 
Constructor Summary
INETv4OnePort(byte[] byteAddressAndPort)
          Constructs a INETv4OnePort object from an six byte array.
INETv4OnePort(java.net.DatagramSocket a)
          Constructs a INETv4OnePort object with DatagramSocket.
INETv4OnePort(java.net.InetAddress a, int p)
          Constructs a INETv4OnePort object with an InetAddress and port number.
INETv4OnePort(hypercast.INETv4OnePort inetv4oneport)
          Constructs a INETv4OnePort object with another INETv4OnePort object.
INETv4OnePort(int portnum)
          Constructs the INETv4OnePort object which has the specified port number.
INETv4OnePort(java.lang.String addrAndPortString)
          Constructs a INETv4OnePort object from a string.
 
Method Summary
 boolean addressCheck(java.lang.Object obj)
          Test if two INETv4OnePort addresses are identical.
 boolean equals(java.lang.Object obj)
          Test if two INETv4OnePort addresses are identical.
 byte[] getByteAddress()
          Gets byte address of this object.
 java.net.InetAddress getInetAddress()
          Gets INETv4 address of this object.
static java.lang.String getLocalIPbyDNS()
          Obtain local IP address by a DNS query and return local IP address in String form.
 int getPort()
          Gets port number of this INETv4OnePort object.
 int getSize()
          Returns the byte array size.
 boolean greaterThan(hypercast.I_Address addr)
          Compares two INETv4OnePort objects.
 int hashCode()
          Returns a hashcode of this object It is important that the argument is of type Object so that it can be used in a Hashtable.
 void setPort(int port)
          Sets port number of this IP_Address object.
 byte[] toByteArray()
          Converts the Address/Port pair to a 6 bytes array.
 java.lang.String toString()
          Converts the IP address object to string format "xxx.xxx.xxx.xxx/port" (e.g.
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

MIN_PORT

public static final int MIN_PORT
See Also:
Constant Field Values

MAX_PORT

public static final int MAX_PORT
See Also:
Constant Field Values

INETv4_ADDRESS_SIZE

public static final int INETv4_ADDRESS_SIZE
The size of IP address when carried in the packet.

See Also:
Constant Field Values

PORT_NUMBER_SIZE

public static final int PORT_NUMBER_SIZE
The size of port number when carried in the packet.

See Also:
Constant Field Values

ADDRESS_SIZE

public static final int ADDRESS_SIZE
The size of INETv4OnePort type physical address when carried in the packet.

See Also:
Constant Field Values
Constructor Detail

INETv4OnePort

public INETv4OnePort(hypercast.INETv4OnePort inetv4oneport)
Constructs a INETv4OnePort object with another INETv4OnePort object.

Parameters:
inetv4oneport - An INETv4OnePort object.

INETv4OnePort

public INETv4OnePort(java.net.InetAddress a,
                     int p)
Constructs a INETv4OnePort object with an InetAddress and port number. This method is called by the constructor of INETv4TwoPorts.

Parameters:
a - An InetAddress.
p - port number.

INETv4OnePort

public INETv4OnePort(java.net.DatagramSocket a)
Constructs a INETv4OnePort object with DatagramSocket.

Parameters:
a - A DatagramSocketObject.

INETv4OnePort

public INETv4OnePort(int portnum)
Constructs the INETv4OnePort object which has the specified port number.

Parameters:
portnum - a port number.

INETv4OnePort

public INETv4OnePort(byte[] byteAddressAndPort)
Constructs a INETv4OnePort object from an six byte array.

Parameters:
byteAddressAndPort - an Internet address and port stored in a byte array
Throws:
java.lang.IllegalArgumentException - when p is not in 0 to (2^16)-1

INETv4OnePort

public INETv4OnePort(java.lang.String addrAndPortString)
Constructs a INETv4OnePort object from a string. The string may contain the address and port separated by a '/' or ':', or only contain a port number.

Parameters:
addrAndPortString - a string representing the INETv4 address and port (eg. "128.143.71.50/4747" or "128.143.71.50:4747" or "4747")
Throws:
java.lang.IllegalArgumentException - when port is not in 0 to (2^16)-1
HyperCastWarningRuntimeException
Method Detail

getInetAddress

public java.net.InetAddress getInetAddress()
Gets INETv4 address of this object.


getByteAddress

public byte[] getByteAddress()
Gets byte address of this object.

Returns:
A byte[] as returned by InetAddress.getAddress.

getPort

public int getPort()
Gets port number of this INETv4OnePort object.


setPort

public void setPort(int port)
Sets port number of this IP_Address object.


getSize

public int getSize()
Returns the byte array size.

Specified by:
getSize in interface I_Address

toByteArray

public byte[] toByteArray()
Converts the Address/Port pair to a 6 bytes array. The format is |-------4------|----2----| | IP | port | | | | |--------------|---------|

Specified by:
toByteArray in interface I_Address
Returns:
a 6 byte array where the first 4 bytes holds the address, the next 2 bytes holds the port.

equals

public boolean equals(java.lang.Object obj)
Test if two INETv4OnePort addresses are identical.

Specified by:
equals in interface I_Address
Overrides:
equals in class java.lang.Object
Parameters:
obj - an object (should be of type INETv4OnePort.)
Throws:
java.lang.IllegalArgumentException - if obj is not of type INETv4OnePort.

addressCheck

public boolean addressCheck(java.lang.Object obj)
Test if two INETv4OnePort addresses are identical.

Specified by:
addressCheck in interface I_PhysicalAddress
Parameters:
obj - an object (should be of type INETv4OnePort.)
Throws:
java.lang.IllegalArgumentException - if obj is not of type INETv4OnePort.

greaterThan

public boolean greaterThan(hypercast.I_Address addr)
Compares two INETv4OnePort objects.

Specified by:
greaterThan in interface I_Address
Parameters:
addr - an object of type I_Address
Returns:
true if (this > addr), otherwise false
Throws:
java.lang.IllegalArgumentException - if obj is not of type INETv4OnePort.

toString

public java.lang.String toString()
Converts the IP address object to string format "xxx.xxx.xxx.xxx/port" (e.g. "128.143.71.50/4747")

Overrides:
toString in class java.lang.Object

hashCode

public int hashCode()
Returns a hashcode of this object It is important that the argument is of type Object so that it can be used in a Hashtable.

Specified by:
hashCode in interface I_Address
Overrides:
hashCode in class java.lang.Object

getLocalIPbyDNS

public static java.lang.String getLocalIPbyDNS()
Obtain local IP address by a DNS query and return local IP address in String form.