Most visited

Recently visited

Added in API level 1
Deprecated since API level 22

SocketFactory

public interface SocketFactory

org.apache.http.conn.scheme.SocketFactory
Known Indirect Subclasses


该接口在API级别22中已被弃用。
请改用openConnection() 请访问this webpage了解更多详情。

一个用于创建和连接套接字的工厂。 工厂封装了建立套接字连接的逻辑。
对于某些连接管理器的正确操作,必须重写Object.equals()Object.hashCode()

Summary

Public methods

abstract Socket connectSocket(Socket sock, String host, int port, InetAddress localAddress, int localPort, HttpParams params)

将套接字连接到给定的主机。

abstract Socket createSocket()

创建一个新的未连接的套接字。

abstract boolean isSecure(Socket sock)

检查套接字是否提供安全连接。

Public methods

connectSocket

Added in API level 1
Socket connectSocket (Socket sock, 
                String host, 
                int port, 
                InetAddress localAddress, 
                int localPort, 
                HttpParams params)

将套接字连接到给定的主机。

Parameters
sock Socket: the socket to connect, as obtained from createSocket. null indicates that a new socket should be created and connected.
host String: the host to connect to
port int: the port to connect to on the host
localAddress InetAddress: the local address to bind the socket to, or null for any
localPort int: the port on the local machine, 0 or a negative number for any
params HttpParams: additional parameters for connecting
Returns
Socket 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

createSocket

Added in API level 1
Socket createSocket ()

创建一个新的未连接的套接字。 随后应该将该套接字传递给connectSocket

Returns
Socket a new socket
Throws
IOException if an I/O error occurs while creating the socket

isSecure

Added in API level 1
boolean isSecure (Socket sock)

检查套接字是否提供安全连接。 该工厂的插座必须是connected 该工厂不会执行此方法的I / O操作。
根据经验,普通套接字不安全,TLS / SSL套接字是安全的。 但是,可能存在应用程序特定的偏差。 例如,在同一个Intranet(“信任区域”)中的主机的简单套接字可以被认为是安全的。 另一方面,基于为连接选择的密码套件,TLS / SSL套接字可能被认为是不安全的。

Parameters
sock Socket: the connected socket to check
Returns
boolean true if the connection of the socket should be considered secure, or false if it should not
Throws
IllegalArgumentException if the argument is invalid, for example because it is not a connected socket or was created by a different socket factory. Note that socket factories are not required to check these conditions, they may simply return a default value when called with an invalid socket argument.

Hooray!