Click to Rate and Give Feedback
MSDN
MSDN Library
.NET Development
.NET Framework 3.5
Socket Class
Socket Methods
 ReceiveMessageFromAsync Method

  Switch on low bandwidth view
This page is specific to
Microsoft Visual Studio 2008/.NET Framework 3.5

Other versions are also available for the following:
.NET Framework Class Library
Socket..::.ReceiveMessageFromAsync Method

Begins to asynchronously receive the specified number of bytes of data into the specified location in the data buffer, using the specified SocketAsyncEventArgs..::.SocketFlags, and stores the endpoint and packet information.

Namespace:  System.Net.Sockets
Assembly:  System (in System.dll)
Visual Basic (Declaration)
Public Function ReceiveMessageFromAsync ( _
    e As SocketAsyncEventArgs _
) As Boolean
Visual Basic (Usage)
Dim instance As Socket
Dim e As SocketAsyncEventArgs
Dim returnValue As Boolean

returnValue = instance.ReceiveMessageFromAsync(e)
C#
public bool ReceiveMessageFromAsync(
    SocketAsyncEventArgs e
)
Visual C++
public:
bool ReceiveMessageFromAsync(
    SocketAsyncEventArgs^ e
)
JScript
public function ReceiveMessageFromAsync(
    e : SocketAsyncEventArgs
) : boolean

Parameters

e
Type: System.Net.Sockets..::.SocketAsyncEventArgs
The System.Net.Sockets..::.SocketAsyncEventArgs object to use for this asynchronous socket operation.

Return Value

Type: System..::.Boolean
Returns true if the I/O operation is pending. The SocketAsyncEventArgs..::.Completed event on the e parameter will be raised upon completion of the operation.
Returns false if the I/O operation completed synchronously. In this case, The SocketAsyncEventArgs..::.Completed event on the e parameter will not be raised and the e object passed as a parameter may be examined immediately after the method call returns to retrieve the result of the operation.
ExceptionCondition
ArgumentNullException

The SocketAsyncEventArgs..::.RemoteEndPoint cannot be null.

NotSupportedException

Windows XP or later is required for this method.

ObjectDisposedException

The Socket has been closed.

SocketException

An error occurred when attempting to access the socket.

The ReceiveMessageFromAsync method is used primarily to receive message data on a connectionless socket. The socket's local address must be known. This method can only be used with datagram and raw sockets. The socket must be initialized with the socket type set to Dgram or Raw before calling this method. This can be done when the socket is constructed using Socket.

The caller must set the SocketAsyncEventArgs..::.RemoteEndPoint property to the IPEndPoint of the remote host from which the data is to be received.

The following properties and events on the System.Net.Sockets..::.SocketAsyncEventArgs object are required to successfully call this method:

The caller may set the SocketAsyncEventArgs..::.UserToken property to any user state object desired before calling the ReceiveMessageFromAsync method, so that the information will be retrievable in the callback method. If the callback needs more information than a single object, a small class can be created to hold the other required state information as members.

For message-oriented sockets, an incoming message is placed into the buffer up to the total size of the buffer. The SocketAsyncEventArgs..::.Count and SocketAsyncEventArgs..::.Offset properties determine where in the buffer the data is placed and the amount of data.

The ReceiveMessageFromAsync method automatically sets the PacketInformation socket option to true the first time it is called for a given Socket. However, the IPPacketInformation object will only be valid for packets which arrive at the local computer after the socket option has been set. If a socket is sent packets between when the socket is bound to a local endpoint (explicitly by the Bind method or implicitly by one of the Connect, ConnectAsync, SendTo, or SendToAsync methods) and the first call to the ReceiveMessageFromAsync method, calls to ReceiveMessageFromAsync method will result in invalid IPPacketInformation objects for these packets.

To ensure that all IPPacketInformation objects are valid, an application should set the PacketInformation socket option to true before it is bound to a local endpoint using the SetSocketOption(SocketOptionLevel, SocketOptionName, Boolean) method.

An application can examine the resulting IPPacketInformation objects if it needs to know if the datagram was sent using a unicast, multicast, or broadcast address.

Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5 SP1, 3.0 SP1, 2.0 SP1
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker