Skip to content

Most visited

Recently visited

navigation
Added in API level 1

ServerSocketChannel

public abstract class ServerSocketChannel
extends AbstractSelectableChannel

java.lang.Object
   ↳ java.nio.channels.spi.AbstractInterruptibleChannel
     ↳ java.nio.channels.SelectableChannel
       ↳ java.nio.channels.spi.AbstractSelectableChannel
         ↳ java.nio.channels.ServerSocketChannel


A ServerSocketChannel is a partial abstraction of a selectable, stream-oriented listening socket. Binding and manipulation of socket options can only be done through the associated ServerSocket object, returned by calling socket(). ServerSocketChannels can not be constructed for an already existing server-socket, nor can a SocketImpl be assigned.

A server-socket channel is open but not bound when created by the 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)

Constructs a new ServerSocketChannel.

Public methods

abstract SocketChannel accept()

Accepts a connection to this server-socket channel.

static ServerSocketChannel open()

Creates an open and unbound server-socket channel.

abstract ServerSocket socket()

Return the server-socket assigned this channel, which does not declare any public methods that are not declared in ServerSocket.

final int validOps()

Gets the valid operations of this channel.

Inherited methods

From class java.nio.channels.spi.AbstractSelectableChannel
From class java.nio.channels.SelectableChannel
From class java.nio.channels.spi.AbstractInterruptibleChannel
From class java.lang.Object
From interface java.nio.channels.Channel
From interface java.nio.channels.InterruptibleChannel
From interface java.io.Closeable
From interface java.lang.AutoCloseable

Protected constructors

ServerSocketChannel

Added in API level 1
ServerSocketChannel (SelectorProvider selectorProvider)

Constructs a new ServerSocketChannel.

Parameters
selectorProvider SelectorProvider: an instance of SelectorProvider.

Public methods

accept

Added in API level 1
SocketChannel accept ()

Accepts a connection to this server-socket channel.

This method returns null when this channel is non-blocking and no connection is available, otherwise it blocks until a new connection is available or an I/O error occurs. The socket channel returned by this method will always be in blocking mode.

This method just executes the same security checks as the accept() method of the ServerSocket class.

Returns
SocketChannel the accepted SocketChannel instance, or null if the channel is non-blocking and no connection is available.
Throws
AsynchronousCloseException if this channel is closed by another thread while this method is in operation.
ClosedByInterruptException if another thread interrupts the calling thread while this operation is in progress. The interrupt state of the calling thread is set and the channel is closed.
ClosedChannelException if this channel is closed.
IOException if another I/O error occurs.
NotYetBoundException if the socket has not yet been bound.

open

Added in API level 1
ServerSocketChannel open ()

Creates an open and unbound server-socket channel.

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

Returns
ServerSocketChannel the new channel which is open but unbound.
Throws
IOException if an I/O error occurs.

socket

Added in API level 1
ServerSocket socket ()

Return the server-socket assigned this channel, which does not declare any public methods that are not declared in ServerSocket.

Returns
ServerSocket the server-socket assigned to this channel.

validOps

Added in API level 1
int validOps ()

Gets the valid operations of this channel. Server-socket channels support accepting operation, so this method returns SelectionKey.OP_ACCEPT.

Returns
int the operations supported by this channel.

See also:

This site uses cookies to store your preferences for site-specific language and display options.

Hooray!

This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.