Example: lrs_length_receive

Example 1

In the following example, data (buffer1) is sent on a socket (socket0). Then the same data is received on the same socket with lrs_length_receive using the OffsetSize location_option. buffer1 consists of a length value of 2 bytes (in bold) and data. After obtaining the length value of 51, lrs_length_receive goes on to read 51 bytes of data from socket0 into buffer2. Note that there is no need to pass the locator parameter"Offset=0" as this is the default setting.

buffer1
51aaabbcc dddeeeeeeeeeeeeeeffffffffffffgggggghhhhhhhi"
lrs_create_socket("socket0", "TCP", "RemoteHost=bona.abc.com:7", LrsLastArg);
lrs_send("socket0", "buffer1", LrsLastArg);
lrs_length_receive("socket0", "buffer2", OffsetSize, "Size=2", LrsLastArg);

Example 2

In this example, data (buffer3) is sent on a socket (socket0). The same data is received on the socket with lrs_length_receive. The LeftRightBoundaries location_option is used with the left boundary being the string "LLLL" and the right boundary "RRRR". The lrs_length_receive first locates the second instance of the left boundary string (in bold) because the Ordinal locator is set to 2. The function is then told to jump a further 27 bytes (Offset=27) to finally locate the length value. This value is 9 (in bold) and is bounded by the right boundary of "RRRR". The 9 bytes after the right boundary are the characters "Requested" which lrs_length_receive reads from socket0 and writes to buffer4.
The subsequent call to lrs_receive reads the rest of the data into another buffer.

buffer3
"12LLLL34LLLLOOOOOfffffsssssseeeeeTTTTTT9RRRRRequestedZZZZZZZZZZZZZZZZZZZZ2LLLLAAAAAAAAAAAAAAAAAAAAAAEnd Buf"
lrs_create_socket("socket0", "TCP", "RemoteHost=bona.abc.com:7", LrsLastArg);
lrs_send("socket0", "buffer3", LrsLastArg);
lrs_length_receive("socket0", "buffer4", 2, "LB=LLLL", "RB=RRRR", "Offset=27", "Ordinal=1", LrsLastArg);
// Now receive the rest of received data
lrs_receive("socket0", "buffer5", LrsLastArg);

Example 3

In this example, data (buffer6) is sent on a socket (socket0). The same data is received on the socket with lrs_length_receive using the LeftBoundarySize location_option, the left boundary being the binary values \\x00\\x00\\x00\\x07. lrs_length_receive first locates these values (in bold) and then is told to jump a further 7 bytes (Offset=7) to finally locate the length value which takes up 2 bytes (Size=2). This value is 16 (also in bold). However, because the additional_param SubtractSize is set to zero, the size of the length field itself, 2, is subtracted from the total, making 14. The 14 byte string following the length field, "Requested Data", is read from socket0 and written to buffer7.
The subsequent call to lrs_receive reads the rest of the data into another buffer.

buffer6
"12LLLL34\\x00\\x00\\x00\\x07eTTTTTT16Requested Data ZZZZZZZZZZZZZZZZZZZZ2LLLLAAAAAAAAAAAAAAAAAEnd Buf"
lrs_create_socket("socket0", "TCP", "RemoteHost=bona.abc.com:7",
lrs_send("socket0", "buffer6", LrsLastArg);
lrs_length_receive("socket0", "buffer7", 3, "LB/BIN=\\x00\\x00\\x00\\x07", "size=2", "Offset=7", "SubtractSize=0", LrsLastArg);
// Now receive the rest of received data
lrs_receive("socket0", "buffer8", LrsLastArg);