Sends a datagram via this channel.
If this channel is in non-blocking mode and there is sufficient room
in the underlying output buffer, or if this channel is in blocking mode
and sufficient room becomes available, then the remaining bytes in the
given buffer are transmitted as a single datagram to the given target
address.
The datagram is transferred from the byte buffer as if by a regular
write
operation.
This method performs exactly the same security checks as the send
method of the DatagramSocket
class. That is, if the socket is not connected
to a specific remote address and a security manager has been installed
then for each datagram sent this method verifies that the target address
and port number are permitted by the security manager's checkConnect
method. The
overhead of this security check can be avoided by first connecting the
socket via the connect
method.
This method may be invoked at any time. If another thread has
already initiated a write operation upon this channel, however, then an
invocation of this method will block until the first operation is
complete.
Returns:
The number of bytes sent, which will be either the number
of bytes that were remaining in the source buffer when this
method was invoked or, if this channel is non-blocking, may be
zero if there was insufficient room for the datagram in the
underlying output buffer
Parameters:
-
src - The buffer containing the datagram to be sent
-
target - The address to which the datagram is to be sent
Throws:
-
ClosedChannelException - If this channel is closed
-
AsynchronousCloseException - If another thread closes this channel
while the read 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
-
SecurityException - If a security manager has been installed
and it does not permit datagrams to be sent
to the given address
-
IOException - If some other I/O error occurs