SocketChannel class abstract
A selectable channel for stream-oriented connecting sockets.
A socket channel is created by invoking one of the {@link #open open} methods of this class. It is not possible to create a channel for an arbitrary, pre-existing socket. 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 {@link NotYetConnectedException} to be thrown. A socket channel can be connected by invoking its {@link #connect 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 {@link #isConnected 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 {@link #connect connect} method for later completion by the {@link #finishConnect finishConnect} method. Whether or not a connection operation is in progress may be determined by invoking the {@link #isConnectionPending isConnectionPending} method.
Socket channels support asynchronous shutdown, which is similar to the asynchronous close operation specified in the {@link 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 {@link AsynchronousCloseException}.
Socket options are configured using the {@link #setOption(SocketOption,Object) setOption} method. Socket channels support the following options:
Additional (implementation specific) options may also be supported.
Option Name Description {@link java.net.StandardSocketOptions#SO_SNDBUF SO_SNDBUF} The size of the socket send buffer {@link java.net.StandardSocketOptions#SO_RCVBUF SO_RCVBUF} The size of the socket receive buffer {@link java.net.StandardSocketOptions#SO_KEEPALIVE SO_KEEPALIVE} Keep connection alive {@link java.net.StandardSocketOptions#SO_REUSEADDR SO_REUSEADDR} Re-use address {@link java.net.StandardSocketOptions#SO_LINGER SO_LINGER} Linger on close if data is present (when configured in blocking mode only) {@link java.net.StandardSocketOptions#TCP_NODELAY TCP_NODELAY} Disable the Nagle algorithm
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 {@link #connect connect} and {@link #finishConnect 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.
- Inheritance
- Implemented types
Constructors
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- isBlocking → bool
-
Tells whether or not every I/O operation on this channel will block
until it completes. A newly-created channel is always in blocking mode.
no setterinherited
- isBound → bool
-
no setter
- isClosed → bool
-
Tells whether or not this channel is open.
no setterinherited
- isConnected → bool
-
Tells whether or not this channel's network socket is connected.
no setter
- localAddress → SocketAddress?
-
See {@inheritDoc}
no setteroverride
- remoteAddress → SocketAddress?
-
Returns the remote address to which this channel's socket is connected.
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
bind(
SocketAddress local) → Future< SocketChannel?> -
Binds the channel's socket to a local address.
override
-
close(
) → Future< void> -
Closes this stream and releases any system resources associated
with it. If the stream is already closed then invoking this
method has no effect.
inherited
-
configureBlocking(
bool block) → SelectableChannel? -
Adjusts this channel's blocking mode.
inherited
-
connect(
SocketAddress remote) → Future< bool> - Connects this channel's socket.
-
implCloseChannel(
) → Future< void> -
Closes this channel.
inherited
-
implConfigureBlocking(
bool block) → void -
Adjusts this channel's blocking mode.
inherited
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
read(
int maxLen) → Future< Uint8List?> -
Reads a sequence of bytes from this channel into the given buffer.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
-
write(
Uint8List src) → Future< int> -
Writes a sequence of bytes to this channel from the given buffer.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited