View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *     http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.apache.commons.net;
18  
19  import java.io.IOException;
20  import java.net.InetAddress;
21  import java.net.ServerSocket;
22  import java.net.Socket;
23  import java.net.UnknownHostException;
24  
25  /***
26   * The SocketFactory interface provides a means for the programmer to
27   * control the creation of sockets and provide his own Socket
28   * implementations for use by all classes derived from
29   * {@link org.apache.commons.net.SocketClient}.
30   * This allows you to provide your own Socket implementations and
31   * to perform security checks or browser capability requests before
32   * creating a Socket.
33   * <p>
34   * <p>
35   * @author Daniel F. Savarese
36   * @see DefaultSocketFactory
37   ***/
38  
39  public interface SocketFactory
40  {
41  
42      /***
43       * Creates a Socket connected to the given host and port.
44       * <p>
45       * @param host The hostname to connect to.
46       * @param port The port to connect to.
47       * @return A Socket connected to the given host and port.
48       * @exception UnknownHostException  If the hostname cannot be resolved.
49       * @exception IOException If an I/O error occurs while creating the Socket.
50       ***/
51      public Socket createSocket(String host, int port)
52      throws UnknownHostException, IOException;
53  
54  
55      /***
56       * Creates a Socket connected to the given host and port.
57       * <p>
58       * @param address The address of the host to connect to.
59       * @param port The port to connect to.
60       * @return A Socket connected to the given host and port.
61       * @exception IOException If an I/O error occurs while creating the Socket.
62       ***/
63      public Socket createSocket(InetAddress address, int port)
64      throws IOException;
65  
66  
67      /***
68       * Creates a Socket connected to the given host and port and
69       * originating from the specified local address and port.
70       * <p>
71       * @param host The hostname to connect to.
72       * @param port The port to connect to.
73       * @param localAddr  The local address to use.
74       * @param localPort  The local port to use.
75       * @return A Socket connected to the given host and port.
76       * @exception UnknownHostException  If the hostname cannot be resolved.
77       * @exception IOException If an I/O error occurs while creating the Socket.
78       ***/
79      public Socket createSocket(String host, int port, InetAddress localAddr,
80                                 int localPort)
81      throws UnknownHostException, IOException;
82  
83      /***
84       * Creates a Socket connected to the given host and port and
85       * originating from the specified local address and port.
86       * <p>
87       * @param address The address of the host to connect to.
88       * @param port The port to connect to.
89       * @param localAddr  The local address to use.
90       * @param localPort  The local port to use.
91       * @return A Socket connected to the given host and port.
92       * @exception IOException If an I/O error occurs while creating the Socket.
93       ***/
94      public Socket createSocket(InetAddress address, int port,
95                                 InetAddress localAddr, int localPort)
96      throws IOException;
97  
98      /***
99       * Creates a ServerSocket bound to a specified port.  A port
100      * of 0 will create the ServerSocket on a system-determined free port.
101      * <p>
102      * @param port  The port on which to listen, or 0 to use any free port.
103      * @return A ServerSocket that will listen on a specified port.
104      * @exception IOException If an I/O error occurs while creating
105      *                        the ServerSocket.
106      ***/
107     public ServerSocket createServerSocket(int port) throws IOException;
108 
109     /***
110      * Creates a ServerSocket bound to a specified port with a given
111      * maximum queue length for incoming connections.  A port of 0 will
112      * create the ServerSocket on a system-determined free port.
113      * <p>
114      * @param port  The port on which to listen, or 0 to use any free port.
115      * @param backlog  The maximum length of the queue for incoming connections.
116      * @return A ServerSocket that will listen on a specified port.
117      * @exception IOException If an I/O error occurs while creating
118      *                        the ServerSocket.
119      ***/
120     public ServerSocket createServerSocket(int port, int backlog)
121     throws IOException;
122 
123     /***
124      * Creates a ServerSocket bound to a specified port on a given local
125      * address with a given maximum queue length for incoming connections.
126      * A port of 0 will
127      * create the ServerSocket on a system-determined free port.
128      * <p>
129      * @param port  The port on which to listen, or 0 to use any free port.
130      * @param backlog  The maximum length of the queue for incoming connections.
131      * @param bindAddr  The local address to which the ServerSocket should bind.
132      * @return A ServerSocket that will listen on a specified port.
133      * @exception IOException If an I/O error occurs while creating
134      *                        the ServerSocket.
135      ***/
136     public ServerSocket createServerSocket(int port, int backlog,
137                                            InetAddress bindAddr)
138     throws IOException;
139 }