pcl2004_27 发表于 2006-10-30 14:10:53

LoadRunner:Getting values from Winsock Buffers

Description

      How to grab values identified by the \ null character while using Winsock.


Solution

      While using the Web/Winsock or plain Winsock method it becomes an issue to capture the right values from the send/rcvd buffers. However, some ansi c functions come in to play and help one out accomplishing the task.
Lets say if you have a value which you are receiving in buf88 you have captured the offset and defined the string length accurately. Now, you want to get rid of the junk characters around it and put it in a variable.
Here is how we do it:

// In code below we are verifying if the buffer is coming back with customer id and we are resolving that through the code.

/* get Customer Id */

lrs_save_param("socket3",NULL, "Cust_id", 0, -1);

strcpy(sActualBuffer1, lr_eval_string("{Cust_id}"));

nl = 0;

nm = 0;

do

{

//I am searching for "t" since it is available in word customer
if (sActualBuffer1 == 't')

{

break;

}

nl++;

}

while(sActualBuffer1 != '\0');

nm = nl+25;

nl = 0;

while(sActualBuffer1 != '\\')

{

sCustid = sActualBuffer1;


}
How we get rid of the unwanted values characters is given below.

lrs_get_last_received_buffer("socket23", & Mybuffer, & Ourbytes);

lrs_save_param_ex("socket23", "user", Mybuffer, 32, 10, "ascii", "Istvalue");

secondval = lr_eval_string("{Istvalue}");

lr_output_message("Value is : %s", secondval);

// Null character \"
symbol = "\"";

Thirdval = strtok(secondval, symbol);

Thirdval='\0';

lr_save_string(Thirdval,"ConidNumb");

custid = lr_eval_string("{CstidNumb}");

lr_output_message("%s", custid);

I hope this would help someone who is working with sockets. It helped me though.
页: [1]
查看完整版本: LoadRunner:Getting values from Winsock Buffers