java.nio.channels
Class DatagramChannel
java.lang.Object
|
+--java.nio.channels.spi.AbstractInterruptibleChannel
|
+--java.nio.channels.SelectableChannel
|
+--java.nio.channels.spi.AbstractSelectableChannel
|
+--java.nio.channels.DatagramChannel
All Implemented Interfaces:
ByteChannel, ScatteringByteChannel, GatheringByteChannel, Channel, InterruptibleChannel
Since:DatagramChannel
protected DatagramChannel(java.nio.channels.spi.SelectorProvider provider)
Initializes the channel.
Parameters:
connect
public DatagramChannel connect(java.net.SocketAddress remote)
Connects this channel's socket.
Parameters:
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 DatagramChannel disconnect()
Disonnects this channel's socket.
Throws:
isConnected
public boolean isConnected()
Tells whether or not this channel's socket is connected.
Throws:
open
public static DatagramChannel open()
Opens a datagram channel.
Throws:
read
public final long read(java.nio.ByteBuffer[] dsts)
Reads data from this channel.
Parameters:
read
public int read(java.nio.ByteBuffer dst)
Reads data from this channel.
Parameters:
read
public long read(java.nio.ByteBuffer[] dsts, int offset, int length)
Reads data from this channel.
Parameters:
Throws:
receive
public SocketAddress receive(java.nio.ByteBuffer dst)
Receives a datagram via this channel.
Parameters:
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 occursSecurityException
- If a security manager has been installed and
it does not permit datagrams to be sent to the given address.
send
public int send(java.nio.ByteBuffer src, java.net.SocketAddress target)
Sends a datagram via this channel.
Parameters:
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 occursSecurityException
- If a security manager has been installed and
it does not permit datagrams to be sent to the given address.
socket
public DatagramSocket socket()
Retrieves the channel's socket.
validOps
public final int validOps()
Retrieves the valid operations for this channel.
Throws:
write
public final long write(java.nio.ByteBuffer[] srcs)
Writes data to this channel.
Parameters:
Throws:
write
public int write(java.nio.ByteBuffer src)
Writes data to this channel.
Parameters:
Throws:
write
public long write(java.nio.ByteBuffer[] srcs, int offset, int length)
Writes data to this channel.
Parameters:
Throws: