< prev index next >

src/java.base/share/classes/java/nio/channels/AsynchronousServerSocketChannel.java

Print this page




  35  * An asynchronous channel for stream-oriented listening sockets.
  36  *
  37  * <p> An asynchronous server-socket channel is created by invoking the
  38  * {@link #open open} method of this class.
  39  * A newly-created asynchronous server-socket channel is open but not yet bound.
  40  * It can be bound to a local address and configured to listen for connections
  41  * by invoking the {@link #bind(SocketAddress,int) bind} method. Once bound,
  42  * the {@link #accept(Object,CompletionHandler) accept} method
  43  * is used to initiate the accepting of connections to the channel's socket.
  44  * An attempt to invoke the {@code accept} method on an unbound channel will
  45  * cause a {@link NotYetBoundException} to be thrown.
  46  *
  47  * <p> Channels of this type are safe for use by multiple concurrent threads
  48  * though at most one accept operation can be outstanding at any time.
  49  * If a thread initiates an accept operation before a previous accept operation
  50  * has completed then an {@link AcceptPendingException} will be thrown.
  51  *
  52  * <p> Socket options are configured using the {@link #setOption(SocketOption,Object)
  53  * setOption} method. Channels of this type support the following options:
  54  * <blockquote>
  55  * <table border summary="Socket options">


  56  *   <tr>
  57  *     <th>Option Name</th>
  58  *     <th>Description</th>
  59  *   </tr>


  60  *   <tr>
  61  *     <td> {@link java.net.StandardSocketOptions#SO_RCVBUF SO_RCVBUF} </td>
  62  *     <td> The size of the socket receive buffer </td>
  63  *   </tr>
  64  *   <tr>
  65  *     <td> {@link java.net.StandardSocketOptions#SO_REUSEADDR SO_REUSEADDR} </td>
  66  *     <td> Re-use address </td>
  67  *   </tr>

  68  * </table>
  69  * </blockquote>
  70  * Additional (implementation specific) options may also be supported.
  71  *
  72  * <p> <b>Usage Example:</b>
  73  * <pre>
  74  *  final AsynchronousServerSocketChannel listener =
  75  *      AsynchronousServerSocketChannel.open().bind(new InetSocketAddress(5000));
  76  *
  77  *  listener.accept(null, new CompletionHandler&lt;AsynchronousSocketChannel,Void&gt;() {
  78  *      public void completed(AsynchronousSocketChannel ch, Void att) {
  79  *          // accept the next connection
  80  *          listener.accept(null, this);
  81  *
  82  *          // handle this connection
  83  *          handle(ch);
  84  *      }
  85  *      public void failed(Throwable exc, Void att) {
  86  *          ...
  87  *      }




  35  * An asynchronous channel for stream-oriented listening sockets.
  36  *
  37  * <p> An asynchronous server-socket channel is created by invoking the
  38  * {@link #open open} method of this class.
  39  * A newly-created asynchronous server-socket channel is open but not yet bound.
  40  * It can be bound to a local address and configured to listen for connections
  41  * by invoking the {@link #bind(SocketAddress,int) bind} method. Once bound,
  42  * the {@link #accept(Object,CompletionHandler) accept} method
  43  * is used to initiate the accepting of connections to the channel's socket.
  44  * An attempt to invoke the {@code accept} method on an unbound channel will
  45  * cause a {@link NotYetBoundException} to be thrown.
  46  *
  47  * <p> Channels of this type are safe for use by multiple concurrent threads
  48  * though at most one accept operation can be outstanding at any time.
  49  * If a thread initiates an accept operation before a previous accept operation
  50  * has completed then an {@link AcceptPendingException} will be thrown.
  51  *
  52  * <p> Socket options are configured using the {@link #setOption(SocketOption,Object)
  53  * setOption} method. Channels of this type support the following options:
  54  * <blockquote>
  55  * <table class="striped">
  56  * <caption style="display:none">Socket options</caption>
  57  * <thead>
  58  *   <tr>
  59  *     <th>Option Name</th>
  60  *     <th>Description</th>
  61  *   </tr>
  62  * </thead>
  63  * <tbody>
  64  *   <tr>
  65  *     <td> {@link java.net.StandardSocketOptions#SO_RCVBUF SO_RCVBUF} </td>
  66  *     <td> The size of the socket receive buffer </td>
  67  *   </tr>
  68  *   <tr>
  69  *     <td> {@link java.net.StandardSocketOptions#SO_REUSEADDR SO_REUSEADDR} </td>
  70  *     <td> Re-use address </td>
  71  *   </tr>
  72  * </tbody>
  73  * </table>
  74  * </blockquote>
  75  * Additional (implementation specific) options may also be supported.
  76  *
  77  * <p> <b>Usage Example:</b>
  78  * <pre>
  79  *  final AsynchronousServerSocketChannel listener =
  80  *      AsynchronousServerSocketChannel.open().bind(new InetSocketAddress(5000));
  81  *
  82  *  listener.accept(null, new CompletionHandler&lt;AsynchronousSocketChannel,Void&gt;() {
  83  *      public void completed(AsynchronousSocketChannel ch, Void att) {
  84  *          // accept the next connection
  85  *          listener.accept(null, this);
  86  *
  87  *          // handle this connection
  88  *          handle(ch);
  89  *      }
  90  *      public void failed(Throwable exc, Void att) {
  91  *          ...
  92  *      }


< prev index next >