public abstract class SocketChannel extends java.nio.channels.spi.AbstractSelectableChannel implements ByteChannel, ScatteringByteChannel, GatheringByteChannel
| Modifier | Constructor and Description |
|---|---|
protected |
SocketChannel(java.nio.channels.spi.SelectorProvider provider)
Initializes this socket channel.
|
| Modifier and Type | Method and Description |
|---|---|
abstract boolean |
connect(java.net.SocketAddress remote)
Connects the channel's socket to the remote address.
|
abstract boolean |
finishConnect()
Finishes the process of connecting a socket channel.
|
abstract boolean |
isConnected()
Tells whether or not the channel's socket is connected.
|
abstract boolean |
isConnectionPending()
Tells whether or not a connection operation is in progress on this channel.
|
static SocketChannel |
open()
Opens a socket channel.
|
static SocketChannel |
open(java.net.SocketAddress remote)
Opens a channel and connects it to a remote address.
|
abstract int |
read(java.nio.ByteBuffer dst)
Reads data from the channel.
|
long |
read(java.nio.ByteBuffer[] dsts)
Reads data from the channel.
|
abstract long |
read(java.nio.ByteBuffer[] dsts,
int offset,
int length)
Reads data from the channel.
|
abstract java.net.Socket |
socket()
Retrieves the channel's socket.
|
int |
validOps()
Retrieves the valid operations for this channel.
|
abstract int |
write(java.nio.ByteBuffer src)
Writes data to the channel.
|
long |
write(java.nio.ByteBuffer[] dsts)
Writes data to the channel.
|
abstract long |
write(java.nio.ByteBuffer[] srcs,
int offset,
int length)
Writes data to the channel.
|
blockingLock, configureBlocking, implCloseChannel, implCloseSelectableChannel, implConfigureBlocking, isBlocking, isRegistered, keyFor, provider, registerregisterbegin, close, end, isOpenprotected SocketChannel(java.nio.channels.spi.SelectorProvider provider)
public static SocketChannel open() throws java.io.IOException
SocketChannel objectjava.io.IOException - If an error occurspublic static SocketChannel open(java.net.SocketAddress remote) throws java.io.IOException
SocketChannel objectAsynchronousCloseException - If this channel is already connected.ClosedByInterruptException - If another thread interrupts the
current thread while the connect operation is in progress, thereby closing
the channel and setting the current thread's interrupt status.java.io.IOException - If an error occursjava.lang.SecurityException - If a security manager has been installed and
it does not permit access to the given remote endpoint.UnresolvedAddressException - If the given remote address is not
fully resolved.UnsupportedAddressTypeException - If the type of the given remote
address is not supported.public final long read(java.nio.ByteBuffer[] dsts) throws java.io.IOException
read in interface ScatteringByteChanneljava.io.IOException - If an error occursNotYetConnectedException - If this channel is not yet connected.public final long write(java.nio.ByteBuffer[] dsts) throws java.io.IOException
write in interface GatheringByteChanneljava.io.IOException - If an error occursNotYetConnectedException - If this channel is not yet connected.public final int validOps()
validOps in class SelectableChannelpublic abstract int read(java.nio.ByteBuffer dst) throws java.io.IOException
read in interface ReadableByteChanneldst - the buffer to put the read data intojava.io.IOException - If an error occursNotYetConnectedException - If this channel is not yet connected.public abstract boolean connect(java.net.SocketAddress remote) throws java.io.IOException
true if the channel got successfully connected,
false if the channel is in non-blocking mode and connection
operation is still in progress.AlreadyConnectedException - If this channel is already connected.AsynchronousCloseException - If this channel is already connected.ClosedByInterruptException - If another thread interrupts the
current thread while the connect operation is in progress, thereby closing
the channel and setting the current thread's interrupt status.ClosedChannelException - If this channel is closed.ConnectionPendingException - If a non-blocking connection
operation is already in progress on this channel.java.io.IOException - If an error occursjava.lang.SecurityException - If a security manager has been installed and
it does not permit access to the given remote endpoint.UnresolvedAddressException - If the given remote address is not
fully resolved.UnsupportedAddressTypeException - If the type of the given remote
address is not supported.public abstract boolean finishConnect() throws java.io.IOException
AsynchronousCloseException - If this channel is already connected.ClosedByInterruptException - If another thread interrupts the
current thread while the connect operation is in progress, thereby closing
the channel and setting the current thread's interrupt status.ClosedChannelException - If this channel is closed.java.io.IOException - If an error occursNoConnectionPendingException - If this channel is not connected
and a connection operation has not been initiated.public abstract boolean isConnected()
public abstract boolean isConnectionPending()
public abstract long read(java.nio.ByteBuffer[] dsts, int offset, int length) throws java.io.IOException
read in interface ScatteringByteChanneljava.io.IOException - If an error occursNotYetConnectedException - If this channel is not yet connected.public abstract java.net.Socket socket()
public abstract int write(java.nio.ByteBuffer src) throws java.io.IOException
write in interface WritableByteChanneljava.io.IOException - If an error occursNotYetConnectedException - If this channel is not yet connected.public abstract long write(java.nio.ByteBuffer[] srcs, int offset, int length) throws java.io.IOException
write in interface GatheringByteChanneljava.io.IOException - If an error occursNotYetConnectedException - If this channel is not yet connected.