LSP is the lrs_save_param () function.
Lsss is the lrs_save_searched_string () function.
Let's use an example to illustrate their usage.
The C/S mechanism is different from that of B/S. In particular, there is a data. ws
The data in it is some data packets sent to the server and the data packets returned by the server.
The following is the data. ws content after my recording
; Wsrdata 2 1
Send buf0 55
"4 ## select agent_name from agents order by agent_name ###"
Recv buf1 55
"0 # Alex # Amanda # Debian # Julia # Mary # Robert # Sharon # Suzan ###"
"\ X00"
Send buf2 68
"2 ## 1 ## select distinct departure from flights order by departure ###"
Recv buf3 56
"0 # Denver # Los Angeles # portland # San Francisco # Seattle ###"
"\ X00"
Send buf4 298
"2 #0 # select departure, flight_number, departure_initials, day_of_week, Ar"
"Rival_initials, arrival, departure_time, arrival_time, airlines, seats_ava"
"Ilable, ticket_price, mileage from flights where arrival = 'portland 'a"
"Nd departure = 'Denver 'and day_of_week = 'Friday' order by flight_number #"
"##"
Recv buf5 128
"0 #5787; 250; 5587; PM; den; Friday; por; PM; NW; 164; Denver #6242; 250; 6"
"042; am; den; Friday; por; am; AA; 177; Denver ###"
"\ X00"
Send buf6 82
"11 # update counters set counter_value = counter_value + 1 where table_name = 'or"
"Ders '###"
Recv buf7 8
"0 #1 ###"
"\ X00"
Send buf8 67
"12 # select counter_value from counters where table_name = 'Orders '###"
Recv buf9 10
"0 #101 ###"
"\ X00"
Send buf10 72
"12 # select customer_no from customers where customer_name = '<customer> '###"
Recv buf11 9
"0 ##-1 ###"
"\ X00"
Send buf12 85
"11 # update counters set counter_value = counter_value + 1 where table_name = 'cu"
"Stomers '###"
Recv buf13 8
"0 #1 ###"
"\ X00"
Send buf14 70
"12 # select counter_value from counters where table_name = 'customer '###"
Recv buf15 9
"0 ## 31 ###"
"\ X00"
Send buf16 81
"11 # insert into MERs (customer_name, customer_no) values ('<customer> ',"
"<Userid> )###"
Recv buf17 8
"0 #1 ###"
"\ X00"
Send buf18 58
"12 # select agent_no from agents where agent_name = '<agent> '###"
Recv buf19 8
"0 ## 4 ###"
"\ X00"
Send buf20 195
"11 # insert into orders (order_number, agent_no, customer_no, flight_number, de"
"Parture_date, tickets_ordered, class, send_signature_with_order) values (<orderno> ,"
"<Agentid>, <userid>, 6242, {d '2017-11-11 '}, 1, '3', 'n ')###"
Recv buf21 8
"0 #1 ###"
"\ X00"
Send buf22 13
"11 ## commit ###"
Recv buf23 8
"0 #0 ###"
"\ X00"
-1
The following is the script in our action.
# Include "lrs. H"
Action ()
{
Int random;
Lrs_create_socket ("socket0", "TCP", "remotehost = 172.16.2.9: 3456", lrslastarg );
Lrs_send ("socket0", "buf0", lrslastarg); // return the agent name
Lrs_receive ("socket0", "buf1", lrslastarg );
Srand (Time (null ));
Random = rand () % 8 + 2;
Lrs_save_searched_string ("socket0", null, "Agent", "lB = #", "RB = #", random, 0,-1 );
Lr_think_time (12 );
Lrs_send ("socket0", "buf2", lrslastarg); // return the starting position and destination of the flight.
Lrs_receive ("socket0", "buf3", lrslastarg );
Lr_think_time (13 );
Lrs_send ("socket0", "buf4", lrslastarg); // query Flight Information
Lrs_receive ("socket0", "buf5", lrslastarg );
Lr_think_time (18 );
Lrs_send ("socket0", "buf6", lrslastarg); // generate the order number
Lrs_receive ("socket0", "buf7", lrslastarg );
Lrs_send ("socket0", "buf8", lrslastarg); // return the order number
Lrs_receive ("socket0", "buf9", lrslastarg );
Lrs_save_param ("socket0", null, "orderno", 3, 3); // use Association to return the order number
Lrs_send ("socket0", "buf10", lrslastarg); // you can check whether the user is a new user. If the user is a new user,-1 is returned. Otherwise, the customer ID is returned.
Lrs_receive ("socket0", "buf11", lrslastarg );
Lrs_save_param ("socket0", null, "userid", 3, 2 );
If (strcmp (lr_eval_string ("<userid>"), "-1") = 0)
{
Lrs_send ("socket0", "buf12", lrslastarg); // generate the customer ID
Lrs_receive ("socket0", "buf13", lrslastarg );
Lrs_send ("socket0", "buf14", lrslastarg); // return the customer ID
Lrs_receive ("socket0", "buf15", lrslastarg );
Lrs_save_param ("socket0", null, "userid", 3, 2 );
Lrs_send ("socket0", "buf16", lrslastarg); // insert customer records
Lrs_receive ("socket0", "buf17", lrslastarg );
};
Lrs_send ("socket0", "buf18", lrslastarg); // return the agent ID
Lrs_receive ("socket0", "buf19", lrslastarg );
Lrs_save_param ("socket0", null, "agentid", 3, 1 );
Lrs_send ("socket0", "buf20", lrslastarg); // insert order records
Lrs_receive ("socket0", "buf21", lrslastarg );
Lrs_send ("socket0", "buf22", lrslastarg); // submit
Lrs_receive ("socket0", "buf23", lrslastarg );
Lr_think_time (7 );
Return 0;
}
Srand (Time (null ));
Random = rand () % 8 + 2;
Lrs_save_searched_string ("socket0", null, "Agent", "lB = #", "RB = #", random, 0,-1 );
We will analyze this code.
Srand (Time (null ));
Random = rand () % 9 + 2;
This random number is used
Lrs_save_searched_string ("socket0", null, "Agent", "lB = #", "RB = #", random, 0,-1 );
Function slave
Recv buf1 55
"0 # Alex # Amanda # Debian # Julia # Mary # Robert # Sharon # Suzan ###"
"\ X00"
Obtain an associated data randomly. Why is the data range 2-9? Let's take a closer look.
# Alex # Amanda # Debian # Julia # Mary # Robert # Sharon # Suzan ###
We can see that there are 11 pairs of D with the left and right boundary as #, but only from the second to the ninth is useful to us.
So let's take this value. We can also see from the above that the associations used in the winsocket protocol are different from those in the HTTP/html protocol, the difference is that the position of the related function in the HTTP protocol must be in front of the page opened, and in the winsocket is in the back.
Execute the following script
Srand (Time (null ));
Random = rand () % 8 + 2;
Lrs_save_searched_string ("socket0", null, "Agent", "lB = #", "RB = #", random, 0,-1 );
The agent will randomly obtain one of Alex, Amanda, Debian, Julia, Mary, Robert, Sharon, and Suzan.
Let me analyze it again
Lrs_save_param ("socket0", null, "orderno", 3, 3 );
This code is used to extract the required data from the data. ws package.
Recv buf9 10
"0 #101 ###"
"\ X00"
From the following examples
Lrs_save_param (char * s_desc, char * buf_desc, char * param_name, effecffset, intparam_len );
We can see that
Lrs_save_param ("socket0", null, "orderno", 3, 3 );
The value starts from the 101 bits of "0 # 3rd ###" and takes three bits. Therefore
Orderon = 101
Let's talk about one of these two functions that you don't know very well. Then we will end this chapter.
Lrs_save_searched_string ("socket0", null, "Agent", "lB = #", "RB = #", random, 0,-1 );
Lrs_save_param ("socket0", null, "orderno", 3, 3 );
All of them have a null value. The function of null is to take the value from the data in the server,
Lrs_send ("socket0", "buf8", lrslastarg); // return the order number
Lrs_receive ("socket0", "buf9", lrslastarg );
Lrs_save_param ("socket0", null, "orderno", 3, 3 );
If null is written and we want to set the value from buf9, the correlated function must be in
Lrs_receive ("socket0", "buf9", lrslastarg );
After
If
Lrs_receive ("socket0", "buf10", lrslastarg );
Lrs_save_param ("socket0", null, "orderno", 3, 3 );
It is the value in duf10.
There is also a case where
Lrs_receive ("socket0", "buf10", lrslastarg );
The value of duf9 must be written in this way.
Lrs_save_param ("socket0", "buf9", "orderno", 3, 3 );