Peek Method

Overview

Type:

Method

Available as of:

V1.0.4.0

Task

Read data stored in the receive buffer without removing it.

Functional Description

Reads data stored in the receive buffer without removing it from there after it has been read.

The Peek method can be used if a certain amount of data needs to be available to be processed correctly and the amount can be determined from parts of the data (a length field for example). In that case, the data can be copied to the application in one call of the Receive method.

The UDINT return value indicates the number of bytes written to the application-provided buffer.

Considerations for Connections Using TLS

The behavior of the methods Peek and Receive might be different for the connections with TLS and without TLS. Especially when large data packets are exchanged. When executing the methods on a connection using TLS, it might be required that several method calls must be executed until all data are copied or moved to the application buffer. In every case before processing the data, verify the amount of data which was copied or moved and whether the data are complete.

Interface

Input

Data type

Valid range

Description

i_pbyReceiveBuffer

POINTER TO BYTE

-

Start address of the buffer to write the received data to.

i_udiReceiveBufferSize

UDINT

1 ... 2147483647

Number of bytes to be read.

NOTE: The value must not be greater than the size of the buffer.
NOTE: To prevent access violation caused by invalid pointer access (out of bounds) to the memory, use the arithmetic operator SIZEOF in conjunction with the targeted buffer to determine the value for i_udiReceiveBufferSize.

Data Limits per Function Call

Depending on the controller, the amount of data to be moved in one function call of one of the Receive, Send or Peek methods is limited.

Controller

Number of bytes which can be moved at once*

M241, M251

2048 bytes

PacDrive LMC, M262

9.000.000 bytes (limited by the application memory)

*This is the maximum value for the difference between buffer size and fill level.

Used by

  • FB_TCPClient/FB_TCPClient2