Example: lrs_set_receive_option

Example 1

In this example, the lrs_set_receive_option function indicates to the receiving socket that if a content mismatch occurs, it sends a mismatch message.

Suppose that the recorded buffer contains a character "!" and in replay the buffer contains "@"

lrs_set_receive_option(Mismatch, MISMATCH_CONTENT);
lrs_send("socket1", "buf2", 1, 0);
lrs_receive("socket1", "buf2", LrsLastArg);
lrs_close_socket("socket1");

If the option value was MISMATCH_SIZE, then this function would not report an error, since the size is the same.

Example 2

In the following example, the lrs_set_receive_option function indicates to the receiving socket that it should receive the same number of bytes as recorded.

lrs_create_socket("socket1", "TCP", "RemoteHost=199.203.77.246:21", LrsLastArg);
lrs_set_receive_option(EndMarker, RecordingSize);
lrs_receive("socket1", "buf2", LrsLastArg);

Suppose that the buffer during recording (buf2) was 20 bytes long, and the buffer sent by the server during replay was 30 bytes long. This example script would make the received buffer 20 bytes long. The remaining buffer data (10 bytes) will be received in the next lrs_receive call.

If the option value was EndMarker_None, then the lrs_receive call would receive the entire buffer, with a mismatch message.

Example 3

In the following example, the lrs_set_receive_option function uses a binary string terminator.

lrs_create_socket("socket1", "TCP", "RemoteHost=199.203.77.246:21", LrsLastArg);
lrs_set_receive_option(EndMarker, BinaryStringTerminator, "\\x00\\x07ABC");
lrs_receive("socket1", "buf2", LrsLastArg);

Suppose that the buffer that the server sent contains the following:

    "\x00\x01\x85\x80\x00\x01\x00\x01\x00\x00\x00\x00\x07"

    "ABC"

    "\x02"

    "co"

    "\x02"

    "il"

    "\x00\x00\x01\x00\x01\xc0"

The received buffer, buf2, will be:

    "\x00\x01\x85\x80\x00\x01\x00\x01\x00\x00\x00\x00\x07"

    "ABC"