public interface NetworkChannel extends Channel
实现此接口的一个通道是网络套接字的一个通道。的bind
法将套接字绑定到本地的address
,getLocalAddress
方法返回的socket地址,和setOption
和getOption
方法用于设置和查询套接字选项。此接口的实现应指定它支持的套接字选项。
的bind
和setOption
方法,否则不具备返回的值是指定的返回网络渠道在它们被调用。这允许方法调用被。实现这个接口应该专门的返回类型,在实现类中的方法调用可以链接。
Modifier and Type | Method and Description |
---|---|
NetworkChannel |
bind(SocketAddress local)
将信道的套接字绑定到本地地址。
|
SocketAddress |
getLocalAddress()
返回此通道的套接字绑定到的套接字地址。
|
<T> T |
getOption(SocketOption<T> name)
返回套接字选项的值。
|
<T> NetworkChannel |
setOption(SocketOption<T> name, T value)
设置套接字选项的值。
|
Set<SocketOption<?>> |
supportedOptions()
返回此通道所支持的套接字选项集的集合。
|
NetworkChannel bind(SocketAddress local) throws IOException
此方法用于建立套接字和本地地址之间的关联。一旦一个关联建立,那么套接字保持绑定,直到通道关闭。如果local
参数的值null
然后插座将绑定到一个地址的自动分配。
local
-地址绑定套接字,或者
null
绑定socket套接字地址的自动分配
AlreadyBoundException
如果插座已绑定
UnsupportedAddressTypeException
如果给定的地址的类型不支持
ClosedChannelException
如果通道关闭
IOException
-如果其他I/O错误发生
SecurityException
如果安全管理器安装和否定一个未指定的权限。此接口的实现应指定任何所需的权限。
getLocalAddress()
SocketAddress getLocalAddress() throws IOException
在渠道bound
到互联网协议的套接字地址然后从这个方法返回值的类型是InetSocketAddress
。
null
如果信道的插座是不受约束的
ClosedChannelException
如果通道关闭
IOException
如果I/O错误发生
<T> NetworkChannel setOption(SocketOption<T> name, T value) throws IOException
T
的套接字选项的值的类型
name
的套接字选项
value
-套接字选项的值。一个价值
null
可能对于一些套接字选项的有效值。
UnsupportedOperationException
如果套接字选项不支持这个频道
IllegalArgumentException
-如果值不是此套接字选项的有效值
ClosedChannelException
-如果这通道关闭
IOException
如果I/O错误发生
StandardSocketOptions
<T> T getOption(SocketOption<T> name) throws IOException
T
的套接字选项的值的类型
name
的套接字选项
null
可能对于一些套接字选项的有效值。
UnsupportedOperationException
如果套接字选项不支持这个频道
ClosedChannelException
-如果这通道关闭
IOException
如果I/O错误发生
StandardSocketOptions
Set<SocketOption<?>> supportedOptions()
该方法将继续返回一组选项,即使通道已经关闭了。
Submit a bug or feature
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 1993, 2014, Oracle and/or its affiliates. All rights reserved.