# AsynchronousSocketChannel

public abstract class **AsynchronousSocketChannel** extends [Object](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html)  
implements [AsynchronousByteChannel](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/AsynchronousByteChannel.html) [NetworkChannel](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/NetworkChannel.html) An asynchronous channel for stream-oriented connecting sockets.

Asynchronous socket channels are created in one of two ways. A newly-created
`AsynchronousSocketChannel` is created by invoking one of the `https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/AsynchronousSocketChannel.html#open()` methods defined by this class. A newly-created channel is open but
not yet connected. A connected `AsynchronousSocketChannel` is created
when a connection is made to the socket of an `https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/AsynchronousServerSocketChannel.html`.
It is not possible to create an asynchronous socket channel for an arbitrary,
pre-existing `https://developers.google.com/j2objc/javadoc/jre/reference/java/net/Socket.html`.

A newly-created channel is connected by invoking its `https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/AsynchronousSocketChannel.html#connect(java.net.SocketAddress)`
method; once connected, a channel remains connected until it is closed. Whether
or not a socket channel is connected may be determined by invoking its `https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/AsynchronousSocketChannel.html#getRemoteAddress()` method. An attempt to invoke an I/O
operation upon an unconnected channel will cause a `https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/NotYetConnectedException.html`
to be thrown.

Channels of this type are safe for use by multiple concurrent threads.
They support concurrent reading and writing, though at most one read operation
and one write operation can be outstanding at any time.
If a thread initiates a read operation before a previous read operation has
completed then a `https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/ReadPendingException.html` will be thrown. Similarly, an
attempt to initiate a write operation before a previous write has completed
will throw a `https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/WritePendingException.html`.

Socket options are configured using the `https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/AsynchronousSocketChannel.html#setOption(java.net.SocketOption<T>,%20T)` method. Asynchronous socket channels support the following options:
>
> | Option Name | Description |
> |---|---|
> | `https://developers.google.com/j2objc/javadoc/jre/reference/java/net/StandardSocketOptions.html#SO_SNDBUF` | The size of the socket send buffer |
> | `https://developers.google.com/j2objc/javadoc/jre/reference/java/net/StandardSocketOptions.html#SO_RCVBUF` | The size of the socket receive buffer |
> | `https://developers.google.com/j2objc/javadoc/jre/reference/java/net/StandardSocketOptions.html#SO_KEEPALIVE` | Keep connection alive |
> | `https://developers.google.com/j2objc/javadoc/jre/reference/java/net/StandardSocketOptions.html#SO_REUSEADDR` | Re-use address |
> | `https://developers.google.com/j2objc/javadoc/jre/reference/java/net/StandardSocketOptions.html#TCP_NODELAY` | Disable the Nagle algorithm |

Additional (implementation specific) options may also be supported.

## Timeouts

The `https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/AsynchronousSocketChannel.html#read(java.nio.ByteBuffer,%20long,%20java.util.concurrent.TimeUnit,%20A,%20java.nio.channels.CompletionHandler<java.lang.Integer,%20?%20super%20A>)`
and `https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/AsynchronousSocketChannel.html#write(java.nio.ByteBuffer,%20long,%20java.util.concurrent.TimeUnit,%20A,%20java.nio.channels.CompletionHandler<java.lang.Integer,%20?%20super%20A>)`
methods defined by this class allow a timeout to be specified when initiating
a read or write operation. If the timeout elapses before an operation completes
then the operation completes with the exception `https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/InterruptedByTimeoutException.html`. A timeout may leave the channel, or the
underlying connection, in an inconsistent state. Where the implementation
cannot guarantee that bytes have not been read from the channel then it puts
the channel into an implementation specific *error state* . A subsequent
attempt to initiate a `read` operation causes an unspecified runtime
exception to be thrown. Similarly if a `write` operation times out and
the implementation cannot guarantee bytes have not been written to the
channel then further attempts to `write` to the channel cause an
unspecified runtime exception to be thrown. When a timeout elapses then the
state of the `https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/ByteBuffer.html`, or the sequence of buffers, for the I/O
operation is not defined. Buffers should be discarded or at least care must
be taken to ensure that the buffers are not accessed while the channel remains
open. All methods that accept timeout parameters treat values less than or
equal to zero to mean that the I/O operation does not timeout.

### Protected Constructor Summary

|---|---|
|   | [AsynchronousSocketChannel](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/AsynchronousSocketChannel.html#AsynchronousSocketChannel(java.nio.channels.spi.AsynchronousChannelProvider))([AsynchronousChannelProvider](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/spi/AsynchronousChannelProvider.html) provider) Initializes a new instance of this class. |

### Public Method Summary

|---|---|
| abstract [AsynchronousSocketChannel](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/AsynchronousSocketChannel.html) | [bind](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/AsynchronousSocketChannel.html#bind(java.net.SocketAddress))([SocketAddress](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/SocketAddress.html) local) Binds the channel's socket to a local address. |
| abstract [Future](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/Future.html)\<[Void](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Void.html)\> | [connect](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/AsynchronousSocketChannel.html#connect(java.net.SocketAddress))([SocketAddress](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/SocketAddress.html) remote) Connects this channel. |
| abstract \<A\> void | [connect](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/AsynchronousSocketChannel.html#connect(java.net.SocketAddress,%20A,%20java.nio.channels.CompletionHandler<java.lang.Void,%20?%20super%20A>))([SocketAddress](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/SocketAddress.html) remote, A attachment, [CompletionHandler](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/CompletionHandler.html)\<[Void](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Void.html), ? super A\> handler) Connects this channel. |
| abstract [SocketAddress](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/SocketAddress.html) | [getLocalAddress](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/AsynchronousSocketChannel.html#getLocalAddress())() Returns the socket address that this channel's socket is bound to. If there is a security manager set, its `checkConnect` method is called with the local address and `-1` as its arguments to see if the operation is allowed. |
| abstract [SocketAddress](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/SocketAddress.html) | [getRemoteAddress](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/AsynchronousSocketChannel.html#getRemoteAddress())() Returns the remote address to which this channel's socket is connected. |
| static [AsynchronousSocketChannel](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/AsynchronousSocketChannel.html) | [open](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/AsynchronousSocketChannel.html#open(java.nio.channels.AsynchronousChannelGroup))([AsynchronousChannelGroup](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/AsynchronousChannelGroup.html) group) Opens an asynchronous socket channel. |
| static [AsynchronousSocketChannel](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/AsynchronousSocketChannel.html) | [open](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/AsynchronousSocketChannel.html#open())() Opens an asynchronous socket channel. |
| final [AsynchronousChannelProvider](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/spi/AsynchronousChannelProvider.html) | [provider](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/AsynchronousSocketChannel.html#provider())() Returns the provider that created this channel. |
| abstract [Future](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/Future.html)\<[Integer](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Integer.html)\> | [read](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/AsynchronousSocketChannel.html#read(java.nio.ByteBuffer))([ByteBuffer](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/ByteBuffer.html) dst) Reads a sequence of bytes from this channel into the given buffer. |
| final \<A\> void | [read](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/AsynchronousSocketChannel.html#read(java.nio.ByteBuffer,%20A,%20java.nio.channels.CompletionHandler<java.lang.Integer,%20?%20super%20A>))([ByteBuffer](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/ByteBuffer.html) dst, A attachment, [CompletionHandler](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/CompletionHandler.html)\<[Integer](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Integer.html), ? super A\> handler) Reads a sequence of bytes from this channel into the given buffer. |
| abstract \<A\> void | [read](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/AsynchronousSocketChannel.html#read(java.nio.ByteBuffer[],%20int,%20int,%20long,%20java.util.concurrent.TimeUnit,%20A,%20java.nio.channels.CompletionHandler<java.lang.Long,%20?%20super%20A>))([ByteBuffer\[\]](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/ByteBuffer.html) dsts, int offset, int length, long timeout, [TimeUnit](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/TimeUnit.html) unit, A attachment, [CompletionHandler](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/CompletionHandler.html)\<[Long](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Long.html), ? super A\> handler) Reads a sequence of bytes from this channel into a subsequence of the given buffers. |
| abstract \<A\> void | [read](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/AsynchronousSocketChannel.html#read(java.nio.ByteBuffer,%20long,%20java.util.concurrent.TimeUnit,%20A,%20java.nio.channels.CompletionHandler<java.lang.Integer,%20?%20super%20A>))([ByteBuffer](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/ByteBuffer.html) dst, long timeout, [TimeUnit](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/TimeUnit.html) unit, A attachment, [CompletionHandler](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/CompletionHandler.html)\<[Integer](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Integer.html), ? super A\> handler) Reads a sequence of bytes from this channel into the given buffer. |
| abstract \<T\> [AsynchronousSocketChannel](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/AsynchronousSocketChannel.html) | [setOption](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/AsynchronousSocketChannel.html#setOption(java.net.SocketOption<T>,%20T))([SocketOption](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/SocketOption.html)\<T\> name, T value) Sets the value of a socket option. |
| abstract [AsynchronousSocketChannel](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/AsynchronousSocketChannel.html) | [shutdownInput](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/AsynchronousSocketChannel.html#shutdownInput())() Shutdown the connection for reading without closing the channel. |
| abstract [AsynchronousSocketChannel](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/AsynchronousSocketChannel.html) | [shutdownOutput](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/AsynchronousSocketChannel.html#shutdownOutput())() Shutdown the connection for writing without closing the channel. |
| abstract [Future](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/Future.html)\<[Integer](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Integer.html)\> | [write](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/AsynchronousSocketChannel.html#write(java.nio.ByteBuffer))([ByteBuffer](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/ByteBuffer.html) src) Writes a sequence of bytes to this channel from the given buffer. |
| abstract \<A\> void | [write](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/AsynchronousSocketChannel.html#write(java.nio.ByteBuffer,%20long,%20java.util.concurrent.TimeUnit,%20A,%20java.nio.channels.CompletionHandler<java.lang.Integer,%20?%20super%20A>))([ByteBuffer](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/ByteBuffer.html) src, long timeout, [TimeUnit](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/TimeUnit.html) unit, A attachment, [CompletionHandler](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/CompletionHandler.html)\<[Integer](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Integer.html), ? super A\> handler) Writes a sequence of bytes to this channel from the given buffer. |
| final \<A\> void | [write](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/AsynchronousSocketChannel.html#write(java.nio.ByteBuffer,%20A,%20java.nio.channels.CompletionHandler<java.lang.Integer,%20?%20super%20A>))([ByteBuffer](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/ByteBuffer.html) src, A attachment, [CompletionHandler](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/CompletionHandler.html)\<[Integer](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Integer.html), ? super A\> handler) Writes a sequence of bytes to this channel from the given buffer. |
| abstract \<A\> void | [write](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/AsynchronousSocketChannel.html#write(java.nio.ByteBuffer[],%20int,%20int,%20long,%20java.util.concurrent.TimeUnit,%20A,%20java.nio.channels.CompletionHandler<java.lang.Long,%20?%20super%20A>))([ByteBuffer\[\]](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/ByteBuffer.html) srcs, int offset, int length, long timeout, [TimeUnit](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/TimeUnit.html) unit, A attachment, [CompletionHandler](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/CompletionHandler.html)\<[Long](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Long.html), ? super A\> handler) Writes a sequence of bytes to this channel from a subsequence of the given buffers. |

### Inherited Method Summary

From class [java.lang.Object](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html)

|---|---|
| [Object](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html) | [clone](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#clone())() Creates and returns a copy of this `Object`. |
| boolean | [equals](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#equals(java.lang.Object))([Object](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html) obj) Compares this instance with the specified object and indicates if they are equal. |
| void | [finalize](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#finalize())() Invoked when the garbage collector has detected that this instance is no longer reachable. |
| final [Class](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Class.html)\<?\> | [getClass](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#getClass())() Returns the unique instance of `https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Class.html` that represents this object's class. |
| int | [hashCode](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#hashCode())() Returns an integer hash code for this object. |
| final void | [notify](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#notify())() Causes a thread which is waiting on this object's monitor (by means of calling one of the `wait()` methods) to be woken up. |
| final void | [notifyAll](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#notifyAll())() Causes all threads which are waiting on this object's monitor (by means of calling one of the `wait()` methods) to be woken up. |
| [String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) | [toString](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#toString())() Returns a string containing a concise, human-readable description of this object. |
| final void | [wait](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#wait(long,%20int))(long timeout, int nanos) Causes the calling thread to wait until another thread calls the `notify()` or `notifyAll()` method of this object or until the specified timeout expires. |
| final void | [wait](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#wait(long))(long timeout) Causes the calling thread to wait until another thread calls the `notify()` or `notifyAll()` method of this object or until the specified timeout expires. |
| final void | [wait](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#wait())() Causes the calling thread to wait until another thread calls the `notify()` or `notifyAll()` method of this object. |

From interface [java.nio.channels.AsynchronousByteChannel](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/AsynchronousByteChannel.html)

|---|---|
| abstract \<A\> void | [read](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/AsynchronousByteChannel.html#read(java.nio.ByteBuffer,%20A,%20java.nio.channels.CompletionHandler<java.lang.Integer,%20?%20super%20A>))([ByteBuffer](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/ByteBuffer.html) dst, A attachment, [CompletionHandler](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/CompletionHandler.html)\<[Integer](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Integer.html), ? super A\> handler) Reads a sequence of bytes from this channel into the given buffer. |
| abstract [Future](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/Future.html)\<[Integer](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Integer.html)\> | [read](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/AsynchronousByteChannel.html#read(java.nio.ByteBuffer))([ByteBuffer](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/ByteBuffer.html) dst) Reads a sequence of bytes from this channel into the given buffer. |
| abstract \<A\> void | [write](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/AsynchronousByteChannel.html#write(java.nio.ByteBuffer,%20A,%20java.nio.channels.CompletionHandler<java.lang.Integer,%20?%20super%20A>))([ByteBuffer](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/ByteBuffer.html) src, A attachment, [CompletionHandler](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/CompletionHandler.html)\<[Integer](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Integer.html), ? super A\> handler) Writes a sequence of bytes to this channel from the given buffer. |
| abstract [Future](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/Future.html)\<[Integer](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Integer.html)\> | [write](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/AsynchronousByteChannel.html#write(java.nio.ByteBuffer))([ByteBuffer](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/ByteBuffer.html) src) Writes a sequence of bytes to this channel from the given buffer. |

From interface [java.nio.channels.NetworkChannel](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/NetworkChannel.html)

|---|---|
| abstract [NetworkChannel](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/NetworkChannel.html) | [bind](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/NetworkChannel.html#bind(java.net.SocketAddress))([SocketAddress](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/SocketAddress.html) local) Binds the channel's socket to a local address. |
| abstract [SocketAddress](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/SocketAddress.html) | [getLocalAddress](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/NetworkChannel.html#getLocalAddress())() Returns the socket address that this channel's socket is bound to. |
| abstract \<T\> T | [getOption](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/NetworkChannel.html#getOption(java.net.SocketOption<T>))([SocketOption](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/SocketOption.html)\<T\> name) Returns the value of a socket option. |
| abstract \<T\> [NetworkChannel](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/NetworkChannel.html) | [setOption](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/NetworkChannel.html#setOption(java.net.SocketOption<T>,%20T))([SocketOption](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/SocketOption.html)\<T\> name, T value) Sets the value of a socket option. |
| abstract [Set](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/Set.html)\<[SocketOption](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/SocketOption.html)\<?\>\> | [supportedOptions](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/NetworkChannel.html#supportedOptions())() Returns a set of the socket options supported by this channel. |

From interface [java.nio.channels.AsynchronousChannel](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/AsynchronousChannel.html)

|---|---|
| abstract void | [close](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/AsynchronousChannel.html#close())() Closes this channel. |

From interface [java.nio.channels.Channel](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/Channel.html)

|---|---|
| abstract void | [close](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/Channel.html#close())() Closes this channel. |
| abstract boolean | [isOpen](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/Channel.html#isOpen())() Tells whether or not this channel is open. |

From interface [java.io.Closeable](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/Closeable.html)

|---|---|
| abstract void | [close](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/Closeable.html#close())() Closes this stream and releases any system resources associated with it. |

From interface [java.lang.AutoCloseable](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/AutoCloseable.html)

|---|---|
| abstract void | [close](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/AutoCloseable.html#close())() Closes this resource, relinquishing any underlying resources. |

## Protected Constructors

#### protected
**AsynchronousSocketChannel**
([AsynchronousChannelProvider](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/spi/AsynchronousChannelProvider.html) provider)

Initializes a new instance of this class.

##### Parameters

| provider | The provider that created this channel |
|---|---|

## Public Methods

#### public abstract [AsynchronousSocketChannel](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/AsynchronousSocketChannel.html)
**bind**
([SocketAddress](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/SocketAddress.html) local)

Binds the channel's socket to a local address.

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 channel is closed. If the `local` parameter has the
value `null` then the socket will be bound to an address that is
assigned automatically.

##### Parameters

| local | The address to bind the socket, or `null` to bind the socket to an automatically assigned socket address |
|---|---|

##### Returns

- This channel

##### Throws

| [ConnectionPendingException](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/ConnectionPendingException.html) | If a connection operation is already in progress on this channel |
| [AlreadyBoundException](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/AlreadyBoundException.html) |   |
| [UnsupportedAddressTypeException](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/UnsupportedAddressTypeException.html) |   |
| [ClosedChannelException](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/ClosedChannelException.html) |   |
| [IOException](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/IOException.html) |   |
| [SecurityException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/SecurityException.html) | If a security manager has been installed and its `https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/SecurityManager.html#checkListen(int)` method denies the operation |
|---|---|

#### public abstract [Future](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/Future.html)\<[Void](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Void.html)\>
**connect**
([SocketAddress](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/SocketAddress.html) remote)

Connects this channel.

This method initiates an operation to connect this channel. This
method behaves in exactly the same manner as the `https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/AsynchronousSocketChannel.html#connect(java.net.SocketAddress,%20A,%20java.nio.channels.CompletionHandler<java.lang.Void,%20?%20super%20A>)` method except that
instead of specifying a completion handler, this method returns a `Future` representing the pending result. The `Future`'s `https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/Future.html#get()` method returns `null` on successful completion.

##### Parameters

| remote | The remote address to which this channel is to be connected |
|---|---|

##### Returns

- A `Future` object representing the pending result

##### Throws

| [UnresolvedAddressException](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/UnresolvedAddressException.html) | If the given remote address is not fully resolved |
| [UnsupportedAddressTypeException](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/UnsupportedAddressTypeException.html) | If the type of the given remote address is not supported |
| [AlreadyConnectedException](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/AlreadyConnectedException.html) | If this channel is already connected |
| [ConnectionPendingException](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/ConnectionPendingException.html) | If a connection operation is already in progress on this channel |
| [SecurityException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/SecurityException.html) | If a security manager has been installed and it does not permit access to the given remote endpoint |
|---|---|

#### public abstract void
**connect**
([SocketAddress](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/SocketAddress.html) remote, A attachment, [CompletionHandler](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/CompletionHandler.html)\<[Void](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Void.html), ? super A\> handler)

Connects this channel.

This method initiates an operation to connect this channel. The
`handler` parameter is a completion handler that is invoked when
the connection is successfully established or connection cannot be
established. If the connection cannot be established then the channel is
closed.

This method performs exactly the same security checks as the `https://developers.google.com/j2objc/javadoc/jre/reference/java/net/Socket.html` class. That is, if a security manager has been
installed then this method verifies that its `https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/SecurityManager.html#checkConnect(java.lang.String,%20int)` method permits
connecting to the address and port number of the given remote endpoint.

##### Parameters

| remote | The remote address to which this channel is to be connected |
| attachment | The object to attach to the I/O operation; can be `null` |
| handler | The handler for consuming the result |
|---|---|

##### Throws

| [UnresolvedAddressException](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/UnresolvedAddressException.html) | If the given remote address is not fully resolved |
| [UnsupportedAddressTypeException](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/UnsupportedAddressTypeException.html) | If the type of the given remote address is not supported |
| [AlreadyConnectedException](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/AlreadyConnectedException.html) | If this channel is already connected |
| [ConnectionPendingException](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/ConnectionPendingException.html) | If a connection operation is already in progress on this channel |
| [ShutdownChannelGroupException](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/ShutdownChannelGroupException.html) | If the channel group has terminated |
| [SecurityException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/SecurityException.html) | If a security manager has been installed and it does not permit access to the given remote endpoint |
|---|---|

##### See Also

- `https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/AsynchronousSocketChannel.html#getRemoteAddress()`

#### public abstract [SocketAddress](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/SocketAddress.html)
**getLocalAddress**
()

Returns the socket address that this channel's socket is bound to.

Where the channel is `https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/NetworkChannel.html#bind(java.net.SocketAddress)` to an Internet Protocol
socket address then the return value from this method is of type `https://developers.google.com/j2objc/javadoc/jre/reference/java/net/InetSocketAddress.html`.


If there is a security manager set, its `checkConnect` method is
called with the local address and `-1` as its arguments to see
if the operation is allowed. If the operation is not allowed,
a `SocketAddress` representing the
`https://developers.google.com/j2objc/javadoc/jre/reference/java/net/InetAddress.html#getLoopbackAddress()` address and the
local port of the channel's socket is returned.

##### Returns

- The `SocketAddress` that the socket is bound to, or the `SocketAddress` representing the loopback address if denied by the security manager, or `null` if the channel's socket is not bound

##### Throws

| [ClosedChannelException](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/ClosedChannelException.html) |   |
| [IOException](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/IOException.html) |   |
|---|---|

#### public abstract [SocketAddress](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/SocketAddress.html)
**getRemoteAddress**
()

Returns the remote address to which this channel's socket is connected.

Where the channel is bound and connected to an Internet Protocol
socket address then the return value from this method is of type `https://developers.google.com/j2objc/javadoc/jre/reference/java/net/InetSocketAddress.html`.

##### Returns

- The remote address; `null` if the channel's socket is not connected

##### Throws

| [ClosedChannelException](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/ClosedChannelException.html) | If the channel is closed |
| [IOException](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/IOException.html) | If an I/O error occurs |
|---|---|

#### public static [AsynchronousSocketChannel](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/AsynchronousSocketChannel.html)
**open**
([AsynchronousChannelGroup](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/AsynchronousChannelGroup.html) group)

Opens an asynchronous socket channel.

The new channel is created by invoking the `https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/spi/AsynchronousChannelProvider.html#openAsynchronousSocketChannel(java.nio.channels.AsynchronousChannelGroup)` method on the `https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/spi/AsynchronousChannelProvider.html` that created the group. If the group parameter
is `null` then the resulting channel is created by the system-wide
default provider, and bound to the *default group*.

##### Parameters

| group | The group to which the newly constructed channel should be bound, or `null` for the default group |
|---|---|

##### Returns

- A new asynchronous socket channel

##### Throws

| [ShutdownChannelGroupException](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/ShutdownChannelGroupException.html) | If the channel group is shutdown |
| [IOException](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/IOException.html) | If an I/O error occurs |
|---|---|

#### public static [AsynchronousSocketChannel](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/AsynchronousSocketChannel.html)
**open**
()

Opens an asynchronous socket channel.

This method returns an asynchronous socket channel that is bound to
the *default group*.This method is equivalent to evaluating the
expression:
>
> ```
>  open((AsynchronousChannelGroup)null);
>  
> ```

<br />

##### Returns

- A new asynchronous socket channel

##### Throws

| [IOException](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/IOException.html) | If an I/O error occurs |
|---|---|

#### public final [AsynchronousChannelProvider](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/spi/AsynchronousChannelProvider.html)
**provider**
()

Returns the provider that created this channel.

##### Returns

- The provider that created this channel

#### public abstract [Future](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/Future.html)\<[Integer](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Integer.html)\>
**read**
([ByteBuffer](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/ByteBuffer.html) dst)

Reads a sequence of bytes from this channel into the given buffer.

This method initiates an asynchronous read operation to read a
sequence of bytes from this channel into the given buffer. The method
behaves in exactly the same manner as the `https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/AsynchronousByteChannel.html#read(java.nio.ByteBuffer,%20A,%20java.nio.channels.CompletionHandler<java.lang.Integer,%20?%20super%20A>)` method except that instead
of specifying a completion handler, this method returns a `Future`
representing the pending result. The `Future`'s `https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/Future.html#get()` method returns the number of bytes read or `-1` if no bytes
could be read because the channel has reached end-of-stream.

##### Parameters

| dst | The buffer into which bytes are to be transferred |
|---|---|

##### Returns

- A Future representing the result of the operation

##### Throws

| [IllegalArgumentException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/IllegalArgumentException.html) |   |
| [ReadPendingException](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/ReadPendingException.html) |   |
| [NotYetConnectedException](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/NotYetConnectedException.html) | If this channel is not yet connected |
|---|---|

#### public final void
**read**
([ByteBuffer](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/ByteBuffer.html) dst, A attachment, [CompletionHandler](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/CompletionHandler.html)\<[Integer](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Integer.html), ? super A\> handler)

Reads a sequence of bytes from this channel into the given buffer.

This method initiates an asynchronous read operation to read a
sequence of bytes from this channel into the given buffer. The `handler` parameter is a completion handler that is invoked when the read
operation completes (or fails). The result passed to the completion
handler is the number of bytes read or `-1` if no bytes could be
read because the channel has reached end-of-stream.

The read operation may read up to *r* bytes from the channel,
where *r* is the number of bytes remaining in the buffer, that is,
`dst.remaining()` at the time that the read is attempted. Where
*r* is 0, the read operation completes immediately with a result of
`0` without initiating an I/O operation.

Suppose that a byte sequence of length *n* is read, where
0 \< *n* \<= *r*.
This byte sequence will be transferred into the buffer so that the first
byte in the sequence is at index *p* and the last byte is at index
*p* + *n* - 1,
where *p* is the buffer's position at the moment the read is
performed. Upon completion the buffer's position will be equal to
*p* + *n*; its limit will not have changed.

Buffers are not safe for use by multiple concurrent threads so care
should be taken to not access the buffer until the operation has
completed.

This method may be invoked at any time. Some channel types may not
allow more than one read to be outstanding at any given time. If a thread
initiates a read operation before a previous read operation has
completed then a `https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/ReadPendingException.html` will be thrown.

##### Parameters

| dst | The buffer into which bytes are to be transferred |
| attachment | The object to attach to the I/O operation; can be `null` |
| handler | The completion handler |
|---|---|

##### Throws

| [IllegalArgumentException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/IllegalArgumentException.html) |   |
| [ReadPendingException](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/ReadPendingException.html) |   |
| [NotYetConnectedException](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/NotYetConnectedException.html) | If this channel is not yet connected |
| [ShutdownChannelGroupException](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/ShutdownChannelGroupException.html) | If the channel group has terminated |
|---|---|

#### public abstract void
**read**
([ByteBuffer\[\]](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/ByteBuffer.html) dsts, int offset, int length, long timeout, [TimeUnit](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/TimeUnit.html) unit, A attachment, [CompletionHandler](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/CompletionHandler.html)\<[Long](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Long.html), ? super A\> handler)

Reads a sequence of bytes from this channel into a subsequence of the
given buffers. This operation, sometimes called a *scattering read* ,
is often useful when implementing network protocols that group data into
segments consisting of one or more fixed-length headers followed by a
variable-length body. The `handler` parameter is a completion
handler that is invoked when the read operation completes (or fails). The
result passed to the completion handler is the number of bytes read or
`-1` if no bytes could be read because the channel has reached
end-of-stream.

This method initiates a read of up to *r* bytes from this channel,
where *r* is the total number of bytes remaining in the specified
subsequence of the given buffer array, that is,

> ```
>  dsts[offset].remaining()
>      + dsts[offset+1].remaining()
>      + ... + dsts[offset+length-1].remaining()
> ```
at the moment that the read is attempted.

Suppose that a byte sequence of length *n* is read, where
0 \< *n* \<= *r*.
Up to the first dsts\[offset\].remaining() bytes of this sequence
are transferred into buffer dsts\[offset\], up to the next
dsts\[offset+1\].remaining() bytes are transferred into buffer
dsts\[offset+1\], and so forth, until the entire byte sequence
is transferred into the given buffers. As many bytes as possible are
transferred into each buffer, hence the final position of each updated
buffer, except the last updated buffer, is guaranteed to be equal to
that buffer's limit. The underlying operating system may impose a limit
on the number of buffers that may be used in an I/O operation. Where the
number of buffers (with bytes remaining), exceeds this limit, then the
I/O operation is performed with the maximum number of buffers allowed by
the operating system.

If a timeout is specified and the timeout elapses before the operation
completes then it completes with the exception `https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/InterruptedByTimeoutException.html`. Where a timeout occurs, and the
implementation cannot guarantee that bytes have not been read, or will not
be read from the channel into the given buffers, then further attempts to
read from the channel will cause an unspecific runtime exception to be
thrown.

##### Parameters

| dsts | The buffers into which bytes are to be transferred |
| offset | The offset within the buffer array of the first buffer into which bytes are to be transferred; must be non-negative and no larger than `dsts.length` |
| length | The maximum number of buffers to be accessed; must be non-negative and no larger than `dsts.length - offset` |
| timeout | The maximum time for the I/O operation to complete |
| unit | The time unit of the `timeout` argument |
| attachment | The object to attach to the I/O operation; can be `null` |
| handler | The handler for consuming the result |
|---|---|

##### Throws

| [IndexOutOfBoundsException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/IndexOutOfBoundsException.html) | If the pre-conditions for the `offset` and `length` parameter aren't met |
| [IllegalArgumentException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/IllegalArgumentException.html) | If the buffer is read-only |
| [ReadPendingException](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/ReadPendingException.html) | If a read operation is already in progress on this channel |
| [NotYetConnectedException](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/NotYetConnectedException.html) | If this channel is not yet connected |
| [ShutdownChannelGroupException](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/ShutdownChannelGroupException.html) | If the channel group has terminated |
|---|---|

#### public abstract void
**read**
([ByteBuffer](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/ByteBuffer.html) dst, long timeout, [TimeUnit](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/TimeUnit.html) unit, A attachment, [CompletionHandler](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/CompletionHandler.html)\<[Integer](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Integer.html), ? super A\> handler)

Reads a sequence of bytes from this channel into the given buffer.

This method initiates an asynchronous read operation to read a
sequence of bytes from this channel into the given buffer. The `handler` parameter is a completion handler that is invoked when the read
operation completes (or fails). The result passed to the completion
handler is the number of bytes read or `-1` if no bytes could be
read because the channel has reached end-of-stream.

If a timeout is specified and the timeout elapses before the operation
completes then the operation completes with the exception `https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/InterruptedByTimeoutException.html`. Where a timeout occurs, and the
implementation cannot guarantee that bytes have not been read, or will not
be read from the channel into the given buffer, then further attempts to
read from the channel will cause an unspecific runtime exception to be
thrown.

Otherwise this method works in the same manner as the `https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/AsynchronousByteChannel.html#read(java.nio.ByteBuffer,%20A,%20java.nio.channels.CompletionHandler<java.lang.Integer,%20?%20super%20A>)`
method.

##### Parameters

| dst | The buffer into which bytes are to be transferred |
| timeout | The maximum time for the I/O operation to complete |
| unit | The time unit of the `timeout` argument |
| attachment | The object to attach to the I/O operation; can be `null` |
| handler | The handler for consuming the result |
|---|---|

##### Throws

| [IllegalArgumentException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/IllegalArgumentException.html) | If the buffer is read-only |
| [ReadPendingException](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/ReadPendingException.html) | If a read operation is already in progress on this channel |
| [NotYetConnectedException](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/NotYetConnectedException.html) | If this channel is not yet connected |
| [ShutdownChannelGroupException](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/ShutdownChannelGroupException.html) | If the channel group has terminated |
|---|---|

#### public abstract [AsynchronousSocketChannel](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/AsynchronousSocketChannel.html)
**setOption**
([SocketOption](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/SocketOption.html)\<T\> name, T value)

Sets the value of a socket option.

##### Parameters

| name | The socket option |
| value | The value of the socket option. A value of `null` may be a valid value for some socket options. |
|---|---|

##### Returns

- This channel

##### Throws

| [IllegalArgumentException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/IllegalArgumentException.html) |   |
| [ClosedChannelException](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/ClosedChannelException.html) |   |
| [IOException](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/IOException.html) |   |
|---|---|

#### public abstract [AsynchronousSocketChannel](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/AsynchronousSocketChannel.html)
**shutdownInput**
()

Shutdown the connection for reading without closing the channel.

Once shutdown for reading then further reads on the channel will
return `-1`, the end-of-stream indication. If the input side of the
connection is already shutdown then invoking this method has no effect.
The effect on an outstanding read operation is system dependent and
therefore not specified. The effect, if any, when there is data in the
socket receive buffer that has not been read, or data arrives subsequently,
is also system dependent.

##### Returns

- The channel

##### Throws

| [NotYetConnectedException](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/NotYetConnectedException.html) | If this channel is not yet connected |
| [ClosedChannelException](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/ClosedChannelException.html) | If this channel is closed |
| [IOException](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/IOException.html) | If some other I/O error occurs |
|---|---|

#### public abstract [AsynchronousSocketChannel](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/AsynchronousSocketChannel.html)
**shutdownOutput**
()

Shutdown the connection for writing without closing the channel.

Once shutdown for writing then further attempts to write to the
channel will throw `https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/ClosedChannelException.html`. If the output side of
the connection is already shutdown then invoking this method has no
effect. The effect on an outstanding write operation is system dependent
and therefore not specified.

##### Returns

- The channel

##### Throws

| [NotYetConnectedException](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/NotYetConnectedException.html) | If this channel is not yet connected |
| [ClosedChannelException](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/ClosedChannelException.html) | If this channel is closed |
| [IOException](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/IOException.html) | If some other I/O error occurs |
|---|---|

#### public abstract [Future](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/Future.html)\<[Integer](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Integer.html)\>
**write**
([ByteBuffer](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/ByteBuffer.html) src)

Writes a sequence of bytes to this channel from the given buffer.

This method initiates an asynchronous write operation to write a
sequence of bytes to this channel from the given buffer. The method
behaves in exactly the same manner as the `https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/AsynchronousByteChannel.html#write(java.nio.ByteBuffer,%20A,%20java.nio.channels.CompletionHandler<java.lang.Integer,%20?%20super%20A>)` method except that instead
of specifying a completion handler, this method returns a `Future`
representing the pending result. The `Future`'s `https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/Future.html#get()` method returns the number of bytes written.

##### Parameters

| src | The buffer from which bytes are to be retrieved |
|---|---|

##### Returns

- A Future representing the result of the operation

##### Throws

| [WritePendingException](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/WritePendingException.html) |   |
| [NotYetConnectedException](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/NotYetConnectedException.html) | If this channel is not yet connected |
|---|---|

#### public abstract void
**write**
([ByteBuffer](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/ByteBuffer.html) src, long timeout, [TimeUnit](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/TimeUnit.html) unit, A attachment, [CompletionHandler](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/CompletionHandler.html)\<[Integer](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Integer.html), ? super A\> handler)

Writes a sequence of bytes to this channel from the given buffer.

This method initiates an asynchronous write operation to write a
sequence of bytes to this channel from the given buffer. The `handler` parameter is a completion handler that is invoked when the write
operation completes (or fails). The result passed to the completion
handler is the number of bytes written.

If a timeout is specified and the timeout elapses before the operation
completes then it completes with the exception `https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/InterruptedByTimeoutException.html`. Where a timeout occurs, and the
implementation cannot guarantee that bytes have not been written, or will
not be written to the channel from the given buffer, then further attempts
to write to the channel will cause an unspecific runtime exception to be
thrown.

Otherwise this method works in the same manner as the `https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/AsynchronousByteChannel.html#write(java.nio.ByteBuffer,%20A,%20java.nio.channels.CompletionHandler<java.lang.Integer,%20?%20super%20A>)`
method.

##### Parameters

| src | The buffer from which bytes are to be retrieved |
| timeout | The maximum time for the I/O operation to complete |
| unit | The time unit of the `timeout` argument |
| attachment | The object to attach to the I/O operation; can be `null` |
| handler | The handler for consuming the result |
|---|---|

##### Throws

| [WritePendingException](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/WritePendingException.html) | If a write operation is already in progress on this channel |
| [NotYetConnectedException](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/NotYetConnectedException.html) | If this channel is not yet connected |
| [ShutdownChannelGroupException](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/ShutdownChannelGroupException.html) | If the channel group has terminated |
|---|---|

#### public final void
**write**
([ByteBuffer](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/ByteBuffer.html) src, A attachment, [CompletionHandler](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/CompletionHandler.html)\<[Integer](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Integer.html), ? super A\> handler)

Writes a sequence of bytes to this channel from the given buffer.

This method initiates an asynchronous write operation to write a
sequence of bytes to this channel from the given buffer. The `handler` parameter is a completion handler that is invoked when the write
operation completes (or fails). The result passed to the completion
handler is the number of bytes written.

The write operation may write up to *r* bytes to the channel,
where *r* is the number of bytes remaining in the buffer, that is,
`src.remaining()` at the time that the write is attempted. Where
*r* is 0, the write operation completes immediately with a result of
`0` without initiating an I/O operation.

Suppose that a byte sequence of length *n* is written, where
0 \< *n* \<= *r*.
This byte sequence will be transferred from the buffer starting at index
*p*, where *p* is the buffer's position at the moment the
write is performed; the index of the last byte written will be
*p* + *n* - 1.
Upon completion the buffer's position will be equal to
*p* + *n*; its limit will not have changed.

Buffers are not safe for use by multiple concurrent threads so care
should be taken to not access the buffer until the operation has
completed.

This method may be invoked at any time. Some channel types may not
allow more than one write to be outstanding at any given time. If a thread
initiates a write operation before a previous write operation has
completed then a `https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/WritePendingException.html` will be thrown.

##### Parameters

| src | The buffer from which bytes are to be retrieved |
| attachment | The object to attach to the I/O operation; can be `null` |
| handler | The completion handler object |
|---|---|

##### Throws

| [WritePendingException](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/WritePendingException.html) |   |
| [NotYetConnectedException](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/NotYetConnectedException.html) | If this channel is not yet connected |
| [ShutdownChannelGroupException](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/ShutdownChannelGroupException.html) | If the channel group has terminated |
|---|---|

#### public abstract void
**write**
([ByteBuffer\[\]](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/ByteBuffer.html) srcs, int offset, int length, long timeout, [TimeUnit](https://developers.google.com/j2objc/javadoc/jre/reference/java/util/concurrent/TimeUnit.html) unit, A attachment, [CompletionHandler](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/CompletionHandler.html)\<[Long](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Long.html), ? super A\> handler)

Writes a sequence of bytes to this channel from a subsequence of the given
buffers. This operation, sometimes called a *gathering write* , is
often useful when implementing network protocols that group data into
segments consisting of one or more fixed-length headers followed by a
variable-length body. The `handler` parameter is a completion
handler that is invoked when the write operation completes (or fails).
The result passed to the completion handler is the number of bytes written.

This method initiates a write of up to *r* bytes to this channel,
where *r* is the total number of bytes remaining in the specified
subsequence of the given buffer array, that is,

> ```
>  srcs[offset].remaining()
>      + srcs[offset+1].remaining()
>      + ... + srcs[offset+length-1].remaining()
> ```
at the moment that the write is attempted.

Suppose that a byte sequence of length *n* is written, where
0 \< *n* \<= *r*.
Up to the first srcs\[offset\].remaining() bytes of this sequence
are written from buffer srcs\[offset\], up to the next
srcs\[offset+1\].remaining() bytes are written from buffer
srcs\[offset+1\], and so forth, until the entire byte sequence is
written. As many bytes as possible are written from each buffer, hence
the final position of each updated buffer, except the last updated
buffer, is guaranteed to be equal to that buffer's limit. The underlying
operating system may impose a limit on the number of buffers that may be
used in an I/O operation. Where the number of buffers (with bytes
remaining), exceeds this limit, then the I/O operation is performed with
the maximum number of buffers allowed by the operating system.

If a timeout is specified and the timeout elapses before the operation
completes then it completes with the exception `https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/InterruptedByTimeoutException.html`. Where a timeout occurs, and the
implementation cannot guarantee that bytes have not been written, or will
not be written to the channel from the given buffers, then further attempts
to write to the channel will cause an unspecific runtime exception to be
thrown.

##### Parameters

| srcs | The buffers from which bytes are to be retrieved |
| offset | The offset within the buffer array of the first buffer from which bytes are to be retrieved; must be non-negative and no larger than `srcs.length` |
| length | The maximum number of buffers to be accessed; must be non-negative and no larger than `srcs.length - offset` |
| timeout | The maximum time for the I/O operation to complete |
| unit | The time unit of the `timeout` argument |
| attachment | The object to attach to the I/O operation; can be `null` |
| handler | The handler for consuming the result |
|---|---|

##### Throws

| [IndexOutOfBoundsException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/IndexOutOfBoundsException.html) | If the pre-conditions for the `offset` and `length` parameter aren't met |
| [WritePendingException](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/WritePendingException.html) | If a write operation is already in progress on this channel |
| [NotYetConnectedException](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/NotYetConnectedException.html) | If this channel is not yet connected |
| [ShutdownChannelGroupException](https://developers.google.com/j2objc/javadoc/jre/reference/java/nio/channels/ShutdownChannelGroupException.html) | If the channel group has terminated |
|---|---|