    View Javadoc
    1   package org.apache.commons.net;
    2
    3   /* ====================================================================
    4    * The Apache Software License, Version 1.1
    5    *
    6    * Copyright (c) 2001 The Apache Software Foundation.  All rights
    7    * reserved.
    8    *
    9    * Redistribution and use in source and binary forms, with or without
    10   * modification, are permitted provided that the following conditions
    11   * are met:
    12   *
    13   * 1. Redistributions of source code must retain the above copyright
    14   *    notice, this list of conditions and the following disclaimer.
    15   *
    16   * 2. Redistributions in binary form must reproduce the above copyright
    17   *    notice, this list of conditions and the following disclaimer in
    18   *    the documentation and/or other materials provided with the
    19   *    distribution.
    20   *
    21   * 3. The end-user documentation included with the redistribution,
    22   *    if any, must include the following acknowledgment:
    23   *       "This product includes software developed by the
    24   *        Apache Software Foundation (http://www.apache.org/)."
    25   *    Alternately, this acknowledgment may appear in the software itself,
    26   *    if and wherever such third-party acknowledgments normally appear.
    27   *
    28   * 4. The names "Apache" and "Apache Software Foundation" and
    29   *    "Apache Commons" must not be used to endorse or promote products
    30   *    derived from this software without prior written permission. For
    31   *    written permission, please contact apache@apache.org.
    32   *
    33   * 5. Products derived from this software may not be called "Apache",
    34   *    nor may "Apache" appear in their name, without
    35   *    prior written permission of the Apache Software Foundation.
    36   *
    37   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
    38   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
    39   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
    40   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
    41   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
    42   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
    43   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
    44   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
    45   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
    46   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
    47   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
    48   * SUCH DAMAGE.
    49   * ====================================================================
    50   *
    51   * This software consists of voluntary contributions made by many
    52   * individuals on behalf of the Apache Software Foundation.  For more
    53   * information on the Apache Software Foundation, please see
    54   * <http://www.apache.org/>;.
    55   */
    56
    57  import java.io.IOException;
    58  import java.net.InetAddress;
    59  import java.net.ServerSocket;
    60  import java.net.Socket;
    61  import java.net.UnknownHostException;
    62
    63  /****
    64   * DefaultSocketFactory implements the SocketFactory interface by
    65   * simply wrapping the java.net.Socket and java.net.ServerSocket
    66   * constructors.  It is the default SocketFactory used by
    67   * <a href="org.apache.commons.net.SocketClient.html"> SocketClient </a>
    68   * implementations.
    69   * <p>
    70   * <p>
    71   * @author Daniel F. Savarese
    72   * @see SocketFactory
    73   * @see SocketClient
    74   * @see SocketClient#setSocketFactory
    75   ***/
    76
    77  public class DefaultSocketFactory implements SocketFactory
    78  {
    79
    80      /****
    81       * Creates a Socket connected to the given host and port.
    82       * <p>
    83       * @param host The hostname to connect to.
    84       * @param port The port to connect to.
    85       * @return A Socket connected to the given host and port.
    86       * @exception UnknownHostException  If the hostname cannot be resolved.
    87       * @exception IOException If an I/O error occurs while creating the Socket.
    88       ***/
    89      public Socket createSocket(String host, int port)
    90      throws UnknownHostException, IOException
    91      {
    92          return new Socket(host, port);
    93      }
    94
    95      /****
    96       * Creates a Socket connected to the given host and port.
    97       * <p>
    98       * @param address The address of the host to connect to.
    99       * @param port The port to connect to.
    100      * @return A Socket connected to the given host and port.
    101      * @exception IOException If an I/O error occurs while creating the Socket.
    102      ***/
    103     public Socket createSocket(InetAddress address, int port)
    104     throws IOException
    105     {
    106         return new Socket(address, port);
    107     }
    108
    109     /****
    110      * Creates a Socket connected to the given host and port and
    111      * originating from the specified local address and port.
    112      * <p>
    113      * @param host The hostname to connect to.
    114      * @param port The port to connect to.
    115      * @param localAddr  The local address to use.
    116      * @param localPort  The local port to use.
    117      * @return A Socket connected to the given host and port.
    118      * @exception UnknownHostException  If the hostname cannot be resolved.
    119      * @exception IOException If an I/O error occurs while creating the Socket.
    120      ***/
    121     public Socket createSocket(String host, int port,
    122                                InetAddress localAddr, int localPort)
    123     throws UnknownHostException, IOException
    124     {
    125         return new Socket(host, port, localAddr, localPort);
    126     }
    127
    128     /****
    129      * Creates a Socket connected to the given host and port and
    130      * originating from the specified local address and port.
    131      * <p>
    132      * @param address The address of the host to connect to.
    133      * @param port The port to connect to.
    134      * @param localAddr  The local address to use.
    135      * @param localPort  The local port to use.
    136      * @return A Socket connected to the given host and port.
    137      * @exception IOException If an I/O error occurs while creating the Socket.
    138      ***/
    139     public Socket createSocket(InetAddress address, int port,
    140                                InetAddress localAddr, int localPort)
    141     throws IOException
    142     {
    143         return new Socket(address, port, localAddr, localPort);
    144     }
    145
    146     /****
    147      * Creates a ServerSocket bound to a specified port.  A port
    148      * of 0 will create the ServerSocket on a system-determined free port.
    149      * <p>
    150      * @param port  The port on which to listen, or 0 to use any free port.
    151      * @return A ServerSocket that will listen on a specified port.
    152      * @exception IOException If an I/O error occurs while creating
    153      *                        the ServerSocket.
    154      ***/
    155     public ServerSocket createServerSocket(int port) throws IOException
    156     {
    157         return new ServerSocket(port);
    158     }
    159
    160     /****
    161      * Creates a ServerSocket bound to a specified port with a given
    162      * maximum queue length for incoming connections.  A port of 0 will
    163      * create the ServerSocket on a system-determined free port.
    164      * <p>
    165      * @param port  The port on which to listen, or 0 to use any free port.
    166      * @param backlog  The maximum length of the queue for incoming connections.
    167      * @return A ServerSocket that will listen on a specified port.
    168      * @exception IOException If an I/O error occurs while creating
    169      *                        the ServerSocket.
    170      ***/
    171     public ServerSocket createServerSocket(int port, int backlog)
    172     throws IOException
    173     {
    174         return new ServerSocket(port, backlog);
    175     }
    176
    177     /****
    178      * Creates a ServerSocket bound to a specified port on a given local
    179      * address with a given maximum queue length for incoming connections.
    180      * A port of 0 will
    181      * create the ServerSocket on a system-determined free port.
    182      * <p>
    183      * @param port  The port on which to listen, or 0 to use any free port.
    184      * @param backlog  The maximum length of the queue for incoming connections.
    185      * @param bindAddr  The local address to which the ServerSocket should bind.
    186      * @return A ServerSocket that will listen on a specified port.
    187      * @exception IOException If an I/O error occurs while creating
    188      *                        the ServerSocket.
    189      ***/
    190     public ServerSocket createServerSocket(int port, int backlog,
    191                                            InetAddress bindAddr)
    192     throws IOException
    193     {
    194         return new ServerSocket(port, backlog, bindAddr);
    195     }
    196 }

This page was automatically generated by Maven