001: /*
002: * Copyright 2001-2005 The Apache Software Foundation
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016: package org.apache.commons.net;
017:
018: import java.io.IOException;
019: import java.net.InetAddress;
020: import java.net.ServerSocket;
021: import java.net.Socket;
022: import java.net.UnknownHostException;
023:
024: /***
025: * The SocketFactory interface provides a means for the programmer to
026: * control the creation of sockets and provide his own Socket
027: * implementations for use by all classes derived from
028: * {@link org.apache.commons.net.SocketClient}.
029: * This allows you to provide your own Socket implementations and
030: * to perform security checks or browser capability requests before
031: * creating a Socket.
032: * <p>
033: * <p>
034: * @author Daniel F. Savarese
035: * @see DefaultSocketFactory
036: ***/
037:
038: public interface SocketFactory {
039:
040: /***
041: * Creates a Socket connected to the given host and port.
042: * <p>
043: * @param host The hostname to connect to.
044: * @param port The port to connect to.
045: * @return A Socket connected to the given host and port.
046: * @exception UnknownHostException If the hostname cannot be resolved.
047: * @exception IOException If an I/O error occurs while creating the Socket.
048: ***/
049: public Socket createSocket(String host, int port)
050: throws UnknownHostException, IOException;
051:
052: /***
053: * Creates a Socket connected to the given host and port.
054: * <p>
055: * @param address The address of the host to connect to.
056: * @param port The port to connect to.
057: * @return A Socket connected to the given host and port.
058: * @exception IOException If an I/O error occurs while creating the Socket.
059: ***/
060: public Socket createSocket(InetAddress address, int port)
061: throws IOException;
062:
063: /***
064: * Creates a Socket connected to the given host and port and
065: * originating from the specified local address and port.
066: * <p>
067: * @param host The hostname to connect to.
068: * @param port The port to connect to.
069: * @param localAddr The local address to use.
070: * @param localPort The local port to use.
071: * @return A Socket connected to the given host and port.
072: * @exception UnknownHostException If the hostname cannot be resolved.
073: * @exception IOException If an I/O error occurs while creating the Socket.
074: ***/
075: public Socket createSocket(String host, int port,
076: InetAddress localAddr, int localPort)
077: throws UnknownHostException, IOException;
078:
079: /***
080: * Creates a Socket connected to the given host and port and
081: * originating from the specified local address and port.
082: * <p>
083: * @param address The address of the host to connect to.
084: * @param port The port to connect to.
085: * @param localAddr The local address to use.
086: * @param localPort The local port to use.
087: * @return A Socket connected to the given host and port.
088: * @exception IOException If an I/O error occurs while creating the Socket.
089: ***/
090: public Socket createSocket(InetAddress address, int port,
091: InetAddress localAddr, int localPort) throws IOException;
092:
093: /***
094: * Creates a ServerSocket bound to a specified port. A port
095: * of 0 will create the ServerSocket on a system-determined free port.
096: * <p>
097: * @param port The port on which to listen, or 0 to use any free port.
098: * @return A ServerSocket that will listen on a specified port.
099: * @exception IOException If an I/O error occurs while creating
100: * the ServerSocket.
101: ***/
102: public ServerSocket createServerSocket(int port) throws IOException;
103:
104: /***
105: * Creates a ServerSocket bound to a specified port with a given
106: * maximum queue length for incoming connections. A port of 0 will
107: * create the ServerSocket on a system-determined free port.
108: * <p>
109: * @param port The port on which to listen, or 0 to use any free port.
110: * @param backlog The maximum length of the queue for incoming connections.
111: * @return A ServerSocket that will listen on a specified port.
112: * @exception IOException If an I/O error occurs while creating
113: * the ServerSocket.
114: ***/
115: public ServerSocket createServerSocket(int port, int backlog)
116: throws IOException;
117:
118: /***
119: * Creates a ServerSocket bound to a specified port on a given local
120: * address with a given maximum queue length for incoming connections.
121: * A port of 0 will
122: * create the ServerSocket on a system-determined free port.
123: * <p>
124: * @param port The port on which to listen, or 0 to use any free port.
125: * @param backlog The maximum length of the queue for incoming connections.
126: * @param bindAddr The local address to which the ServerSocket should bind.
127: * @return A ServerSocket that will listen on a specified port.
128: * @exception IOException If an I/O error occurs while creating
129: * the ServerSocket.
130: ***/
131: public ServerSocket createServerSocket(int port, int backlog,
132: InetAddress bindAddr) throws IOException;
133: }
|