org.p2psockets
Class P2PSocketAddress

java.lang.Object
  extended byjava.net.SocketAddress
      extended byorg.p2psockets.P2PSocketAddress
All Implemented Interfaces:
java.io.Serializable

public class P2PSocketAddress
extends java.net.SocketAddress

This class implements a P2P Socket Address (Jxta host name + port number + IP Address).

Version:
0.5
Author:
Brad GNUberg, bkn3@columbia.edu
See Also:
Serialized Form

Constructor Summary
P2PSocketAddress(java.net.InetAddress inetAddr, int port)
          Creates a socket address from an IP address and a port number.
P2PSocketAddress(int port)
          Creates a socket address where the IP address is the wildcard address and the port number a specified value.
P2PSocketAddress(java.lang.String host, int port)
          Creates a socket address from a host and a port number.
 
Method Summary
 boolean equals(java.lang.Object obj)
           
protected  int generateRandomPort()
          This method generates a random port number.
 java.net.InetAddress getAddress()
          Gets the InetAddress.
 java.lang.String getHostName()
          Gets the host.
 int getPort()
          Gets the port number.
 int hashCode()
           
 void setHostName(java.lang.String host)
           
 void setPort(int port)
           
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

P2PSocketAddress

public P2PSocketAddress(int port)
Creates a socket address where the IP address is the wildcard address and the port number a specified value.

A valid port value is between 0 and 65535. A port number of zero will let the system pick up an ephemeral port in a bind operation.

Parameters:
port - The port number
Throws:
java.lang.IllegalArgumentException - if the port parameter is outside the specified range of valid port values.

P2PSocketAddress

public P2PSocketAddress(java.net.InetAddress inetAddr,
                        int port)
Creates a socket address from an IP address and a port number.

A valid port value is between 0 and 65535. A port number of zero will let the system pick up an ephemeral port in a bind operation.

A null address will assign the wildcard address.

Parameters:
inetAddr - The IP address
port - The port number
Throws:
java.lang.IllegalArgumentException - if the port parameter is outside the specified range of valid port values.

P2PSocketAddress

public P2PSocketAddress(java.lang.String host,
                        int port)
Creates a socket address from a host and a port number.

An attempt will be made to resolve the host into an InetAddress. If that attempt fails, the address will be flagged as unresolved.

A valid port value is between 0 and 65535. A port number of zero will let the system pick up an ephemeral port in a bind operation.

Parameters:
host - the Host name
port - The port number
Throws:
java.lang.IllegalArgumentException - if the port parameter is outside the range of valid port values, or if the host parameter is null.
See Also:
#isUnresolved()
Method Detail

getPort

public final int getPort()
Gets the port number.

Returns:
the port number.

getAddress

public final java.net.InetAddress getAddress()
Gets the InetAddress.

Returns:
the InetAdress or null if it is unresolved.

getHostName

public final java.lang.String getHostName()
Gets the host.

Returns:
the host part of the address.

setPort

public void setPort(int port)

setHostName

public void setHostName(java.lang.String host)

toString

public java.lang.String toString()

equals

public final boolean equals(java.lang.Object obj)

hashCode

public final int hashCode()

generateRandomPort

protected int generateRandomPort()
This method generates a random port number. This is used because in some cases we don't 'care' what the local or remote port number is, such as when we are a client talking to a server and want to know what port the client is communicating on locally: the client is not even communicating through a port, since they are using JXTA. We still need a value though and simply create this number using this method.