Android
java.nio.channels
public abstract class

java.nio.channels.ServerSocketChannel

java.lang.Object
java.nio.channels.spi.AbstractInterruptibleChannel Channel InterruptibleChannel
java.nio.channels.SelectableChannel Channel
java.nio.channels.spi.AbstractSelectableChannel
java.nio.channels.ServerSocketChannel

A ServerSocketChannel is a partly abstracted stream-oriented listening socket which is selectable. Binding and manipulation of socket options can only be done through the associated ServerSocket object, returned by calling socket method. ServerSocketChannels can not be constructed for a pre-existing server socket, nor can it be assigned a SocketImpl.

A Server-Socket channel is open but not bound when created by open method. (Calling accept before bound will cause a NotYetBoundException). It can be bound by calling the bind method of a related ServerSocket instance.

Summary

Protected Constructors

            ServerSocketChannel(SelectorProvider selectorProvider)
Construct a new instance for ServerSocketChannel

Public Methods

abstract          SocketChannel  accept()
Accepts a connection to this socket.
      static    ServerSocketChannel  open()
Create an open and unbound server-socket channel.
abstract          ServerSocket  socket()
Return the related server-socket of this channel.
    final      int  validOps()
Get the valid operations of this channel.
Methods inherited from class java.nio.channels.spi.AbstractSelectableChannel
Methods inherited from class java.nio.channels.SelectableChannel
Methods inherited from class java.nio.channels.spi.AbstractInterruptibleChannel
Methods inherited from class java.lang.Object
Methods inherited from interface java.io.Closeable
Methods inherited from interface java.nio.channels.Channel
Methods inherited from interface java.nio.channels.InterruptibleChannel

Details

Protected Constructors

protected ServerSocketChannel(SelectorProvider selectorProvider)

Construct a new instance for ServerSocketChannel

Parameters

selectorProvider An instance of SelectorProvider

Public Methods

public abstract SocketChannel accept()

Accepts a connection to this socket.

It returns null when the channel is non-blocking and no connections available, otherwise it blocks indefinitely until a new connection is available or an I/O error occurs. The returned channel will be in blocking mode any way.

This method just execute the same security checks as the accept method of the ServerSocket class.

Returns

  • The accepted SocketChannel instance, or null as the channel is non-blocking and no connections available.

Throws

ClosedChannelException If the channel is already closed.
AsynchronousCloseException If the channel is closed by another thread while this method is in operation.
ClosedByInterruptException If another thread interrupts the calling thread while the operation is in progress. The calling thread will have the interrupt state set, and the channel will be closed.
NotYetBoundException If the socket has not yet been bound.
SecurityException If there is a security manager, and the new connection is not permitted to access.
IOException Some other IO error occurred.

public static ServerSocketChannel open()

Create an open and unbound server-socket channel.

This channel is got by calling openServerSocketChannel method of the default SelectorProvider instance.

Returns

  • The new created channel which is open but unbound.

Throws

IOException If some IO problem occurs.

public abstract ServerSocket socket()

Return the related server-socket of this channel. All public methods declared in returned object should be declared in ServerSocket.

Returns

  • The related ServerSocket instance.

public final int validOps()

Get the valid operations of this channel. Server-socket channels support accepting operation.Currently the only supported operation is OP_ACCEPT. It always returns SelectionKey.OP_ACCEPT.

Returns

  • Valid operations in bit-set.

See Also

Copyright 2007 Google Inc. Build 0.9_r1-98467 - 14 Aug 2008 18:56