Project JXTA

net.jxta.impl.endpoint
Class IPUtils

java.lang.Object
  extended bynet.jxta.impl.endpoint.IPUtils

public final class IPUtils
extends Object

Utility methods for use by IP based transports.


Field Summary
static InetAddress ANYADDRESS
          Constant which works as the IP "Any Address" value
static InetAddress ANYADDRESSV4
           
static InetAddress ANYADDRESSV6
           
(package private) static String IPV4ANYADDRESS
           
(package private) static String IPV4LOOPBACK
           
(package private) static String IPV6ANYADDRESS
           
(package private) static String IPV6LOOPBACK
           
static InetAddress LOOPBACK
          Constant which works as the IP "Local Loopback" value;
static InetAddress LOOPBACKV4
           
static InetAddress LOOPBACKV6
           
(package private) static Random random
           
(package private) static int rangesize
          Size of port groups we will probe.
 
Method Summary
static Socket connectToFrom(InetAddress inetAddress, int port, InetAddress usingInterface, int localPort, int timeout)
          Create a client socket using the configured socketFactory or connectToFromNoFactory if none is available.
static Socket connectToFromNoFactory(InetAddress inetAddress, int port, InetAddress usingInterface, int localPort, int timeout)
          Create a client socket with the JDK1.4 method connect().
static Iterator getAllLocalAddresses()
          Provide an iterator which returns all of the local InetAddresses for this host.
static ServerSocketFactory getServerSocketFactory()
          returns the ServerSocketFactory to create server sockets, or null if new SeverSocket() is being used.
static SocketFactory getSocketFactory()
          returns the socketFactory used by connectToFrom() to create sockets, or null if connectToFromNoFactory() is being used.
static ServerSocket openServerSocketInRange(int start, int end, int backlog, InetAddress bindAddress)
          Open a ServerSocket in the specified range.
static void setServerSocketFactory(ServerSocketFactory sf)
          makes connectToFrom create sockets with this factory.
static void setSocketFactory(SocketFactory sf)
          makes connectToFrom create sockets with this factory.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

random

static final Random random

IPV4ANYADDRESS

static final String IPV4ANYADDRESS
See Also:
Constant Field Values

IPV6ANYADDRESS

static final String IPV6ANYADDRESS
See Also:
Constant Field Values

IPV4LOOPBACK

static final String IPV4LOOPBACK
See Also:
Constant Field Values

IPV6LOOPBACK

static final String IPV6LOOPBACK
See Also:
Constant Field Values

ANYADDRESS

public static final InetAddress ANYADDRESS
Constant which works as the IP "Any Address" value


ANYADDRESSV4

public static InetAddress ANYADDRESSV4

ANYADDRESSV6

public static InetAddress ANYADDRESSV6

LOOPBACK

public static final InetAddress LOOPBACK
Constant which works as the IP "Local Loopback" value;


LOOPBACKV4

public static InetAddress LOOPBACKV4

LOOPBACKV6

public static InetAddress LOOPBACKV6

rangesize

static final int rangesize
Size of port groups we will probe.

See Also:
Constant Field Values
Method Detail

getAllLocalAddresses

public static Iterator getAllLocalAddresses()
Provide an iterator which returns all of the local InetAddresses for this host.

Returns:
iterator of InetAddress which is all of the InetAddress for all local interfaces.

connectToFrom

public static Socket connectToFrom(InetAddress inetAddress,
                                   int port,
                                   InetAddress usingInterface,
                                   int localPort,
                                   int timeout)
                            throws IOException
Create a client socket using the configured socketFactory or connectToFromNoFactory if none is available.

Throws:
IOException

connectToFromNoFactory

public static Socket connectToFromNoFactory(InetAddress inetAddress,
                                            int port,
                                            InetAddress usingInterface,
                                            int localPort,
                                            int timeout)
                                     throws IOException
Create a client socket with the JDK1.4 method connect().

Throws:
IOException

setSocketFactory

public static void setSocketFactory(SocketFactory sf)
makes connectToFrom create sockets with this factory.

Parameters:
sf - is the socket factory to use or null if you want the default behaviour provided by connectToFromNoFactory().

getSocketFactory

public static SocketFactory getSocketFactory()
returns the socketFactory used by connectToFrom() to create sockets, or null if connectToFromNoFactory() is being used.

Returns:
the socket factory used by connectToFrom() or null if the connectToFromNoFactory() method is used to create Sockets.

setServerSocketFactory

public static void setServerSocketFactory(ServerSocketFactory sf)
makes connectToFrom create sockets with this factory.

Parameters:
sf - is the socket factory to use or null if you want the default behaviour provided by new SeverSocket().

getServerSocketFactory

public static ServerSocketFactory getServerSocketFactory()
returns the ServerSocketFactory to create server sockets, or null if new SeverSocket() is being used.

Returns:
the socket factory used or null if the new SeverSocket() method is used to create ServerSockets.

openServerSocketInRange

public static ServerSocket openServerSocketInRange(int start,
                                                   int end,
                                                   int backlog,
                                                   InetAddress bindAddress)
                                            throws IOException
Open a ServerSocket in the specified range.

The method used is done so that the entire range is examined if needed while ensuring that the process eventually terminates if no port is available.

Parameters:
start - The lowest numbered port to try.
end - The highest numbered port to try.
backlog - the allowed backlog of unaccepted connections.
Throws:
IOException - when the socket cannot be opened. (Lame, but that's what ServerSocket says).

JXTA J2SE