The script is very simple, basically, like putting an elephant in a refrigerator, in total three steps:
The first step: Open the refrigerator door.
Establish a connection to the server
rc =LRS_create_socket ("Socket0", "TCP", "localhost=0", "remotehost=128.64.64.23:8988", Lrslastarg);
if (rc==0)
Lr_output_message ("Socket was successfully created");
Else
Lr_output_message ("An error occurred while creating the socket, error Code:%d", RC);
Step two: Load the elephant in.
Lrs_send ("Socket0", "buf0", Lrslastarg); Send data from "buf0" to "Socket0"
Lrs_receive ("Socket0", "Buf1", lrslastarg);//The data returned in "SOCKE0" is stored in "BUF1"
Step three: Take the refrigerator door with you.
Close connection
Lrs_close_socket ("Socket0");
Everyone must have seen it, the whole point is in the second step, to put such an elephant into the refrigerator is not an easy thing, we have to do some processing of the transmitted data. If you have a script recording of the WinSocket protocol, you will knowLRWill write the contents of the packet you sent to data.ws this file, then we should also write the data in the data.ws. Assuming I'm sending the string "00100312303456", I'm going to write it directly into the data.ws script as follows:
; Wsrdata 2 1
Send buf0 10
"00100312303456"//Note to add ""
Recv BUF1 128
-1
Run the script to see the execution succeed. InLogThe message can print out the sent buffer and the buffer content received.
Next, we are going to parameterize the sent string, so that each time the script sends a different string, how to do it?
There are two ways of doing this:
1, direct parameterization. In the data.ws can be directly parameterized, the specific operation I will not say more. Note that the default parameter name symbol is the angle bracket (<>), which differs from the curly braces ({}) of the HTTP protocol (the reason why LR has to set the default parameter name symbols for different protocols is not a toss-up). The script is as follows:
Send BUF0 106
"<string>"//string is a custom parameter name
This method is the simplest and easy to understand.
Using the Windows socket protocol in LoadRunner