IPeer.Receive2 (METH)ΒΆ

METHOD Receive2 : ERROR

This method serves to receive data.
The pointer pData specifies the memory area to write the read data to. udiSize defines the max number of bytes to read. When data was read successfully, udiCount indicates the actually read number of bytes.
itfIPAddressFrom and uiPortFrom indicate the ip and port the data was received from.

Below is an example of how to handle the itfIPAddressFrom parameter. It is necessary to assign an instance of NBS.IPv4Address to a variable of type NBS.IIPAddress.

 VAR
     eErrorID : NBS.ERROR;
     myPeer : NBS.UDP_Peer;
     abyBuffer : ARRAY[0..1023] OF BYTE;
     myIPAddressFrom : NBS.IPv4Address;
     itfIPAddressFrom : NBS.IIPAddress := myIPAddressFrom;
     uiPortFrom : UINT;
     udiCount : UDINT;
     eTransmission : NBS.TRANSMISSION;
     myIPFrom : ARRAY[0..3] OF BYTE;
 END_VAR

 eErrorID := myPeer.Receive(
     ADR(abyBuffer), SIZEOF(abyBuffer),
     itfIPAddressFrom:=itfIPAddressFrom, uiPortFrom=>uiPortFrom,
     udiCount=>udiCount,
     eTransmission=>eTransmission
 );

IF eErrorID = NBS.ERROR.NO_ERROR THEN
    myIPFrom := myIPAddressFrom.GetIPasByteArray(eError=>eErrorID);
END_IF
InOut:

Scope

Name

Type

Return

Receive2

ERROR

Input

pData

__XWORD

udiSize

UDINT

Inout

itfIPAddressFrom

IIPAddress

Output

uiPortFrom

UINT

udiCount

UDINT

eTransmission

TRANSMISSION