java.nio.channels

Class AsynchronousServerSocketChanne- l

  • 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

    AsynchronousServerSocketChannel (Java Platform SE 7 ) Home of API Java Contents Haut

    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

Document created the 11/06/2005, last modified the 04/03/2020
Source of the printed document:https://www.gaudry.be/en/java-api-rf-java/nio/channels/asynchronousserversocketchannel.html

The infobrol is a personal site whose content is my sole responsibility. The text is available under CreativeCommons license (BY-NC-SA). More info on the terms of use and the author.

References

  1. View the html document Language of the document:fr Manuel PHP : https://docs.oracle.com

These references and links indicate documents consulted during the writing of this page, or which may provide additional information, but the authors of these sources can not be held responsible for the content of this page.
The author This site is solely responsible for the way in which the various concepts, and the freedoms that are taken with the reference works, are presented here. Remember that you must cross multiple source information to reduce the risk of errors.

Contents Haut