UdpSingleSourceMulticastClient.BeginReceiveFromSource(Byte[], Int32, Int32, AsyncCallback, Object) 方法

定义

注意

This API supports the .NET Framework infrastructure and is not intended to be used directly from your code.

开始执行从已联接的多播组接收数据包的操作,并在来自指定发送器的数据包到达组时调用指定的回叫。Begins the operation of receiving a packet from the joined multicast group and invokes the specified callback when a packet has arrived on the group from a specified sender.

public:
 IAsyncResult ^ BeginReceiveFromSource(cli::array <System::Byte> ^ buffer, int offset, int count, AsyncCallback ^ callback, System::Object ^ state);
[System.Obsolete("This API supports the .NET Framework infrastructure and is not intended to be used directly from your code.", true)]
public IAsyncResult BeginReceiveFromSource (byte[] buffer, int offset, int count, AsyncCallback callback, object state);
[<System.Obsolete("This API supports the .NET Framework infrastructure and is not intended to be used directly from your code.", true)>]
member this.BeginReceiveFromSource : byte[] * int * int * AsyncCallback * obj -> IAsyncResult
Public Function BeginReceiveFromSource (buffer As Byte(), offset As Integer, count As Integer, callback As AsyncCallback, state As Object) As IAsyncResult

参数

buffer
Byte[]

用于存储已接收数据的缓冲区。The buffer to store the received data.

offset
Int32

应存储数据的 buffer 开始处的偏移量(以字节为单位)。The offset, in bytes, from the beginning of the buffer where the data should be stored.

count
Int32

要接收并存储在 buffer 中的最大字节数。The maximum number of bytes to receive and store in the buffer.

callback
AsyncCallback

要在此操作完成时调用的回调方法。The callback method to invoke when the operation completes.

state
Object

要为此操作传递给 callback 方法的可选状态信息。Optional state information to pass to the callback method for this operation.

返回

IAsyncResult

引用此操作的 IAsyncResultAn IAsyncResult that references this operation.

属性

例外

buffer 为 null 引用(在 Visual Basic 中为 Nothing)。buffer is a null reference (Nothing in Visual Basic).

offset 小于 0offset is less than 0 - 或 --or- offset 大于 buffer 的长度。offset is greater than the length of the buffer.

- 或 --or- count 小于 0count is less than 0 - 或 --or- offset 加上此计数大于 buffer 的长度。offset plus the count is greater than the length of the buffer.

尚未联接多播组。The multicast group has not yet been joined.

试图访问供接收的套接字时发生错误。An error occurred when attempting to access the socket for receiving.

注解

BeginReceiveFromSource方法开始从一个发送方的已联接的多播组接收 UDP 数据包的操作。The BeginReceiveFromSource method begins an operation of receiving a UDP packet from the joined multicast group from a single sender. 本地端口、多播组和发件人源地址在 UdpSingleSourceMulticastClient 构造函数中指定。The local port, multicast group, and sender source address are specified in the UdpSingleSourceMulticastClient constructor. 多播客户端还必须已完成到多播组的联接。The multicast client must also have completed a join to the multicast group.

接收到数据包时,将调用参数中指定的方法 callbackThe method specified in the callback parameter is invoked when a packet has received.

如果接收操作同步失败,则可能会出现套接字故障,但这种情况不太常见。It is possible to have a socket failure if a receive operation fails synchronously, although this is uncommon with UDP. 如果出现套接字故障, SocketException 则会引发。If a socket failure occurs, a SocketException is thrown. 收到的错误被指定为枚举的成员 SocketErrorThe error received is specified as a member of the SocketError enumeration.

适用于