Most visited

Recently visited

Added in API level 24

NetworkChannel

public interface NetworkChannel
implements Channel

java.nio.channels.NetworkChannel
Known Indirect Subclasses


通往网络套接字的通道。

实现此接口的通道是通往网络套接字的通道。 bind方法用于套接字绑定到本地address ,所述getLocalAddress方法返回套接字绑定到的地址,所述setOptiongetOption方法用于设置和查询套接字选项。 该接口的实现应该指定它支持的套接字选项。

指定不具有返回值的bindsetOption方法以返回调用它们的网络通道。 这允许方法调用被链接。 这个接口的实现应该专注于返回类型,以便实现类的方法调用可以链接在一起。

Summary

Public methods

abstract NetworkChannel bind(SocketAddress local)

将通道的套接字绑定到本地地址。

abstract SocketAddress getLocalAddress()

返回此通道套接字绑定的套接字地址,如果套接字未绑定,则 null

abstract <T> T getOption(SocketOption<T> name)

返回套接字选项的值。

abstract <T> NetworkChannel setOption(SocketOption<T> name, T value)

设置套接字选项的值。

abstract Set<SocketOption<?>> supportedOptions()

返回此通道支持的一组套接字选项。

Inherited methods

From interface java.nio.channels.Channel
From interface java.io.Closeable
From interface java.lang.AutoCloseable

Public methods

bind

Added in API level 24
NetworkChannel bind (SocketAddress local)

将通道的套接字绑定到本地地址。

此方法用于在套接字和本地地址之间建立关联。 一旦建立了关联,套接字就会保持绑定状态,直到通道关闭。 如果local参数的值为null则套接字将被绑定到自动分配的地址。

Parameters
local SocketAddress: The address to bind the socket, or null to bind the socket to an automatically assigned socket address
Returns
NetworkChannel This channel
Throws
AlreadyBoundException If the socket is already bound
UnsupportedAddressTypeException If the type of the given address is not supported
ClosedChannelException If the channel is closed
IOException If some other I/O error occurs
SecurityException If a security manager is installed and it denies an unspecified permission. An implementation of this interface should specify any required permissions.

也可以看看:

getLocalAddress

Added in API level 24
SocketAddress getLocalAddress ()

返回此通道套接字绑定的套接字地址,如果套接字未绑定,则 null

如果通道是 bound到Internet协议套接字地址,则此方法的返回值是类型 InetSocketAddress

Returns
SocketAddress The socket address that the socket is bound to, or null if the channel's socket is not bound
Throws
ClosedChannelException If the channel is closed
IOException If an I/O error occurs

getOption

Added in API level 24
T getOption (SocketOption<T> name)

返回套接字选项的值。

Parameters
name SocketOption: The socket option
Returns
T The value of the socket option. A value of null may be a valid value for some socket options.
Throws
UnsupportedOperationException If the socket option is not supported by this channel
ClosedChannelException If this channel is closed
IOException If an I/O error occurs

也可以看看:

setOption

Added in API level 24
NetworkChannel setOption (SocketOption<T> name, 
                T value)

设置套接字选项的值。

Parameters
name SocketOption: The socket option
value T: The value of the socket option. A value of null may be a valid value for some socket options.
Returns
NetworkChannel This channel
Throws
UnsupportedOperationException If the socket option is not supported by this channel
IllegalArgumentException If the value is not a valid value for this socket option
ClosedChannelException If this channel is closed
IOException If an I/O error occurs

也可以看看:

supportedOptions

Added in API level 24
Set<SocketOption<?>> supportedOptions ()

返回此通道支持的一组套接字选项。

即使通道已关闭,此方法仍会继续返回选项集。

Returns
Set<SocketOption<?>> A set of the socket options supported by this channel

Hooray!