A server-socket channel is created by invoking one of the open
methods of this class. The no-arg open
method opens a server-socket
channel for an Internet protocol socket. The open(ProtocolFamily)
method is used to open a server-socket channel for a socket of a specified
protocol family. It is not possible to create a channel for an arbitrary,
pre-existing socket. A newly-created server-socket channel is open but not yet
bound. An attempt to invoke the accept
method of an
unbound server-socket channel will cause a NotYetBoundException
to be thrown. A server-socket channel can be bound by invoking one of the
bind
methods defined by this class.
Socket options are configured using the setOption
method. Server-socket channels for Internet protocol sockets
support the following options:
Option Name Description SO_RCVBUF
The size of the socket receive buffer SO_REUSEADDR
Re-use address
Server-socket channels for Unix domain sockets support:
Option Name Description SO_RCVBUF
The size of the socket receive buffer
Additional (implementation specific) options may also be supported.
Server-socket channels are safe for use by multiple concurrent threads.
Access | Constructor and Description |
---|---|
protected | ServerSocketChannel(SelectorProvider
The provider that created this channel provider)Initializes a new instance of this class. |
Modifier and Type | Method and Description |
---|---|
public abstract SocketChannel | Returns: The socket channel for the new connection, ornull if this channel is in non-blocking mode
and no connection is available to be acceptedAccepts a connection made to this channel's socket. |
public final ServerSocketChannel | Returns: This channelThe local address to bind the socket, or local)null to bind
to an automatically assigned socket addressImplements java. Binds the channel's socket to a local address and configures the socket to listen for connections. |
public abstract ServerSocketChannel | Returns: This channelThe address to bind the socket, or local, int null to bind to
an automatically assigned socket addressThe maximum number of pending connections backlog)Binds the channel's socket to a local address and configures the socket to listen for connections. |
public abstract SocketAddress | Returns: TheSocketAddress that the socket is bound to, or the
SocketAddress representing the loopback address or empty
path if denied by the security manager, or null if the
channel's socket is not boundRedeclares java. Returns the socket address that this channel's socket is bound to. |
public static ServerSocketChannel | |
public static ServerSocketChannel | Returns: A new socket channelThe protocol family family)Opens a server-socket channel. |
public abstract <T> ServerSocketChannel | setOption(SocketOption<T>
The socket option name, T The value of the socket option. A value of value)null may be
a valid value for some socket options.Redeclares java. Sets the value of a socket option. |
public abstract ServerSocket | Returns: A server socket associated with this channelRetrieves a server socket associated with this channel. |
public final int | Returns: The valid-operation setImplements abstract java. Returns an operation set identifying this channel's supported operations. |
ServerSocketChannel | back to summary |
---|---|
protected ServerSocketChannel(SelectorProvider provider) Initializes a new instance of this class.
|
accept | back to summary |
---|---|
public abstract SocketChannel accept() throws IOException Accepts a connection made to this channel's socket. If this channel is in non-blocking mode then this method will
immediately return The socket channel returned by this method, if any, will be in blocking mode regardless of the blocking mode of this channel. If bound to an Internet protocol socket address, this method
performs exactly the same security checks as the
|
bind | back to summary |
---|---|
public final ServerSocketChannel bind(SocketAddress local) throws IOException Implements java. Binds the channel's socket to a local address and configures the socket to listen for connections. An invocation of this method is equivalent to the following: bind(local, 0);
|
bind | back to summary |
---|---|
public abstract ServerSocketChannel bind(SocketAddress local, int backlog) throws IOException Binds the channel's socket to a local address and configures the socket to listen for connections. This method is used to establish an association between the socket and a local address. For Internet protocol sockets, once an association is established then the socket remains bound until the channel is closed. The API Note Binding a server socket channel for a Unix Domain socket, creates a
file corresponding to the file path in the Implementation Note Each platform enforces an implementation specific, maximum length for the name of a Unix Domain socket. This limitation is enforced when a channel is bound. The maximum length is typically close to and generally not less than 100 bytes. This limitation also applies to automatically bound server socket channels. See the Unix domain networking properties that can be used to select the temporary directory where these sockets are created.
|
getLocalAddress | back to summary |
---|---|
public abstract SocketAddress getLocalAddress() throws IOException Redeclares java. Doc from java. Returns the socket address that this channel's socket is bound to. Where the channel is Where the channel is bound to a Unix Domain socket address, the socket
address is a
|
open | back to summary |
---|---|
public static ServerSocketChannel open() throws IOException Opens a server-socket channel for an Internet protocol socket. The new channel is created by invoking the The new channel's socket is initially unbound; it must be bound to a
specific address via one of its socket's
|
open | back to summary |
---|---|
public static ServerSocketChannel open(ProtocolFamily family) throws IOException Opens a server-socket channel. The The new channel is created by invoking the
|
setOption | back to summary |
---|---|
public abstract <T> ServerSocketChannel setOption(SocketOption<T> name, T value) throws IOException Redeclares java. Doc from java. Sets the value of a socket option.
|
socket | back to summary |
---|---|
public abstract ServerSocket socket() Retrieves a server socket associated with this channel. The returned object will not declare any public methods that are not
declared in the
|
validOps | back to summary |
---|---|
public final int validOps() Implements abstract java. Returns an operation set identifying this channel's supported operations. Server-socket channels only support the accepting of new
connections, so this method returns
|