DatagramChannel.Receive(ByteBuffer) Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Receives a datagram via this channel.
[Android.Runtime.Register("receive", "(Ljava/nio/ByteBuffer;)Ljava/net/SocketAddress;", "GetReceive_Ljava_nio_ByteBuffer_Handler")]
public abstract Java.Net.SocketAddress? Receive (Java.Nio.ByteBuffer? dst);
[<Android.Runtime.Register("receive", "(Ljava/nio/ByteBuffer;)Ljava/net/SocketAddress;", "GetReceive_Ljava_nio_ByteBuffer_Handler")>]
abstract member Receive : Java.Nio.ByteBuffer -> Java.Net.SocketAddress
Parameters
- dst
- ByteBuffer
The buffer into which the datagram is to be transferred
Returns
The datagram's source address,
or null
if this channel is in non-blocking mode
and no datagram was immediately available
- 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
Receives a datagram via this channel.
If a datagram is immediately available, or if this channel is in blocking mode and one eventually becomes available, then the datagram is copied into the given byte buffer and its source address is returned. If this channel is in non-blocking mode and a datagram is not immediately available then this method immediately returns null
.
The datagram is transferred into the given byte buffer starting at its current position, as if by a regular ReadableByteChannel#read(java.nio.ByteBuffer) read
operation. If there are fewer bytes remaining in the buffer than are required to hold the datagram then the remainder of the datagram is silently discarded.
This method performs exactly the same security checks as the java.net.DatagramSocket#receive receive
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 received this method verifies that the source's address and port number are permitted by the security manager's java.lang.SecurityManager#checkAccept checkAccept
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 read 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 invoking the #bind bind
method with a parameter of null
.
Java documentation for java.nio.channels.DatagramChannel.receive(java.nio.ByteBuffer)
.
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.