DefaultSocketFactory
Date: 2016-06-23

org.apache.commons.net

## Class DefaultSocketFactory

- java.lang.Object
- - javax.net.SocketFactory
  - - org.apache.commons.net.DefaultSocketFactory

-     public class DefaultSocketFactory
      extends javax.net.SocketFactory

  DefaultSocketFactory implements the SocketFactory interface by simply wrapping the java.net.Socket and java.net.ServerSocket constructors. It is the default SocketFactory used by `SocketClient` implementations.
  See Also:
    `SocketFactory`, `SocketClient`, `SocketClient.setSocketFactory(javax.net.SocketFactory)`

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `DefaultSocketFactory()` The default constructor.
    `DefaultSocketFactory(java.net.Proxy proxy)` A constructor for sockets with proxy support.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `java.net.ServerSocket` | `createServerSocket(int port)` Creates a ServerSocket bound to a specified port.
    `java.net.ServerSocket` | `createServerSocket(int port, int backlog)` Creates a ServerSocket bound to a specified port with a given maximum queue length for incoming connections.
    `java.net.ServerSocket` | `createServerSocket(int port, int backlog, java.net.InetAddress bindAddr)` Creates a ServerSocket bound to a specified port on a given local address with a given maximum queue length for incoming connections.
    `java.net.Socket` | `createSocket()` Creates an unconnected Socket.
    `java.net.Socket` | `createSocket(java.net.InetAddress address, int port)` Creates a Socket connected to the given host and port.
    `java.net.Socket` | `createSocket(java.net.InetAddress address, int port, java.net.InetAddress localAddr, int localPort)` Creates a Socket connected to the given host and port and originating from the specified local address and port.
    `java.net.Socket` | `createSocket(java.lang.String host, int port)` Creates a Socket connected to the given host and port.
    `java.net.Socket` | `createSocket(java.lang.String host, int port, java.net.InetAddress localAddr, int localPort)` Creates a Socket connected to the given host and port and originating from the specified local address and port.

    - ### Methods inherited from class javax.net.SocketFactory

      `getDefault`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### DefaultSocketFactory

          public DefaultSocketFactory()

      The default constructor.

    - #### DefaultSocketFactory

          public DefaultSocketFactory(java.net.Proxy proxy)

      A constructor for sockets with proxy support.
      Parameters:
        `proxy` - The Proxy to use when creating new Sockets.
      Since:
        3.2

  - ### Method Detail

    - #### createSocket

          public java.net.Socket createSocket()
                                       throws java.io.IOException

      Creates an unconnected Socket.
      Overrides:
        `createSocket` in class `javax.net.SocketFactory`
      Returns:
        A new unconnected Socket.
      Throws:
        `java.io.IOException` - If an I/O error occurs while creating the Socket.
      Since:
        3.2

    - #### createSocket

          public java.net.Socket createSocket(java.lang.String host,
                                     int port)
                                       throws java.net.UnknownHostException,
                                              java.io.IOException

      Creates a Socket connected to the given host and port.
      Specified by:
        `createSocket` in class `javax.net.SocketFactory`
      Parameters:
        `host` - The hostname to connect to.
        `port` - The port to connect to.
      Returns:
        A Socket connected to the given host and port.
      Throws:
        `java.net.UnknownHostException` - If the hostname cannot be resolved.
        `java.io.IOException` - If an I/O error occurs while creating the Socket.

    - #### createSocket

          public java.net.Socket createSocket(java.net.InetAddress address,
                                     int port)
                                       throws java.io.IOException

      Creates a Socket connected to the given host and port.
      Specified by:
        `createSocket` in class `javax.net.SocketFactory`
      Parameters:
        `address` - The address of the host to connect to.
        `port` - The port to connect to.
      Returns:
        A Socket connected to the given host and port.
      Throws:
        `java.io.IOException` - If an I/O error occurs while creating the Socket.

    - #### createSocket

          public java.net.Socket createSocket(java.lang.String host,
                                     int port,
                                     java.net.InetAddress localAddr,
                                     int localPort)
                                       throws java.net.UnknownHostException,
                                              java.io.IOException

      Creates a Socket connected to the given host and port and originating from the specified local address and port.
      Specified by:
        `createSocket` in class `javax.net.SocketFactory`
      Parameters:
        `host` - The hostname to connect to.
        `port` - The port to connect to.
        `localAddr` - The local address to use.
        `localPort` - The local port to use.
      Returns:
        A Socket connected to the given host and port.
      Throws:
        `java.net.UnknownHostException` - If the hostname cannot be resolved.
        `java.io.IOException` - If an I/O error occurs while creating the Socket.

    - #### createSocket

          public java.net.Socket createSocket(java.net.InetAddress address,
                                     int port,
                                     java.net.InetAddress localAddr,
                                     int localPort)
                                       throws java.io.IOException

      Creates a Socket connected to the given host and port and originating from the specified local address and port.
      Specified by:
        `createSocket` in class `javax.net.SocketFactory`
      Parameters:
        `address` - The address of the host to connect to.
        `port` - The port to connect to.
        `localAddr` - The local address to use.
        `localPort` - The local port to use.
      Returns:
        A Socket connected to the given host and port.
      Throws:
        `java.io.IOException` - If an I/O error occurs while creating the Socket.

    - #### createServerSocket

          public java.net.ServerSocket createServerSocket(int port)
                                                   throws java.io.IOException

      Creates a ServerSocket bound to a specified port. A port of 0 will create the ServerSocket on a system-determined free port.
      Parameters:
        `port` - The port on which to listen, or 0 to use any free port.
      Returns:
        A ServerSocket that will listen on a specified port.
      Throws:
        `java.io.IOException` - If an I/O error occurs while creating the ServerSocket.

    - #### createServerSocket

          public java.net.ServerSocket createServerSocket(int port,
                                                 int backlog)
                                                   throws java.io.IOException

      Creates a ServerSocket bound to a specified port with a given maximum queue length for incoming connections. A port of 0 will create the ServerSocket on a system-determined free port.
      Parameters:
        `port` - The port on which to listen, or 0 to use any free port.
        `backlog` - The maximum length of the queue for incoming connections.
      Returns:
        A ServerSocket that will listen on a specified port.
      Throws:
        `java.io.IOException` - If an I/O error occurs while creating the ServerSocket.

    - #### createServerSocket

          public java.net.ServerSocket createServerSocket(int port,
                                                 int backlog,
                                                 java.net.InetAddress bindAddr)
                                                   throws java.io.IOException

      Creates a ServerSocket bound to a specified port on a given local address with a given maximum queue length for incoming connections. A port of 0 will create the ServerSocket on a system-determined free port.
      Parameters:
        `port` - The port on which to listen, or 0 to use any free port.
        `backlog` - The maximum length of the queue for incoming connections.
        `bindAddr` - The local address to which the ServerSocket should bind.
      Returns:
        A ServerSocket that will listen on a specified port.
      Throws:
        `java.io.IOException` - If an I/O error occurs while creating the ServerSocket.