Socket.ReceiveMessageFrom Method

Note: This method is new in the .NET Framework version 2.0.

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.

Namespace: System.Net.Sockets
Assembly: System (in system.dll)

public int ReceiveMessageFrom (
	byte[] buffer,
	int offset,
	int size,
	ref SocketFlags socketFlags,
	ref EndPoint remoteEP,
	out IPPacketInformation ipPacketInformation
public int ReceiveMessageFrom (
	byte[] buffer, 
	int offset, 
	int size, 
	/** @ref */ SocketFlags socketFlags, 
	/** @ref */ EndPoint remoteEP, 
	/** @attribute OutAttribute() */ /** @ref */ IPPacketInformation ipPacketInformation
JScript does not support passing value-type arguments by reference.



An array of type Byte that is the storage location for received data.


The position in the buffer parameter to store the received data.


The number of bytes to receive.


A bitwise combination of the SocketFlags values.


An EndPoint, passed by reference, that represents the remote server.


An IPPacketInformation holding address and interface information.

Return Value

The number of bytes received.

Exception typeCondition


buffer is a null reference (Nothing in Visual Basic).

- or-

remoteEP is a null reference (Nothing in Visual Basic).


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 ReceiveMessageFrom 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.

Examine ipPacketInformation if you need to know if the datagram was sent using a unicast, multicast, or broadcast address.


The AddressFamily of the EndPoint used in ReceiveFrom needs to match the AddressFamily of the EndPoint used in SendTo.


This member outputs trace information when you enable network tracing in your application. For more information, see Network Tracing.

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

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

.NET Framework

Supported in: 2.0