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        /***
042         * Creates a Socket connected to the given host and port.
043         * <p>
044         * @param host The hostname to connect to.
045         * @param port The port to connect to.
046         * @return A Socket connected to the given host and port.
047         * @exception UnknownHostException  If the hostname cannot be resolved.
048         * @exception IOException If an I/O error occurs while creating the Socket.
049         ***/
050        public Socket createSocket(String host, int port)
051        throws UnknownHostException, IOException;
052    
053    
054        /***
055         * Creates a Socket connected to the given host and port.
056         * <p>
057         * @param address The address of the host to connect to.
058         * @param port The port to connect to.
059         * @return A Socket connected to the given host and port.
060         * @exception IOException If an I/O error occurs while creating the Socket.
061         ***/
062        public Socket createSocket(InetAddress address, int port)
063        throws IOException;
064    
065    
066        /***
067         * Creates a Socket connected to the given host and port and
068         * originating from the specified local address and port.
069         * <p>
070         * @param host The hostname to connect to.
071         * @param port The port to connect to.
072         * @param localAddr  The local address to use.
073         * @param localPort  The local port to use.
074         * @return A Socket connected to the given host and port.
075         * @exception UnknownHostException  If the hostname cannot be resolved.
076         * @exception IOException If an I/O error occurs while creating the Socket.
077         ***/
078        public Socket createSocket(String host, int port, InetAddress localAddr,
079                                   int localPort)
080        throws UnknownHostException, IOException;
081    
082        /***
083         * Creates a Socket connected to the given host and port and
084         * originating from the specified local address and port.
085         * <p>
086         * @param address The address of the host to connect to.
087         * @param port The port to connect to.
088         * @param localAddr  The local address to use.
089         * @param localPort  The local port to use.
090         * @return A Socket connected to the given host and port.
091         * @exception IOException If an I/O error occurs while creating the Socket.
092         ***/
093        public Socket createSocket(InetAddress address, int port,
094                                   InetAddress localAddr, int localPort)
095        throws IOException;
096    
097        /***
098         * Creates a ServerSocket bound to a specified port.  A port
099         * of 0 will create the ServerSocket on a system-determined free port.
100         * <p>
101         * @param port  The port on which to listen, or 0 to use any free port.
102         * @return A ServerSocket that will listen on a specified port.
103         * @exception IOException If an I/O error occurs while creating
104         *                        the ServerSocket.
105         ***/
106        public ServerSocket createServerSocket(int port) throws IOException;
107    
108        /***
109         * Creates a ServerSocket bound to a specified port with a given
110         * maximum queue length for incoming connections.  A port of 0 will
111         * create the ServerSocket on a system-determined free port.
112         * <p>
113         * @param port  The port on which to listen, or 0 to use any free port.
114         * @param backlog  The maximum length of the queue for incoming connections.
115         * @return A ServerSocket that will listen on a specified port.
116         * @exception IOException If an I/O error occurs while creating
117         *                        the ServerSocket.
118         ***/
119        public ServerSocket createServerSocket(int port, int backlog)
120        throws IOException;
121    
122        /***
123         * Creates a ServerSocket bound to a specified port on a given local
124         * address with a given maximum queue length for incoming connections.
125         * A port of 0 will
126         * create the ServerSocket on a system-determined free port.
127         * <p>
128         * @param port  The port on which to listen, or 0 to use any free port.
129         * @param backlog  The maximum length of the queue for incoming connections.
130         * @param bindAddr  The local address to which the ServerSocket should bind.
131         * @return A ServerSocket that will listen on a specified port.
132         * @exception IOException If an I/O error occurs while creating
133         *                        the ServerSocket.
134         ***/
135        public ServerSocket createServerSocket(int port, int backlog,
136                                               InetAddress bindAddr)
137        throws IOException;
138    }