Class TCPIPAddressID
- All Implemented Interfaces:
Serializable, Cloneable
Provides a concrete implementation of the abstract NodeAddressID for use with the
TCP/IP link protocol. A TCP/IP node address consists of an internet host address (IP address)
and 16bit IP port number.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate InetAddressprivate booleanprivate final intprivate ProtocolIDprivate String -
Constructor Summary
ConstructorsConstructorDescriptionTCPIPAddressID(String host, int port, boolean isUnique) Creates a TCPIPAddressID for a computer, given it's host name and port number.TCPIPAddressID(InetAddress host, int port, boolean isUnique) Creates a TCPIPAddressID for a computer, given it's IP address and port number. -
Method Summary
Modifier and TypeMethodDescriptionfinal booleanCompares two TCPIPAddressID for equality.static NodeAddressIDgetAddressIDFromString(String stringForm) Constructs and returns a TCPIPv4 NodeAddressID from a String.final InetAddressgetHost()Returns the computer's IP addressfinal intgetPort()Returns the computer's port number for incoming link requests.Returns the ProtocolID for this addressprotected StringReturns a string representation of the address suitable for use in thecreateAddressIDmethod ofTCPIPProtocolID.final inthashCode()Returns a hashCode for this TCPIPAddressIDbooleanReturnstrueif thisNodeAddressIDis known to be unique within the global org.jcsp.net domain.final StringtoString()Returns a string representation of this TCPIPAddressID, in the form "123.45.67.234:5678".Methods inherited from class NodeAddressID
clone
-
Field Details
-
host
-
port
private final int port -
protocolID
-
stringForm
-
isUnique
private boolean isUnique
-
-
Constructor Details
-
TCPIPAddressID
Creates a TCPIPAddressID for a computer, given it's IP address and port number.- Parameters:
host- The computer's IP address.port- The computer's port number, in the range 0-65535 inclusive.isUnique- True if the address ID is globally unique, false otherwise.- Throws:
IllegalArgumentException- If the port is invalid.
-
TCPIPAddressID
public TCPIPAddressID(String host, int port, boolean isUnique) throws IllegalArgumentException, UnknownHostException Creates a TCPIPAddressID for a computer, given it's host name and port number.- Parameters:
host- The computer's IP address, as a stringport- The computer's port number.- Throws:
IllegalArgumentException- If the port is invalid.UnknownHostException- If the host name cannot be resolved.
-
-
Method Details
-
getAddressIDFromString
public static NodeAddressID getAddressIDFromString(String stringForm) throws IllegalArgumentException Constructs and returns a TCPIPv4 NodeAddressID from a String. The String MUST be in the form of that returned from the getStringForm method.- Parameters:
stringForm- The String form representing a NodeAddressID.- Throws:
IllegalArgumentException- if the string is incorrectly formatted.
-
getStringForm
Returns a string representation of the address suitable for use in thecreateAddressIDmethod ofTCPIPProtocolID.- Specified by:
getStringFormin classNodeAddressID- Returns:
- a
Stringthat can be passed to the staticgetAddressIDFromString(String)method in order to reconstuct the object.
-
getProtocolID
Returns the ProtocolID for this address- Specified by:
getProtocolIDin classNodeAddressID- Returns:
- this
NodeAddressIDobject'sProtocolID.
-
getHost
-
getPort
public final int getPort()Returns the computer's port number for incoming link requests.- Returns:
- Port number of server.
-
equals
Compares two TCPIPAddressID for equality.- Specified by:
equalsin classNodeAddressID- Parameters:
obj- another object that should be anotherNodeAddressID.- Returns:
- true iff obj is a non-null TCPIPAddressID for the same port invalid input: '&' host, false otherwise.
-
hashCode
public final int hashCode()Returns a hashCode for this TCPIPAddressID- Specified by:
hashCodein classNodeAddressID- Returns:
- an
inthash code.
-
isGloballyUnique
public boolean isGloballyUnique()Description copied from class:NodeAddressIDReturns
trueif thisNodeAddressIDis known to be unique within the global org.jcsp.net domain.A Node may have several addresses. If a Node is on an internal network that is connected to the Internet, it may have one local address and one address that is accessible from the Internet. The Internet address may be globally unique whereas the local address may be duplicated in other internal networks. The
NodeAddressIDobject representing the Internet address should returntruewhen this method is called whereas theNodeAddressIDrepresenting the local address should returnfalse.- Specified by:
isGloballyUniquein classNodeAddressID- Returns:
trueiff thisNodeAddressIDis globally unique.
-
toString
-