java.nio.channels

Class DatagramChannel

public abstract class DatagramChannel extends AbstractSelectableChannel implements ByteChannel, ScatteringByteChannel, GatheringByteChannel

Since: 1.4

Constructor Summary
protected DatagramChannel(SelectorProvider provider)
Initializes the channel.
Method Summary
abstract DatagramChannelconnect(SocketAddress remote)
Connects this channel's socket.
abstract DatagramChanneldisconnect()
Disonnects this channel's socket.
abstract booleanisConnected()
Tells whether or not this channel's socket is connected.
static DatagramChannelopen()
Opens a datagram channel.
longread(ByteBuffer[] dsts)
Reads data from this channel.
abstract intread(ByteBuffer dst)
Reads data from this channel.
abstract longread(ByteBuffer[] dsts, int offset, int length)
Reads data from this channel.
abstract SocketAddressreceive(ByteBuffer dst)
Receives a datagram via this channel.
abstract intsend(ByteBuffer src, SocketAddress target)
Sends a datagram via this channel.
abstract DatagramSocketsocket()
Retrieves the channel's socket.
intvalidOps()
Retrieves the valid operations for this channel.
longwrite(ByteBuffer[] srcs)
Writes data to this channel.
abstract intwrite(ByteBuffer src)
Writes data to this channel.
abstract longwrite(ByteBuffer[] srcs, int offset, int length)
Writes data to this channel.

Constructor Detail

DatagramChannel

protected DatagramChannel(SelectorProvider provider)
Initializes the channel.

Method Detail

connect

public abstract DatagramChannel connect(SocketAddress remote)
Connects this channel's socket.

Throws: AsynchronousCloseException If another thread closes this channel while the connect operation is in progress. ClosedByInterruptException If another thread interrupts the current thread while the read operation is in progress, thereby closing the channel and setting the current thread's interrupt status. ClosedChannelException If this channel is closed. IOException If an error occurs. SecurityException If a security manager has been installed and it does not permit datagrams to be sent to the given address.

disconnect

public abstract DatagramChannel disconnect()
Disonnects this channel's socket.

Throws: IOException If an error occurs

isConnected

public abstract boolean isConnected()
Tells whether or not this channel's socket is connected.

Throws: NotYetConnectedException The channel's socket is not connected.

open

public static DatagramChannel open()
Opens a datagram channel.

Throws: IOException If an error occurs

read

public final long read(ByteBuffer[] dsts)
Reads data from this channel.

read

public abstract int read(ByteBuffer dst)
Reads data from this channel.

read

public abstract long read(ByteBuffer[] dsts, int offset, int length)
Reads data from this channel.

Throws: IOException If an error occurs. NotYetConnectedException The channel's socket is not connected.

receive

public abstract SocketAddress receive(ByteBuffer dst)
Receives a datagram via this channel.

Throws: AsynchronousCloseException If another thread closes this channel while the connect operation is in progress. ClosedByInterruptException If another thread interrupts the current thread while the read operation is in progress, thereby closing the channel and setting the current thread's interrupt status. ClosedChannelException If this channel is closed. IOException If an error occurs SecurityException If a security manager has been installed and it does not permit datagrams to be sent to the given address.

send

public abstract int send(ByteBuffer src, SocketAddress target)
Sends a datagram via this channel.

Throws: AsynchronousCloseException If another thread closes this channel while the connect operation is in progress. ClosedByInterruptException If another thread interrupts the current thread while the read operation is in progress, thereby closing the channel and setting the current thread's interrupt status. ClosedChannelException If this channel is closed. IOException If an error occurs SecurityException If a security manager has been installed and it does not permit datagrams to be sent to the given address.

socket

public abstract DatagramSocket socket()
Retrieves the channel's socket.

validOps

public final int validOps()
Retrieves the valid operations for this channel.

Throws: NotYetConnectedException The channel's socket is not connected.

write

public final long write(ByteBuffer[] srcs)
Writes data to this channel.

Throws: IOException If an error occurs NotYetConnectedException The channel's socket is not connected.

write

public abstract int write(ByteBuffer src)
Writes data to this channel.

Throws: IOException If an error occurs. NotYetConnectedException The channel's socket is not connected.

write

public abstract long write(ByteBuffer[] srcs, int offset, int length)
Writes data to this channel.

Throws: IOException If an error occurs. NotYetConnectedException The channel's socket is not connected.