Udostępnij za pośrednictwem


AsynchronousServerSocketChannel Class

Definition

An asynchronous channel for stream-oriented listening sockets.

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

Remarks

An asynchronous channel for stream-oriented listening sockets.

An asynchronous server-socket channel is created by invoking the #open 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(SocketAddress,int) bind method. Once bound, the #accept(Object,CompletionHandler) 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(SocketOption,Object) setOption method. Channels of this type 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_RCVBUF SO_RCVBUF</th> <td> The size of the socket receive buffer </td> </tr> <tr> <th scope="row"> java.net.StandardSocketOptions#SO_REUSEADDR SO_REUSEADDR</th> <td> Re-use address </td> </tr> </tbody> </table> </blockquote> Additional (implementation specific) options may also be supported.

<b>Usage Example:</b>

final AsynchronousServerSocketChannel listener =
                 AsynchronousServerSocketChannel.open().bind(new InetSocketAddress(5000));

             listener.accept(null, new CompletionHandler&lt;AsynchronousSocketChannel,Void&gt;() {
                 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) {
                     ...
                 }
             });

Added in 1.7.

Java documentation for java.nio.channels.AsynchronousServerSocketChannel.

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

AsynchronousServerSocketChannel(AsynchronousChannelProvider)

Initializes a new instance of this class.

AsynchronousServerSocketChannel(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)
ThresholdClass
ThresholdType

Methods

Accept()

Accepts a connection.

Accept(Object, ICompletionHandler)

Accepts a connection.

Bind(SocketAddress, Int32)

Binds the channel's socket to a local address and configures the socket to listen for connections.

Bind(SocketAddress)

Binds the channel's socket to a local address and configures the socket to listen for connections.

Clone()

Creates and returns a copy of this object.

(Inherited from Object)
Close()

Closes 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 server-socket channel.

Open(AsynchronousChannelGroup)

Opens an asynchronous server-socket channel.

Provider()

Returns the provider that created this channel.

SetHandle(IntPtr, JniHandleOwnership)

Sets the Handle property.

(Inherited from Object)
SetOption(ISocketOption, Object)
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, 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)
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)

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