An asynchronous server-socket channel is created by invoking the
open method of this class.
A newly-created asynchronous server-socket channel is open but not yet bound.
It can be bound to a local address and configured to listen for connections
by invoking the bind method. Once bound,
the accept method
is used to initiate the accepting of connections to the channel's socket.
An attempt to invoke the accept method on an unbound channel will
cause a NotYetBoundException to be thrown.
Channels of this type are safe for use by multiple concurrent threads
though at most one accept operation can be outstanding at any time.
If a thread initiates an accept operation before a previous accept operation
has completed then an AcceptPendingException will be thrown.
Socket options are configured using the setOption method. Channels of this type support the following options:
Additional (implementation specific) options may also be supported.
Option Name Description SO_RCVBUFThe size of the socket receive buffer SO_REUSEADDRRe-use address
Usage Example:
final AsynchronousServerSocketChannel listener = AsynchronousServerSocketChannel.open().bind(new InetSocketAddress(5000)); listener.accept(null, new CompletionHandler<AsynchronousSocketChannel,Void>() { public void completed(AsynchronousSocketChannel ch, Void att) { // accept the next connection listener.accept(null, this); // handle this connection handle(ch); } public void failed(Throwable exc, Void att) { ... } });
| Modifier and Type | Field and Description |
|---|---|
| private final AsynchronousChannelProvider |
| Access | Constructor and Description |
|---|---|
| protected | AsynchronousServerSocketChannel(AsynchronousChannelProvider
The provider that created this channel provider)Initializes a new instance of this class. |
| Modifier and Type | Method and Description |
|---|---|
| public abstract < The type of the attachment A> void | accept(A
The object to attach to the I/O operation; can be attachment, CompletionHandler<AsynchronousSocketChannel, ? super A> nullThe handler for consuming the result handler)Accepts a connection. |
| public abstract Future | |
| public final AsynchronousServerSocketChannel | Returns: This channelThe local address to bind the socket, or local)null to bind
to an automatically assigned socket addressImplements java. Binds the channel's socket to a local address and configures the socket to listen for connections. |
| public abstract AsynchronousServerSocketChannel | Returns: This channelThe local address to bind the socket, or local, int null to bind
to an automatically assigned socket addressThe maximum number of pending connections backlog)Binds the channel's socket to a local address and configures the socket to listen for connections. |
| public abstract SocketAddress | Returns: TheSocketAddress that the socket is bound to; null
if the channel's socket is not boundRedeclares java. Returns the socket address that this channel's socket is bound to. |
| public static AsynchronousServerSocketChannel | Returns: A new asynchronous server socket channelThe group to which the newly constructed channel should be bound,
or group)null for the default groupOpens an asynchronous server-socket channel. |
| public static AsynchronousServerSocketChannel | |
| public final AsynchronousChannelProvider | Returns: The provider that created this channelReturns the provider that created this channel. |
| public abstract <T> AsynchronousServerSocketChannel | setOption(SocketOption<T> name, T value)
Redeclares java. Sets the value of a socket option. |
| provider | back to summary |
|---|---|
| private final AsynchronousChannelProvider provider | |
| AsynchronousServerSocketChannel | back to summary |
|---|---|
| protected AsynchronousServerSocketChannel(AsynchronousChannelProvider provider) Initializes a new instance of this class.
| |
| accept | back to summary |
|---|---|
| public abstract <A> void accept(A attachment, CompletionHandler<AsynchronousSocketChannel, ? super A> handler) Accepts a connection. This method initiates an asynchronous operation to accept a
connection made to this channel's socket. The When a new connection is accepted then the resulting To allow for concurrent handling of new connections, the completion handler is not invoked directly by the initiating thread when a new connection is accepted immediately (see Threading).
| |
| accept | back to summary |
|---|---|
| public abstract Future Accepts a connection. This method initiates an asynchronous operation to accept a
connection made to this channel's socket. The method behaves in exactly
the same manner as the
| |
| bind | back to summary |
|---|---|
| public final AsynchronousServerSocketChannel bind(SocketAddress local) throws IOException Implements java. Binds the channel's socket to a local address and configures the socket to listen for connections. An invocation of this method is equivalent to the following: bind(local, 0);
| |
| bind | back to summary |
|---|---|
| public abstract AsynchronousServerSocketChannel bind(SocketAddress local, int backlog) throws IOException Binds the channel's socket to a local address and configures the socket to listen for connections. This method is used to establish an association between the socket and a local address. Once an association is established then the socket remains bound until the associated channel is closed. The
| |
| getLocalAddress | back to summary |
|---|---|
| public abstract SocketAddress getLocalAddress() throws IOException Redeclares java. Doc from java. Returns the socket address that this channel's socket is bound to. Where the channel is
| |
| open | back to summary |
|---|---|
| public static AsynchronousServerSocketChannel open(AsynchronousChannelGroup group) throws IOException Opens an asynchronous server-socket channel. The new channel is created by invoking the
| |
| open | back to summary |
|---|---|
| public static AsynchronousServerSocketChannel open() throws IOException Opens an asynchronous server-socket channel. This method returns an asynchronous server socket channel that is bound to the default group. This method is equivalent to evaluating the expression: open((AsynchronousChannelGroup)null);
| |
| provider | back to summary |
|---|---|
| public final AsynchronousChannelProvider provider() Returns the provider that created this channel.
| |
| setOption | back to summary |
|---|---|
| public abstract <T> AsynchronousServerSocketChannel setOption(SocketOption<T> name, T value) throws IOException Redeclares java. Doc from java. Sets the value of a socket option.
| |