AsynchronousSocketChannel Class

Definition

An asynchronous channel for stream-oriented connecting sockets.

[Android.Runtime.Register("java/nio/channels/AsynchronousSocketChannel", ApiSince=26, DoNotGenerateAcw=true)]
public abstract class AsynchronousSocketChannel : Java.Lang.Object, IDisposable, Java.Interop.IJavaPeerable, Java.Nio.Channels.IAsynchronousByteChannel
[<Android.Runtime.Register("java/nio/channels/AsynchronousSocketChannel", ApiSince=26, DoNotGenerateAcw=true)>]
type AsynchronousSocketChannel = class
    inherit Object
    interface IAsynchronousByteChannel
    interface IAsynchronousChannel
    interface IChannel
    interface ICloseable
    interface IJavaObject
    interface IDisposable
    interface IJavaPeerable
Inheritance
AsynchronousSocketChannel
Attributes
Implements

Remarks

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 #open 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 AsynchronousServerSocketChannel. It is not possible to create an asynchronous socket channel for an arbitrary, pre-existing java.net.Socket socket.

A newly-created channel is connected by invoking its #connect connect 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 #getRemoteAddress getRemoteAddress method. An attempt to invoke an I/O operation upon an unconnected channel will cause a NotYetConnectedException 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 ReadPendingException will be thrown. Similarly, an attempt to initiate a write operation before a previous write has completed will throw a WritePendingException.

Socket options are configured using the #setOption(SocketOption,Object) setOption method. Asynchronous socket channels support the following options: <blockquote> <table class="striped"> <caption style="display:none">Socket options</caption> <thead> <tr> <th scope="col">Option Name</th> <th scope="col">Description</th> </tr> </thead> <tbody> <tr> <th scope="row"> java.net.StandardSocketOptions#SO_SNDBUF SO_SNDBUF</th> <td> The size of the socket send buffer </td> </tr> <tr> <th scope="row"> java.net.StandardSocketOptions#SO_RCVBUF SO_RCVBUF</th> <td> The size of the socket receive buffer </td> </tr> <tr> <th scope="row"> java.net.StandardSocketOptions#SO_KEEPALIVE SO_KEEPALIVE</th> <td> Keep connection alive </td> </tr> <tr> <th scope="row"> java.net.StandardSocketOptions#SO_REUSEADDR SO_REUSEADDR</th> <td> Re-use address </td> </tr> <tr> <th scope="row"> java.net.StandardSocketOptions#TCP_NODELAY TCP_NODELAY</th> <td> Disable the Nagle algorithm </td> </tr> </tbody> </table> </blockquote> Additional (implementation specific) options may also be supported.

<h2>Timeouts</h2>

The #read(ByteBuffer,long,TimeUnit,Object,CompletionHandler) read and #write(ByteBuffer,long,TimeUnit,Object,CompletionHandler) write 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 InterruptedByTimeoutException. 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 <em>error state</em>. 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 ByteBuffer, 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.

Added in 1.7.

Java documentation for java.nio.channels.AsynchronousSocketChannel.

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Constructors

AsynchronousSocketChannel(AsynchronousChannelProvider)

Initializes a new instance of this class.

AsynchronousSocketChannel(IntPtr, JniHandleOwnership)

Properties

Class

Returns the runtime class of this Object.

(Inherited from Object)
Handle

The handle to the underlying Android instance.

(Inherited from Object)
IsOpen
JniIdentityHashCode (Inherited from Object)
JniPeerMembers
LocalAddress
PeerReference (Inherited from Object)
RemoteAddress
ThresholdClass
ThresholdType

Methods

Bind(SocketAddress)
Clone()

Creates and returns a copy of this object.

(Inherited from Object)
Close()

Closes this channel.

Connect(SocketAddress)

Connects this channel.

Connect(SocketAddress, Object, ICompletionHandler)

Connects this channel.

Dispose() (Inherited from Object)
Dispose(Boolean) (Inherited from Object)
Equals(Object)

Indicates whether some other object is "equal to" this one.

(Inherited from Object)
GetHashCode()

Returns a hash code value for the object.

(Inherited from Object)
JavaFinalize()

Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.

(Inherited from Object)
Notify()

Wakes up a single thread that is waiting on this object's monitor.

(Inherited from Object)
NotifyAll()

Wakes up all threads that are waiting on this object's monitor.

(Inherited from Object)
Open()

Opens an asynchronous socket channel.

Open(AsynchronousChannelGroup)

Opens an asynchronous socket channel.

Provider()

Returns the provider that created this channel.

Read(ByteBuffer)
Read(ByteBuffer, Int64, TimeUnit, Object, ICompletionHandler)

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

Read(ByteBuffer, Object, ICompletionHandler)
Read(ByteBuffer[], Int32, Int32, Int64, TimeUnit, Object, ICompletionHandler)

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

SetHandle(IntPtr, JniHandleOwnership)

Sets the Handle property.

(Inherited from Object)
SetOption(ISocketOption, Object)
ShutdownInput()

Shutdown the connection for reading without closing the channel.

ShutdownOutput()

Shutdown the connection for writing without closing the channel.

ToArray<T>() (Inherited from Object)
ToString()

Returns a string representation of the object.

(Inherited from Object)
UnregisterFromRuntime() (Inherited from Object)
Wait()

Causes the current thread to wait until it is awakened, typically by being <em>notified</em> or <em>interrupted</em>.

(Inherited from Object)
Wait(Int64)

Causes the current thread to wait until it is awakened, typically by being <em>notified</em> or <em>interrupted</em>, or until a certain amount of real time has elapsed.

(Inherited from Object)
Wait(Int64, Int32)

Causes the current thread to wait until it is awakened, typically by being <em>notified</em> or <em>interrupted</em>, or until a certain amount of real time has elapsed.

(Inherited from Object)
Write(ByteBuffer)
Write(ByteBuffer, Int64, TimeUnit, Object, ICompletionHandler)

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

Write(ByteBuffer, Object, ICompletionHandler)
Write(ByteBuffer[], Int32, Int32, Int64, TimeUnit, Object, ICompletionHandler)

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

Explicit Interface Implementations

IJavaPeerable.Disposed() (Inherited from Object)
IJavaPeerable.DisposeUnlessReferenced() (Inherited from Object)
IJavaPeerable.Finalized() (Inherited from Object)
IJavaPeerable.JniManagedPeerState (Inherited from Object)
IJavaPeerable.SetJniIdentityHashCode(Int32) (Inherited from Object)
IJavaPeerable.SetJniManagedPeerState(JniManagedPeerStates) (Inherited from Object)
IJavaPeerable.SetPeerReference(JniObjectReference) (Inherited from Object)

Extension Methods

JavaCast<TResult>(IJavaObject)

Performs an Android runtime-checked type conversion.

JavaCast<TResult>(IJavaObject)
GetJniTypeName(IJavaPeerable)

Applies to