Socket.BeginReceiveMessageFrom(Byte[], Int32, Int32, SocketFlags, EndPoint, AsyncCallback, Object) Socket.BeginReceiveMessageFrom(Byte[], Int32, Int32, SocketFlags, EndPoint, AsyncCallback, Object) Socket.BeginReceiveMessageFrom(Byte[], Int32, Int32, SocketFlags, EndPoint, AsyncCallback, Object) Method


开始使用指定的 SocketFlags 将指定字节数的数据异步接收到数据缓冲区的指定位置,然后存储终结点和数据包信息。Begins to asynchronously receive the specified number of bytes of data into the specified location of the data buffer, using the specified SocketFlags, and stores the endpoint and packet information.

 IAsyncResult ^ BeginReceiveMessageFrom(cli::array <System::Byte> ^ buffer, int offset, int size, System::Net::Sockets::SocketFlags socketFlags, System::Net::EndPoint ^ % remoteEP, AsyncCallback ^ callback, System::Object ^ state);
public IAsyncResult BeginReceiveMessageFrom (byte[] buffer, int offset, int size, System.Net.Sockets.SocketFlags socketFlags, ref System.Net.EndPoint remoteEP, AsyncCallback callback, object state);
member this.BeginReceiveMessageFrom : byte[] * int * int * System.Net.Sockets.SocketFlags *  * AsyncCallback * obj -> IAsyncResult



Byte 类型的数组,它是存储接收到的数据的位置。An array of type Byte that is the storage location for the received data.

Int32 Int32 Int32

buffer 参数中存储数据的位置,该位置从零开始计数。The zero-based position in the buffer parameter at which to store the data.

Int32 Int32 Int32

要接收的字节数。The number of bytes to receive.

SocketFlags SocketFlags SocketFlags

SocketFlags 值的按位组合。A bitwise combination of the SocketFlags values.

EndPoint EndPoint EndPoint

一个 EndPoint,它表示数据的来源。An EndPoint that represents the source of the data.

Object Object Object

一个对象,它包含此请求的状态信息。An object that contains state information for this request.


引用异步读的 IAsyncResultAn IAsyncResult that references the asynchronous read.


buffernullbuffer is null.

- 或 --or- remoteEPnullremoteEP is null.

尝试访问套接字时出错。An error occurred when attempting to access the socket.

offset 小于 0。offset is less than 0.

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

- 或 --or- size 小于 0。size is less than 0.

- 或 --or- size 大于 buffer 的长度减去 offset 参数的值。size is greater than the length of buffer minus the value of the offset parameter.

操作系统为 Windows 2000 或更低版本,而此方法需要在 Windows XP 中使用。The operating system is Windows 2000 or earlier, and this method requires Windows XP.


异步接收操作必须通过调用完成EndReceiveMessageFrom方法。The asynchronous receive operation must be completed by calling the EndReceiveMessageFrom method. 通常情况下,通过调用该方法asyncCallback委托。Typically, the method is invoked by the asyncCallback delegate.

此方法不会阻止,直到操作完成。This method does not block until the operation completes. 若要阻止在操作完成之前,请使用ReceiveMessageFrom方法。To block until the operation completes, use the ReceiveMessageFrom method.

若要取消挂起BeginReceiveMessageFrom,调用Close方法。To cancel a pending BeginReceiveMessageFrom, call the Close method.

有关使用异步编程模型的详细信息,请参阅异步调用同步方法For detailed information about using the asynchronous programming model, see Calling Synchronous Methods Asynchronously

此方法将数据读入buffer参数,并捕获的远程主机终结点从其发送数据,以及有关接收的数据包的信息。This method reads data into the buffer parameter, and captures the remote host endpoint from which the data is sent, as well as information about the received packet. 有关如何检索此终结点的信息,请参阅EndReceiveFromFor information on how to retrieve this endpoint, refer to EndReceiveFrom. 此方法是最有用,如果你想要以异步方式从未知的主机或多个主机接收无连接的数据报。This method is most useful if you intend to asynchronously receive connectionless datagrams from an unknown host or multiple hosts.


如果你收到SocketException,使用SocketException.ErrorCode属性来获取特定错误代码。If you receive a SocketException, use the SocketException.ErrorCode property to obtain the specific error code. 获取此代码后,请参阅Windows 套接字版本 2 API 错误代码有关错误的详细说明的文档。After you have obtained this code, refer to the Windows Sockets version 2 API error code documentation for a detailed description of the error.


当你在应用程序中启用网络跟踪后,此成员将输出跟踪信息。This member outputs trace information when you enable network tracing in your application. 有关详细信息,请参阅在.NET Framework 中进行网络跟踪For more information, see Network Tracing in the .NET Framework.


为异步缓存的执行上下文 (的安全上下文中,被模拟的用户,并在调用上下文)Socket方法。The execution context (the security context, the impersonated user, and the calling context) is cached for the asynchronous Socket methods. 后首次使用特定的上下文 (特定于异步Socket方法中,特定Socket实例和特定的回调),以后使用该上下文将看到性能的改进。After the first use of a particular context (a specific asynchronous Socket method, a specific Socket instance, and a specific callback), subsequent uses of that context will see a performance improvement.