public interface NetworkChannel
implements Channel
| java.nio.channels.NetworkChannel |
| |
通往网络套接字的通道。
实现此接口的通道是通往网络套接字的通道。 该bind方法用于套接字绑定到本地address ,所述getLocalAddress方法返回套接字绑定到的地址,所述setOption种getOption方法用于设置和查询套接字选项。 该接口的实现应该指定它支持的套接字选项。
指定不具有返回值的bind和setOption方法以返回调用它们的网络通道。 这允许方法调用被链接。 这个接口的实现应该专注于返回类型,以便实现类的方法调用可以链接在一起。
Public methods |
|
|---|---|
abstract NetworkChannel |
bind(SocketAddress local) 将通道的套接字绑定到本地地址。 |
abstract SocketAddress |
getLocalAddress() 返回此通道套接字绑定的套接字地址,如果套接字未绑定,则 |
abstract <T> T |
getOption(SocketOption<T> name) 返回套接字选项的值。 |
abstract <T> NetworkChannel |
setOption(SocketOption<T> name, T value) 设置套接字选项的值。 |
abstract Set<SocketOption<?>> |
supportedOptions() 返回此通道支持的一组套接字选项。 |
Inherited methods |
|
|---|---|
java.nio.channels.Channel
|
|
java.io.Closeable
|
|
java.lang.AutoCloseable
|
|
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. |
也可以看看:
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 |
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 |
也可以看看:
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 |
也可以看看:
Set<SocketOption<?>> supportedOptions ()
返回此通道支持的一组套接字选项。
即使通道已关闭,此方法仍会继续返回选项集。
| Returns | |
|---|---|
Set<SocketOption<?>> |
A set of the socket options supported by this channel |