A selectable channel for stream-oriented connecting sockets.
Socket channels are not a complete abstraction of connecting network
sockets. Binding, shutdown, and the manipulation of socket options must be
done through an associated Socket object obtained by
invoking the socket method. It is not possible to create
a channel for an arbitrary, pre-existing socket, nor is it possible to
specify the SocketImpl object to be used by a socket
associated with a socket channel.
A socket channel is created by invoking one of the open
methods of this class. A newly-created socket channel is open but not yet
connected. An attempt to invoke an I/O operation upon an unconnected
channel will cause a NotYetConnectedException to be thrown. A
socket channel can be connected by invoking its connect
method; once connected, a socket channel remains connected until it is
closed. Whether or not a socket channel is connected may be determined by
invoking its isConnected method.
Socket channels support non-blocking connection: A socket
channel may be created and the process of establishing the link to the
remote socket may be initiated via the connect method for
later completion by the finishConnect method.
Whether or not a connection operation is in progress may be determined by
invoking the isConnectionPending method.
The input and output sides of a socket channel may independently be
shut down without actually closing the channel. Shutting down the
input side of a channel by invoking the shutdownInput method of an associated socket object will cause further
reads on the channel to return -1, the end-of-stream indication.
Shutting down the output side of the channel by invoking the shutdownOutput method of an associated
socket object will cause further writes on the channel to throw a ClosedChannelException .
Socket channels support asynchronous shutdown, which is similar
to the asynchronous close operation specified in the Channel class.
If the input side of a socket is shut down by one thread while another
thread is blocked in a read operation on the socket's channel, then the read
operation in the blocked thread will complete without reading any bytes and
will return -1. If the output side of a socket is shut down by one
thread while another thread is blocked in a write operation on the socket's
channel, then the blocked thread will receive an AsynchronousCloseException .
Socket channels are safe for use by multiple concurrent threads. They
support concurrent reading and writing, though at most one thread may be
reading and at most one thread may be writing at any given time. The connect and finishConnect methods are
mutually synchronized against each other, and an attempt to initiate a read
or write operation while an invocation of one of these methods is in
progress will block until that invocation is complete.
Socket channels are not a complete abstraction of connecting network sockets. Binding, shutdown, and the manipulation of socket options must be done through an associated Socket object obtained by invoking the socket method. It is not possible to create a channel for an arbitrary, pre-existing socket, nor is it possible to specify the SocketImpl object to be used by a socket associated with a socket channel.
A socket channel is created by invoking one of the open methods of this class. A newly-created socket channel is open but not yet connected. An attempt to invoke an I/O operation upon an unconnected channel will cause a NotYetConnectedException to be thrown. A socket channel can be connected by invoking its connect method; once connected, a socket channel remains connected until it is closed. Whether or not a socket channel is connected may be determined by invoking its isConnected method.
Socket channels support non-blocking connection: A socket channel may be created and the process of establishing the link to the remote socket may be initiated via the connect method for later completion by the finishConnect method. Whether or not a connection operation is in progress may be determined by invoking the isConnectionPending method.
The input and output sides of a socket channel may independently be shut down without actually closing the channel. Shutting down the input side of a channel by invoking the shutdownInput method of an associated socket object will cause further reads on the channel to return -1, the end-of-stream indication. Shutting down the output side of the channel by invoking the shutdownOutput method of an associated socket object will cause further writes on the channel to throw a ClosedChannelException .
Socket channels support asynchronous shutdown, which is similar to the asynchronous close operation specified in the Channel class. If the input side of a socket is shut down by one thread while another thread is blocked in a read operation on the socket's channel, then the read operation in the blocked thread will complete without reading any bytes and will return -1. If the output side of a socket is shut down by one thread while another thread is blocked in a write operation on the socket's channel, then the blocked thread will receive an AsynchronousCloseException .
Socket channels are safe for use by multiple concurrent threads. They support concurrent reading and writing, though at most one thread may be reading and at most one thread may be writing at any given time. The connect and finishConnect methods are mutually synchronized against each other, and an attempt to initiate a read or write operation while an invocation of one of these methods is in progress will block until that invocation is complete.