com.mindbright.net
Class SocketFactory

java.lang.Object
  extended by com.mindbright.net.SocketFactory

public class SocketFactory
extends java.lang.Object

Opens and connects a new SocketChannel with an optional timeout.


Constructor Summary
SocketFactory()
           
 
Method Summary
static java.nio.channels.SocketChannel newSocket(java.net.InetAddress ia, int port)
          Connects to the given server.
static java.nio.channels.SocketChannel newSocket(java.net.InetAddress ia, int port, long mstimeout)
          Connects to the given server.
static java.nio.channels.SocketChannel newSocket(java.lang.String host, int port)
          Connects to the given server.
static java.nio.channels.SocketChannel newSocket(java.lang.String host, int port, long mstimeout)
          Connects to the given server.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SocketFactory

public SocketFactory()
Method Detail

newSocket

public static java.nio.channels.SocketChannel newSocket(java.net.InetAddress ia,
                                                        int port)
                                                 throws java.io.IOException
Connects to the given server.

Parameters:
ia - Address of server to connect to
port - Port to connect to
Returns:
A SocketChannel connected to the given address
Throws:
java.io.IOException - If there are any errors during the connection.

newSocket

public static java.nio.channels.SocketChannel newSocket(java.lang.String host,
                                                        int port)
                                                 throws java.net.UnknownHostException,
                                                        java.io.IOException
Connects to the given server.

Parameters:
host - Name of server to connect to
port - Port to connect to
Returns:
A SocketChannel connected to the given address
Throws:
java.io.IOException - If there are any errors during the connection.
java.net.UnknownHostException

newSocket

public static java.nio.channels.SocketChannel newSocket(java.lang.String host,
                                                        int port,
                                                        long mstimeout)
                                                 throws java.net.UnknownHostException,
                                                        java.io.IOException
Connects to the given server.

Parameters:
host - Name of server to connect to
port - Port to connect to
mstimeout - How many millisecondse to wait before giving up
Returns:
A SocketChannel connected to the given address
Throws:
java.io.IOException - If there are any errors during the connection or if the connection has not been established before mstimeout milliseconds have passwd.
java.net.UnknownHostException

newSocket

public static java.nio.channels.SocketChannel newSocket(java.net.InetAddress ia,
                                                        int port,
                                                        long mstimeout)
                                                 throws java.io.IOException
Connects to the given server.

Parameters:
ia - Address of server to connect to
port - Port to connect to
mstimeout - How many millisecondse to wait before giving up
Returns:
A SocketChannel connected to the given address
Throws:
java.io.IOException - If there are any errors during the connection or if the connection has not been established before mstimeout milliseconds have passwd.