Most visited

Recently visited

Added in API level 1

SocketFactory

public abstract class SocketFactory
extends Object

java.lang.Object
   ↳ javax.net.SocketFactory
Known Direct Subclasses
Known Indirect Subclasses


这个类创建套接字。 它可能被其他工厂子类化,这些工厂创建套接字的特定子类,从而为添加公共套接字级功能提供了一个通用框架。

套接字工厂是捕获与正在构建的套接字有关的各种策略的简单方法,以不需要特殊配置要求套接字的代码的方式生成这样的套接字:

工厂类由环境特定的配置机制指定。 例如, getDefault方法可以返回一个适合特定用户或applet的工厂,并且框架可以使用根据自己的用途进行定制的工厂。

也可以看看:

Summary

Protected constructors

SocketFactory()

创建一个 SocketFactory

Public methods

abstract Socket createSocket(String host, int port)

创建套接字并将其连接到指定远程端口上的指定远程主机。

abstract Socket createSocket(InetAddress host, int port)

创建一个套接字并将其连接到指定地址的指定端口号。

abstract Socket createSocket(InetAddress address, int port, InetAddress localAddress, int localPort)

创建套接字并将其连接到指定远程端口上的指定远程地址。

abstract Socket createSocket(String host, int port, InetAddress localHost, int localPort)

创建套接字并将其连接到指定远程端口上的指定远程主机。

Socket createSocket()

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

static SocketFactory getDefault()

返回环境默认套接字工厂的副本。

Inherited methods

From class java.lang.Object

Protected constructors

SocketFactory

Added in API level 1
SocketFactory ()

创建一个 SocketFactory

Public methods

createSocket

Added in API level 1
Socket createSocket (String host, 
                int port)

创建套接字并将其连接到指定远程端口上的指定远程主机。 该套接字使用为该工厂建立的套接字选项进行配置。

如果有安全管理器,则使用主机地址和port作为参数调用其checkConnect方法。 这可能会导致SecurityException。

Parameters
host String: the server host name with which to connect, or null for the loopback address.
port int: the server port
Returns
Socket the Socket
Throws
IOException if an I/O error occurs when creating the socket
SecurityException if a security manager exists and its checkConnect method doesn't allow the operation.
UnknownHostException if the host is not known
IllegalArgumentException if the port parameter is outside the specified range of valid port values, which is between 0 and 65535, inclusive.

也可以看看:

createSocket

Added in API level 1
Socket createSocket (InetAddress host, 
                int port)

创建一个套接字并将其连接到指定地址的指定端口号。 该套接字使用为该工厂建立的套接字选项进行配置。

如果有安全管理器, checkConnect主机地址和port作为参数调用其checkConnect方法。 这可能会导致SecurityException。

Parameters
host InetAddress: the server host
port int: the server port
Returns
Socket the Socket
Throws
IOException if an I/O error occurs when creating the socket
SecurityException if a security manager exists and its checkConnect method doesn't allow the operation.
IllegalArgumentException if the port parameter is outside the specified range of valid port values, which is between 0 and 65535, inclusive.
NullPointerException if host is null.

也可以看看:

createSocket

Added in API level 1
Socket createSocket (InetAddress address, 
                int port, 
                InetAddress localAddress, 
                int localPort)

创建套接字并将其连接到指定远程端口上的指定远程地址。 套接字也将被绑定到本地地址和端口。 套接字使用为此工厂建立的套接字选项进行配置。

如果有安全管理器, checkConnect主机地址和port作为参数调用其checkConnect方法。 这可能会导致SecurityException。

Parameters
address InetAddress: the server network address
port int: the server port
localAddress InetAddress: the client network address
localPort int: the client port
Returns
Socket the Socket
Throws
IOException if an I/O error occurs when creating the socket
SecurityException if a security manager exists and its checkConnect method doesn't allow the operation.
IllegalArgumentException if the port parameter or localPort parameter is outside the specified range of valid port values, which is between 0 and 65535, inclusive.
NullPointerException if address is null.

也可以看看:

createSocket

Added in API level 1
Socket createSocket (String host, 
                int port, 
                InetAddress localHost, 
                int localPort)

创建套接字并将其连接到指定远程端口上的指定远程主机。 套接字也将被绑定到本地地址和提供的端口。 该套接字使用为该工厂建立的套接字选项进行配置。

如果有安全管理器, checkConnect主机地址和port作为参数调用其checkConnect方法。 这可能会导致SecurityException。

Parameters
host String: the server host name with which to connect, or null for the loopback address.
port int: the server port
localHost InetAddress: the local address the socket is bound to
localPort int: the local port the socket is bound to
Returns
Socket the Socket
Throws
IOException if an I/O error occurs when creating the socket
SecurityException if a security manager exists and its checkConnect method doesn't allow the operation.
UnknownHostException if the host is not known
IllegalArgumentException if the port parameter or localPort parameter is outside the specified range of valid port values, which is between 0 and 65535, inclusive.

也可以看看:

createSocket

Added in API level 1
Socket createSocket ()

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

Returns
Socket the unconnected socket
Throws
IOException if the socket cannot be created

也可以看看:

getDefault

Added in API level 1
SocketFactory getDefault ()

返回环境默认套接字工厂的副本。

Returns
SocketFactory the default SocketFactory

Hooray!