java.nio.channels.ServerSocketChannel

public abstract class
ServerSocketChannel
extends AbstractSelectableChannel
java.lang.Object
? java.nio.channels.spi.AbstractInterruptibleChannel
? java.nio.channels.SelectableChannel
? java.nio.channels.spi.AbstractSelectableChannel
? java.nio.channels.ServerSocketChannel


Class Overview

A ServerSocketChannel is a partial abstraction of a selectable, stream-oriented listening socket. Binding and manipulation of socket options can only be done through the associated ServerSocket object, returned by calling socket(). ServerSocketChannels can not be constructed for an already existing server-socket, nor can a SocketImpl be assigned.
一个ServerSocketChannel是一个partial abstraction of a selectable,面向流的监听socket。绑定和操纵socket只能通过ServerSocket对象,由调用socket()方法。
ServerSocketChannels不能由已经创建的server-socket构造,也不能由SocketImpl分配。

A server-socket channel is open but not bound when created by the open() method. Calling accept before bound will cause a NotYetBoundException. It can be bound by calling the bind method of a related ServerSocket instance.
调用open()创建server-socket通道,此时server-socket通道处于打开但是未绑定状态。此时调用accept方法会导致NotYetBoundException异常。
(备注:试图在尚未绑定的服务器套接字通道上调用 I/O 操作时,抛出此未经检查的异常。)使用bind方法可以将server-socket channel绑定到对应的ServerSocket实例。

Summary

Protected Constructors
ServerSocketChannel(SelectorProvider selectorProvider)
Constructs a new ServerSocketChannel.
构造一个新的ServerSocketChannel.

Public Methods
abstract SocketChannel accept()
Accepts a connection to this server-socket channel.
接收一个到该服务端channel的连接。

static ServerSocketChannel open()
Creates an open and unbound server-socket channel.
创建一个打开但是未绑定的服务端channel。

abstract ServerSocket socket()
Return the server-socket assigned this channel, which does not declare any public methods that are not declared in ServerSocket.
返回一个分配给该channel的服务端socket。...

final int validOps()
Gets the valid operations of this channel.
获取该channel的可执行操作。

[Expand]
Inherited Methods
From class java.nio.channels.spi.AbstractSelectableChannel
From class java.nio.channels.SelectableChannel
From class java.nio.channels.spi.AbstractInterruptibleChannel
From class java.lang.Object
From interface java.io.Closeable
From interface java.nio.channels.Channel
From interface java.nio.channels.InterruptibleChannel
Protected Constructors

protected ServerSocketChannel (SelectorProvider selectorProvider)
Since: API Level 1
Constructs a new ServerSocketChannel.
Parameters
selectorProvider an instance of SelectorProvider.
一个SelectorProvider实例。该实例由SelectorProvider的一个静态方法提供。

Public Methods

public abstract SocketChannel accept ()
Since: API Level 1
Accepts a connection to this server-socket channel.
This method returns null when this channel is non-blocking and no connection is available, otherwise it blocks until a new connection is available or an I/O error occurs. The socket channel returned by this method will always be in blocking mode.
This method just executes the same security checks as the accept() method of the ServerSocket class.
接收到该channel的连接。当无连接可用且该channel处于非阻塞状态时,该方法返回null;否则channel将一直阻塞直到一个新的可用连接出现或者发生I/O错误。
由该方法返回的socket channel将一直处于阻塞模式。
该方法进行的安全检查和ServerSocket的accept()方法相同。
Returns
the accepted SocketChannel instance, or null if the channel is non-blocking and no connection is available.
接收到的SocketChannel实例,否则:
null channel处于非阻塞模式且无连接可用。
Throws
AsynchronousCloseException if this channel is closed by another thread while this method is in operation.
ClosedByInterruptException if another thread interrupts the calling thread while this operation is in progress. The interrupt state of the calling thread is set and the channel is closed.
ClosedChannelException if this channel is closed.
IOException if another I/O error occurs.
NotYetBoundException if the socket has not yet been bound.
socket尚未绑定。
SecurityException if there is a security manager and it does not permit to access the new connection.
安全管理员不允许接收新连接。

public static ServerSocketChannel open ()
Since: API Level 1
Creates an open and unbound server-socket channel.
This channel is created by calling openServerSocketChannel method of the default SelectorProvider instance.
Returns
创建未绑定服务端channel。
channel通过调用默认的SelectorProvider实例的openServerSocketChannel方法创建。
the new channel which is open but unbound.
Throws
IOException if an I/O error occurs.

public abstract ServerSocket socket ()
Since: API Level 1
Return the server-socket assigned this channel, which does not declare any public methods that are not declared in ServerSocket.
返回分配给该channel的server-socket。...
Returns
the server-socket assigned to this channel.

public final int validOps ()
Since: API Level 1
Gets the valid operations of this channel. Server-socket channels support accepting operation, so this method returns SelectionKey.OP_ACCEPT.
获取可以操作,包括SelectionKey.OP_ACCEPT.
Returns
the operations supported by this channel.
See Also
validOps()
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值