TcpConnection.Peek (METH)

METHOD Peek : ERROR_ID

Peek is a method to read the data without deleting them from the TCP buffer.
Other than the TcpConnection.Receive method, Peek will not receive the telegrams stream wise.
Once it has read some data, the internal variables will be resetted.

Hint

The method does not work as a stream. For this, please use the Receive method.

Hint

SOCKET_MSG_PEEK is currently doing a BLOCKING call if no data are available in the TCP buffer.

VAR
    fbTcpConnection     : TcpConnection;        (* Instance of function block - can be either TcpConnection or TcpClient. Anyhow a communication must be established before using the Receive method() *)

    eErrorId            : AC500_Tcp.ERROR_ID;           (* Error Id of the Connect method *)
    dwAddErrNo          : AC500_Tcp.RTS_IEC_RESULT;     (* Additional error number - list available in GVL of CmpErrors.Erros library *)
    sDataPeek           : STRING(1000);                 (* Data buffer where the incoming message will be stored *)
    diRecvBytes         : DINT;                         (* Number of received bytes *)
END_VAR

------------
// Cyclic call of Peek()
eErrorId := fbTcpConnection.Receive(    Data        := ADR(sDataPeek),
                                        Size        := SIZEOF(sDataPeek),
                                        RecvBytes   => diRecvBytes,
                                        AddErrNo    => dwAddErrNo);

// As long as ERROR_ID = BUSY, the TcpConnection is waiting for incoming messages
IF eErrorId = AC500_Tcp.ERROR_ID.NO_ERROR OR eErrorId = AC500_Tcp.ERROR_ID.NO_ERROR_BUSY THEN

    // Something has been received without an error
    IF diRecvBytes > 0 THEN
        ;   // The received telegram/message is <> to 0
    END_IF
ELSIF eErrorId <> AC500_Tcp.ERROR_ID.BUSY THEN

    ;   // For ERR_INTERNAL, please check AddErrNo - AC500_Tcp.RTS_IEC_RESULT - the error codes are listed in the GVL of CmpErros.Errors

END_IF
InOut:

Scope

Name

Type

Comment

Return

Peek

ERROR_ID

Input

Data

POINTER TO BYTE

Pointer to the memory size where the data will be stored

Size

UDINT

Size of the datat to be received - maximum size of TCP packet is 64kB = 65 535 Bytes

Output

RecvBytes

DINT

Number of received bytes that has been read from the TCP stream

AddErrNo

RTS_IEC_RESULT

Additional error number gives information about error from SysSock2Close –> please see CmpErrors.Errors