WebTcpipRecvProtoEx Function

Action

Like the WebTcpipRecvProto function, but with the additional possibility to verify a fixed portion of the tcp packet (by specifying its starting position and length), and two additional parameters to define the performed packet-length calculation (multiplication and addition). If the verification fails an error is raised.

Include file

WebAPI.bdh

Syntax

WebTcpipRecvProtoEx( in  hWeb          : number,
                     in  nProtoStart   : number,
                     in  nProtoLength  : number,
                     in  nOption       : number optional,
                     out sData         : string optional,
                     in  nMaxData      : number optional,
                     out nReceived     : number optional,
                     in  sVerify       : string optional,
                     in  nVerifyStart  : number optional,
                     in  nVerifyLength : number optional,
                     in  nMultiply     : number optional,
                     in  nAdd          : number optional ): boolean;

Return value

  • true if the receive operation succeeded

  • false otherwise

Parameter Description
hWeb Valid handle to a Web connection that was created by WebTcpipConnect.
nProtoStart Starting byte of the packet-length specification.
nProtoLength Length of the packet-length specification.
nOption

Specify any combination of following flags (optional):

  • TCP_FLAG_LITTLE_ENDIAN. Specifies the byte order of the packet-length section. Little-endian means, that the most significant byte is at the end. Big-endian (default) means, that the most significant byte is at the front of the packet-length section.

  • TCP_FLAG_INCLUDE_PROTO. Specify this flag to signal, that the bytes of the protocol header (ending with the specified packet-length section) are included in the calculated packet-length. If this flag is not set, the receive operation of the calculated packet-length starts after the protocol header.

  • TCP_FLAG_TextProto. Specify this option if the length specification is provided as a string (readable value). By default this value will be interpreted as a decimal number. Use TCP_FLAG_TextProtoHex for a hexadecimal number or TCP_FLAG_TextProtoOct for an octal representation.

  • TCP_FLAG_TextProtoNumberOnly. Specify this flag in combination with TCP_FLAG_TextProto if the length specification consists of an unknown number of digits and if the header is not included in the specified length (TCP_FLAG_INCLUDE_PROTO must not be specified). If specified the body starts after the last digit of the length specification.

  • TCP_FLAG_TextProtoHex. Use this flag in combination with the TCP_FLAG_TextProto option to interpret the length specification as a hexadecimal number.

  • TCP_FLAG_TextProtoOct. Use this flag in combination with the TCP_FLAG_TextProto option to interpret the length specification as an octal number.

sData

Buffer to store the received data (optional).

This field also can be set to NULL (default) to use only internal buffers, for example, if data is not to be parsed.

nMaxData

Maximum amount of bytes to store into sData (optional). Specify STRING_COMPLETE to get all received data.

This value has no effect when sData is set to NULL. If this parameter is omitted only internal buffers are used.

nReceived Parameter that receives the actual amount of data received from the server (optional).
sVerify Binary pattern to verify (optional). If this parameter is omitted no verification is performed.
nVerifyStart Starting position of the pattern verification (optional). If this parameter is omitted the verification starts at the beginning.
nVerifyLength Length of the verification pattern (optional). If this parameter is omitted no verification is performed.
nMultiply The parsed packet-length (specified by the nProtoStart, nProtoLength and bLittleEndian parameters) is multiplied by nMultiply and finally nSum is added (optional). If this parameter is omitted no multiplication is performed.
nAdd The parsed packet-length (specified by the nProtoStart, nProtoLength and bLittleEndian parameters) is multiplied by nMultiply and finally nAdd is added (optional). If this parameter is omitted no addition is performed.

Example

dcltrans
  transaction TWeb
  var
    hWeb      : number;
    sHdr      : string(2000);
    sSize     : string(20);
    nReceived : number;
  begin
    WebTcpipConnect(hWeb, "lab3", 80);

    WebTcpipSend(hWeb, "Start\r\n");

    WebTcpipRecvProtoEx(hWeb, 0, 2, TCP_FLAG_INCLUDE_PROTO | TCP_FLAG_LITTLE_ENDIAN, sHdr, STRING_COMPLETE, nReceived,
                        "WIDECHARS", 2, 9, 2, 18);
    
    StrSearchDelimited(sSize, STRING_COMPLETE, sHdr,
                       "Age: ", 1, "\r\n",
                       1, STR_SEARCH_FIRST);

    WebTcpipShutdown(hWeb, WEB_SHUTDOWN_RESET);
  end TWeb;