JavaScript is disabled on your browser.
Java™ Platform
Standard Ed. 7
java.nio.channels

Class AsynchronousServerSocketChannel

  • All Implemented Interfaces:
    Closeable, AutoCloseable, AsynchronousChannel, Channel, NetworkChannel


    public abstract class AsynchronousServerSocketChannel
    extends Object
    implements AsynchronousChannel, NetworkChannel 
    An asynchronous channel for stream-oriented listening sockets.

    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:

    Option Name Description
    SO_RCVBUF The size of the socket receive buffer
    SO_REUSEADDR Re-use address
    Additional (implementation specific) options may also be supported.

    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) {
     ...
     }
     });
     
    Since:
    1.7
Java™ Platform
Standard Ed. 7

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, 2020, Oracle and/or its affiliates. All rights reserved. Use is subject to license terms. Also see the documentation redistribution policy.

Scripting on this page tracks web page traffic, but does not change the content in any way.

AltStyle によって変換されたページ (->オリジナル) /