Build 1.0_r1(from source)

Class ServerSocketChannel

  extended by java.nio.channels.spi.AbstractInterruptibleChannel
      extended by java.nio.channels.SelectableChannel
          extended by java.nio.channels.spi.AbstractSelectableChannel
              extended by java.nio.channels.ServerSocketChannel
All Implemented Interfaces:
Closeable, Channel, InterruptibleChannel

public abstract class ServerSocketChannel
extends AbstractSelectableChannel

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.

Constructor Summary
protected ServerSocketChannel(SelectorProvider selectorProvider)
          Construct a new instance for ServerSocketChannel
Method Summary
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.
 int validOps()
          Get the valid operations of this channel.
Methods inherited from class java.nio.channels.spi.AbstractSelectableChannel
blockingLock, configureBlocking, implCloseChannel, implCloseSelectableChannel, implConfigureBlocking, isBlocking, isRegistered, keyFor, provider, register
Methods inherited from class java.nio.channels.SelectableChannel
Methods inherited from class java.nio.channels.spi.AbstractInterruptibleChannel
begin, close, end, isOpen
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface java.nio.channels.Channel
close, isOpen

Constructor Detail


protected ServerSocketChannel(SelectorProvider selectorProvider)
Construct a new instance for ServerSocketChannel

selectorProvider - An instance of SelectorProvider
Method Detail


public static ServerSocketChannel open()
                                throws IOException
Create an open and unbound server-socket channel.

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

The new created channel which is open but unbound.
IOException - If some IO problem occurs.


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.

Specified by:
validOps in class SelectableChannel
Valid operations in bit-set.
See Also:


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

The related ServerSocket instance.


public abstract SocketChannel accept()
                              throws IOException
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.

The accepted SocketChannel instance, or null as the channel is non-blocking and no connections available.
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.

Build 1.0_r1(from source)

Please submit a feedback, bug or feature