Class PlainSocketFactory

java.lang.Object
org.apache.http.conn.scheme.PlainSocketFactory
All Implemented Interfaces:
SocketFactory

public final class PlainSocketFactory
extends Object
implements SocketFactory
The default class for creating sockets.
Author:
Roland Weber, Michael Becke
  • Constructor Details

    • PlainSocketFactory

      public PlainSocketFactory​(HostNameResolver nameResolver)
    • PlainSocketFactory

      public PlainSocketFactory()
  • Method Details

    • getSocketFactory

      public static PlainSocketFactory getSocketFactory()
      Gets the singleton instance of this class.
      Returns:
      the one and only plain socket factory
    • createSocket

      public Socket createSocket()
      Description copied from interface: SocketFactory
      Creates a new, unconnected socket. The socket should subsequently be passed to connectSocket.
      Specified by:
      createSocket in interface SocketFactory
      Returns:
      a new socket
    • connectSocket

      public Socket connectSocket​(Socket sock, String host, int port, InetAddress localAddress, int localPort, HttpParams params) throws IOException
      Description copied from interface: SocketFactory
      Connects a socket to the given host.
      Specified by:
      connectSocket in interface SocketFactory
      Parameters:
      sock - the socket to connect, as obtained from createSocket. null indicates that a new socket should be created and connected.
      host - the host to connect to
      port - the port to connect to on the host
      localAddress - the local address to bind the socket to, or null for any
      localPort - the port on the local machine, 0 or a negative number for any
      params - additional parameters for connecting
      Returns:
      the connected socket. The returned object may be different from the sock argument if this factory supports a layered protocol.
      Throws:
      IOException - if an I/O error occurs
      UnknownHostException - if the IP address of the target host can not be determined
      ConnectTimeoutException - if the socket cannot be connected within the time limit defined in the params
    • isSecure

      public final boolean isSecure​(Socket sock) throws IllegalArgumentException
      Checks whether a socket connection is secure. This factory creates plain socket connections which are not considered secure.
      Specified by:
      isSecure in interface SocketFactory
      Parameters:
      sock - the connected socket
      Returns:
      false
      Throws:
      IllegalArgumentException - if the argument is invalid
    • equals

      public boolean equals​(Object obj)
      Compares this factory with an object. There is only one instance of this class.
      Overrides:
      equals in class Object
      Parameters:
      obj - the object to compare with
      Returns:
      iff the argument is this object
      See Also:
      Object.hashCode()
    • hashCode

      public int hashCode()
      Obtains a hash code for this object. All instances of this class have the same hash code. There is only one instance of this class.
      Overrides:
      hashCode in class Object
      Returns:
      this object's hash code.
      See Also:
      Object.equals(java.lang.Object)