sunlabs.brazil.util
Interface SocketFactory

All Known Implementing Classes:
SunProxy

public interface SocketFactory

This interface is used as a heap to control the allocation of sockets.

An instance of this interface can be passed to methods that allocate sockets. In this way, the actual, underlying type of socket allocated can be replaced (for instance, with an SSL socket or an firewall-tunnelling socket), without the user of the socket having to explicitly be aware of the underlying implementation.

In some ways, this class is a replacement for the SocketImplFactory class. This class addresses the following issues.

Version:
2.2
Author:
Colin Stevens (colin.stevens@sun.com)

Field Summary
static SocketFactory defaultFactory
          The default socket factory.
 
Method Summary
 Socket newSocket(String host, int port)
          Creates a new Socket that talks to the specified port on the named host.
 

Field Detail

defaultFactory

static final SocketFactory defaultFactory
The default socket factory. It just creates a standard Socket to the specified host and port, and is exactly equivalent to calling new Socket(host, port).

Method Detail

newSocket

Socket newSocket(String host,
                 int port)
                 throws IOException
Creates a new Socket that talks to the specified port on the named host.

The implementation may choose any way it wants to provide a socket-like object (essentially any mechanism that supports bidirectional communication). The returned Socket (or subclass of Socket) might not be based on TCP/IP, or it might involve running a TCP/IP stack over some other protocol, or it might actually redirect all connections via some other proxy machine, etc.

Parameters:
host - The host name.
port - The port number.
Returns:
An object that provides socket-like communication.
Throws:
IOException - If there is some problem establishing the socket to the specified port on the named host.