Receives 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.
Assembly: System (in System.dll)
public int ReceiveMessageFrom( byte buffer, int offset, int size, ref SocketFlags socketFlags, ref EndPoint remoteEP, out IPPacketInformation ipPacketInformation )
- Type: System.Int32
The position in the buffer parameter to store the received data.
- Type: System.Int32
The number of bytes to receive.
- Type: System.Net.EndPoint%
An EndPoint, passed by reference, that represents the remote server.
Return ValueType: System.Int32
The number of bytes received.
buffer is null.
remoteEP is null.
offset is less than 0.
offset is greater than the length of buffer.
size is less than 0.
size is greater than the length of the buffer minus the value of the offset parameter.
socketFlags is not a valid combination of values.
The LocalEndPoint property was not set.
The .NET Framework is running on an AMD 64-bit processor.
An error occurred when attempting to access the socket. See the Remarks section for more information.
The Socket has been closed.
The operating system is Windows 2000 or earlier, and this method requires Windows XP.
The method reads data into the buffer parameter, returns the number of bytes successfully read, and captures the remote host endpoint from which the data was sent, as well as information about the received packet.
The 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.
For message-oriented sockets, an incoming message is placed into the buffer parameter up to the total size specified in the size parameter. The offset parameter determines where in the buffer the data is placed. The actual amount of data placed into the buffer is returned by the method.
The method automatically method sets the PacketInformation socket option to true the first time it is called for a given Socket. However, the returned 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 it is bound to a local endpoint (explicitly by the Bind method or implicitly by one of the Connect, ConnectAsync, SendTo, or SendToAsync methods) and its first call to the method, calls to method will return 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 ipPacketInformation parameter if it needs to know if the datagram was sent using a unicast, multicast, or broadcast address.
This member outputs trace information when you enable network tracing in your application. For more information, see Network Tracing.
Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98
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.