Share via


DatagramChannel.Send(ByteBuffer, SocketAddress) Method

Definition

Sends a datagram via this channel.

[Android.Runtime.Register("send", "(Ljava/nio/ByteBuffer;Ljava/net/SocketAddress;)I", "GetSend_Ljava_nio_ByteBuffer_Ljava_net_SocketAddress_Handler")]
public abstract int Send (Java.Nio.ByteBuffer? src, Java.Net.SocketAddress? target);
[<Android.Runtime.Register("send", "(Ljava/nio/ByteBuffer;Ljava/net/SocketAddress;)I", "GetSend_Ljava_nio_ByteBuffer_Ljava_net_SocketAddress_Handler")>]
abstract member Send : Java.Nio.ByteBuffer * Java.Net.SocketAddress -> int

Parameters

src
ByteBuffer

The buffer containing the datagram to be sent

target
SocketAddress

The address to which the datagram is to be sent

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

Attributes

Exceptions

if the channel is already closed.

if the channel is closed by another thread while this method is in operation.

if another thread interrupts the calling thread while the operation is in progress. The calling thread will have the interrupt state set and the channel will be closed.

some other I/O error occurs.

Remarks

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 WritableByteChannel#write(java.nio.ByteBuffer) write operation.

This method performs exactly the same security checks as the java.net.DatagramSocket#send send method of the java.net.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 java.lang.SecurityManager#checkConnect checkConnect method. The overhead of this security check can be avoided by first connecting the socket via the #connect 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. If this channel's socket is not bound then this method will first cause the socket to be bound to an address that is assigned automatically, as if by invoking the #bind bind method with a parameter of null.

Java documentation for java.nio.channels.DatagramChannel.send(java.nio.ByteBuffer, java.net.SocketAddress).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to