Methods Summary |
---|
public abstract java.nio.channels.DatagramChannel | connect(java.net.SocketAddress address)Connects the socket of this channel to a remote address, which is the
only communication peer for getting and sending datagrams after being
connected.
This method can be called at any time without affecting the read and
write operations being processed at the time the method is called. The
connection status does not change until the channel is disconnected or
closed.
This method executes the same security checks as the connect method of
the {@link DatagramSocket} class.
|
public abstract java.nio.channels.DatagramChannel | disconnect()Disconnects the socket of this channel, which has been connected before
in order to send and receive datagrams.
This method can be called at any time without affecting the read and
write operations being underway. It does not have any effect if the
socket is not connected or the channel is closed.
|
public abstract boolean | isConnected()Returns whether this channel's socket is connected or not.
|
public static java.nio.channels.DatagramChannel | open()Creates an opened and not-connected datagram channel.
This channel is created by calling the openDatagramChannel
method of the default {@link SelectorProvider} instance.
return SelectorProvider.provider().openDatagramChannel();
|
public abstract int | read(java.nio.ByteBuffer target)Reads a datagram from this channel into the byte buffer.
The precondition for calling this method is that the channel is connected
and the incoming datagram is from the connected address. If the buffer is
not big enough to store the datagram, the part of the datagram that does
not fit in the buffer is discarded. Otherwise, this method has the same
behavior as the {@code read} method in the {@link ReadableByteChannel}
interface.
|
public abstract long | read(java.nio.ByteBuffer[] targets, int offset, int length)Reads a datagram from this channel into an array of byte buffers.
The precondition for calling this method is that the channel is connected
and the incoming datagram is from the connected address. If the buffers
do not have enough remaining space to store the datagram, the part of the
datagram that does not fit in the buffers is discarded. Otherwise, this
method has the same behavior as the {@code read} method in the
{@link ScatteringByteChannel} interface.
|
public final synchronized long | read(java.nio.ByteBuffer[] targets)Reads a datagram from this channel into an array of byte buffers.
The precondition for calling this method is that the channel is connected
and the incoming datagram is from the connected address. If the buffers
do not have enough remaining space to store the datagram, the part of the
datagram that does not fit in the buffers is discarded. Otherwise, this
method has the same behavior as the {@code read} method in the
{@link ScatteringByteChannel} interface.
return read(targets, 0, targets.length);
|
public abstract java.net.SocketAddress | receive(java.nio.ByteBuffer target)Gets a datagram from this channel.
This method transfers a datagram from the channel into the target byte
buffer. If this channel is in blocking mode, it waits for the datagram
and returns its address when it is available. If this channel is in
non-blocking mode and no datagram is available, it returns {@code null}
immediately. The transfer starts at the current position of the buffer,
and if there is not enough space remaining in the buffer to store the
datagram then the part of the datagram that does not fit is discarded.
This method can be called at any time and it will block if there is
another thread that has started a read operation on the channel.
This method executes the same security checks as the receive method of
the {@link DatagramSocket} class.
|
public abstract int | send(java.nio.ByteBuffer source, java.net.SocketAddress address)Sends a datagram through this channel. The datagram consists of the
remaining bytes in {@code source}.
If this channel is in blocking mode then the datagram is sent as soon as
there is enough space in the underlying output buffer. If this channel is
in non-blocking mode then the datagram is only sent if there is enough
space in the underlying output buffer at that moment. The transfer action
is just like a regular write operation.
This method can be called at any time and it will block if another thread
has started a send operation on this channel.
This method executes the same security checks as the send method of the
{@link DatagramSocket} class.
|
public abstract java.net.DatagramSocket | socket()Returns the related datagram socket of this channel, which does not
define additional public methods to those defined by
{@link DatagramSocket}.
|
public final int | validOps()Gets the valid operations of this channel. Datagram channels support read
and write operations, so this method returns (
SelectionKey.OP_READ | SelectionKey.OP_WRITE ).
return (SelectionKey.OP_READ | SelectionKey.OP_WRITE);
|
public abstract int | write(java.nio.ByteBuffer source)Writes a datagram from the byte buffer to this channel.
The precondition of calling this method is that the channel is connected
and the datagram is sent to the connected address. Otherwise, this method
has the same behavior as the {@code write} method in the
{@link WritableByteChannel} interface.
|
public abstract long | write(java.nio.ByteBuffer[] sources, int offset, int length)Writes a datagram from the byte buffers to this channel.
The precondition of calling this method is that the channel is connected
and the datagram is sent to the connected address. Otherwise, this method
has the same behavior as the {@code write} method in the
{@link GatheringByteChannel} interface.
|
public final synchronized long | write(java.nio.ByteBuffer[] sources)Writes a datagram from the byte buffers to this channel.
The precondition of calling this method is that the channel is connected
and the datagram is sent to the connected address. Otherwise, this method
has the same behavior as the write method in the
{@link GatheringByteChannel} interface.
return write(sources, 0, sources.length);
|