这3个函数其实都可以动态获取运行中收到的数据包中的数据,只要跟在要获取的收取数据包脚本后面即可。其中lrs_save_searched_string和lrs_save_param如果buf_desc指明buf名称,则从我们录制的data.ws中获取数据,所以每次这个值都是固定值,不会改变的;比如订单提交的确认信息等;而如果lrs_save_searched_string和lrs_save_param参数buf_desc设置为NULL,则从脚本中每次返回的数据包中获取数据,这个数据也随着每次脚本的动态运行而变化,比如某个不断递增的ID号等。而lrs_save_param_ex 的buf_desc有3个参数,其中static指的是从我们在脚本中定义的一个静态变量中取值,而received指的是从收到的数据包取值;而user指从data.ws文件中取值。这个一定要搞清楚。关于这个函数,这里再次提供下最原始的说明

type  

The type of buffer data to save into the parameter. Possible values: 

user        - save the user data,
static - save the static buffer that was originally recorded,
received - save the buffer(s) received by the last call to lrs_receive. buff Depends on the type of buffer data specified in the type parameter.
For user the pointer to the user buffer,
For static - the descriptor of the buffer in the data file,
For received the buff parameter is ignored.
user:实例
char *ParamBuf = "(size=\x05)" 
lrs_save_param_ex("socket0", "user", ParamBuf, 0, strlen(ParamBuf),"ascii", "size_param"); 
static实例
lrs_save_param_ex("socket0", "user", "buf1", 0, 23,"ascii", "param"); 
received实例
lrs_save_param_ex("socket0", NULL, "buf1", 0, 23,"ascii", "param"); 

---------------------------------------------------------------------------------------------------
    
        //实例1
        lrs_save_searched_string("socke0","buf1","wtbh","LB/BIN=|","RB/BIN=|",2,0,-1);

//输出结果 "wtbh = 10000013" 。原始数据为"0|普通指令下达成功|10000031|"。那就是在以左边界和右边界第2次出现的地方,
        //获取左右边界里面的所有的值

//实例2
        lrs_save_searched_string("socke0","buf1","wtbh","LB/BIN=|","RB/BIN=|",1,0,-1);

//输出结果"wtbh = 普通指令下达成功"原始数据为"0|普通指令下达成功|10000031|"。那就是在以左边界和右边界第1次出现的地方,
        //获取左右边界里面的所有的值

//实例3
        lrs_save_searched_string("socke0","buf1","wtbh","LB/BIN=|","RB/BIN=|",1,4,-1);

//输出结果"wtbh = 指令下达成功"原始数据为"0|普通指令下达成功|10000031|"。那就是在以左边界和右边界第1次出现的地方,
        //获取左边界为起点的第4个字符后面的数据。

//实例4
        lrs_save_param("socket0","buf1","wtbh", 34, 8);
        
        //从数据包中第34个字符开始连续取8个字符。
        
        //实例5
            
        char * ReceivedBuffer;
        
        int iLen = 0;
        
        int iFor = 2;
        
        lrs_get_last_received_buffer("socket0", &ReceivedBuffer, &iLen); 
        
        lrs_save_param_ex("socket0", "user", ReceivedBuffer, 0, 43, "ascii", "test_para");
        
        lrs_free_buffer(ReceivedBuffer);

strZhwth = lr_eval_string("<test_para>");
        
        strZhwth = (char *)strtok(strZhwth,"|");
        
        while(iFor > 0)
        {
            iFor = iFor - 1;
            strZhwth = (char *)strtok(NULL,"|");//获取下一个token
        }
        //通过上面的循环获取了第2个“|”后面的字符,并且保存到strZhwth中
        lrs_save_param_ex("socket0", "user", strZhwth, 0, 8, "ascii", "Zhwth"); 
        //在上面获取字符中从第1位开始连续获取8个字符。
        //函数实例6
        函数strtok
        说明Returns a token from a string delimited by specified characters. 
        定义char *strtok ( char *string, const char *delimiters ); 
        参数string The string to scan.  delimiters The string consisting of the character or characters that delimit tokens in the first string. 
        实例
       extern char * strtok(char * string, const char * delimiters ); // Explicit declaration 
       char path[] = "c:\\mercury\\lrun\\bin\\wlrun.exe"; 
       char separators[] = ".\\"; 
       char * token; 
       token = (char *)strtok(path, separators); // Get the first token 
       if (!token) { 
              lr_output_message ("No tokens found in string!"); 
              return( -1 ); 
       } 
       while (token != NULL ) { // While valid tokens are returned 
              lr_output_message ("%s", token ); 
              token = (char *)strtok(NULL, separators); // Get the next token 
       } 
        Output:
        Action.c(18): c:
        Action.c(18): mercury
        Action.c(18): lrun
        Action.c(18): bin
        Action.c(18): wlrun
        Action.c(18): exe 
        //函数实例7
        函数strstr
        说明Returns the first occurrence of one string in another. 
        定义char *strstr ( const char *string1, const char *string2 ); 
        参数string1The string that is searched.  string2The string that is searched for in the first string.  
        实例1
        lrs_save_param_ex("socket0", "user", ReceivedBuffer_cjhb, 0, iLenCj, "ascii", "cjhb");
        lrs_free_buffer(ReceivedBuffer_cjhb); 
        if(strstr(lr_eval_string("<cjhb>"), "已成交") != NULL)
        return 0;
        实例2
        After strstr returns the address, position, the code then calculates the word's place in str by subtracting the address of the start of the string from position. This is the offset of the word "dog", in bytes.

int offset; 
       char * position; 
       char * str = "The quick brown dog jumps over the lazy fox"; 
       char * search_str = "dog"; 
       position = (char *)strstr(str, search_str);

// strstr has returned the address. Now calculate * the offset from the beginning of str 
       offset = (int)(position - str + 1); 
       lr_output_message ("The string \"%s\" was found at position %d", search_str, offset); 
        Output:
        Action.c(14): The string "dog" was found at position 17

//函数实例8
        函数strcmp
        说明Compares string1 and string2 to determine the alphabetic order.
        定义int  ( const char *string1, const char *string2 );
        参数string1  The first string that is compared.  string2  The second string that is compared.strcmp compares string1 and string2 to determine the alphabetic order.   
        实例1
        The following example compares two strings, string1 and string2, which are identical except for the word "quick" which is lowercase in string1 and uppercase in string2. strcmp, which is case-sensitive, returns an unequal comparison. 
       int result; 
       char tmp[20]; 
       char string1[] = "The quick brown dog jumps over the lazy fox"; 
       char string2[] = "The QUICK brown dog jumps over the lazy fox"; 
       result = strcmp( string1, string2); // Case-sensitive comparison 
       if(result > 0) 
              strcpy(tmp, "greater than"); 
       else if(result < 0) 
              strcpy(tmp, "less than"); 
       else 
              strcpy(tmp, "equal to"); 
       lr_output_message ("strcmp: String 1 is %s string 2", tmp); 
       result = stricmp(string1, string2 ); // Case-insensitive comparison 
       if( result > 0 ) 
              strcpy( tmp, "greater than" ); 
       else if( result < 0 ) 
              strcpy( tmp, "less than" ); 
       else 
              strcpy( tmp, "equal to" ); 
       lr_output_message( "stricmp: String 1 is %s string 2", tmp ); 
        Output:
        Action.c(17): strcmp: String 1 is greater than string 2
        Action.c(28): stricmp: String 1 is equal to string 2

单词descriptor identifying 标识符描述

Loadrunner中socket协议中的三个关联函数的更多相关文章

  1. Loadrunner 中socket协议RecvBuffer接收到数据长度为空

    socket通讯,有两种方式,一种是建立长连接(TCP),建立后,不停的发送,接收.另外一种是建立短连接(UDP),建立连接,发送报文,接收响应,关闭连接.两种方式 server的开销不同. 今天出现 ...

  2. 自行控制loadrunner的socket协议性能测试 (转)

    一前言 二任务的提出 三实现方案讨论 四技术要点讲解 如何开始录制一个最简单的收发数据包脚本 写日志文件 一行一行读数据包文件 字符串转换为十六进制数据包 发送自己定义的数据包 接收数据包到自定义缓冲 ...

  3. LoadRunner编写Socket协议脚本方法

    本文主要介绍使用LoadRunner手工编写Windows Socket协议测试脚本的方法. 通过LoadRunner编写Windows Socket协议测试脚本,总体说来,比较简单.就像把大象放进冰 ...

  4. python中TCP协议中的粘包问题

    TCP协议中的粘包问题 1.粘包现象 基于TCP实现一个简易远程cmd功能 #服务端 import socket import subprocess sever = socket.socket() s ...

  5. Swift中声明协议中的class关键字的作用

    大熊猫猪·侯佩原创或翻译作品.欢迎转载,转载请注明出处. 如果觉得写的不好请多提意见,如果觉得不错请多多支持点赞.谢谢! hopy ;) 最近在Cocos2D编程for Swift中看到以下一个代码片 ...

  6. loadrunner使用socket协议来实现客户端对服务器产生压力实例。(通过发送心跳包,达到连接多个客户端的目的)

    #include "lrs.h" vuser_init(){ char *ip; int handler; //编写获取LR分配的Vuser IP函数,将IP保存在ip变量中. i ...

  7. 修改Linux中ssh协议中的默认端口号22

    说明:最近的一台服务器老是提示异常登录.主要原因是你的账户和密码可能太简单了,别人用默认的端口22进行登录. 打开SSH端口所在文件 vim /etc/ssh/sshd_config 进入编辑模式,将 ...

  8. loadrunner socket协议问题归纳(3)

    摘要:通过实例讲解loadrunner中的socket协议性能测试的一种测试方法,如何不依赖loadrunner既定规则,自行控制收发数据包 关键词:Loadrunner,socket,自行控制,收发 ...

  9. Loadrunner的Socket脚本关联小技巧

    Socket脚本关联小技巧 我们在socket脚本调试的时候经常会遇到很多问题,比如:socket包中繁杂的二进制编码,socket数据如何进行截取,如何对socket数据包进行参数化等等,以下几点内 ...

随机推荐

  1. Qt creator 编译错误:无法解析的外部符号(命令)

    问题来自于:仅仅是在creator 中加入了一个新的DIalog类,并在main(),中实例化并show.就出现例如以下的错误: main.obj:-1: error: LNK2019: 无法解析的外 ...

  2. Oracle行转列SQL

      -- Create table /*create table TEST_TABLE ( STUDENT VARCHAR2(200), SUBJECT VARCHAR2(200), GRADE NU ...

  3. 全库搜索某个内容的sql

    DECLARE @what varchar(800) SET @what='联系' --要搜索的字符串 DECLARE @sql varchar(8000) DECLARE TableCursor C ...

  4. 【NOI】9272 偶数个三

    题目 链接:bajdcc/ACM 描述 在所有的N位数中,有多少个数中有偶数个数字3?结果模12345.(1<=N<=10000) 样例输入 2 样例输出 73 方法一:穷举 评价:最简单 ...

  5. 也谈免拆机破解中兴B860av1.1(解决不能安装软件/解决遥控)

    20170221更新   部分用户(自己恢复出厂测试过),操作后仍然无法直接在当贝市场安装应用了,    在第8条,最后两步,先改为中国通用市场,后面再改为未知局方.    如果开机想优先启动当贝桌面 ...

  6. Celery+python+redis异步执行定时任务

    我之前的一篇文章中写了[Celery+django+redis异步执行任务] 博文:http://blog.csdn.net/apple9005/article/details/54236212 你会 ...

  7. thymeleaf 的hello world

    在研究一个模板引擎,选了这个thymeleaf .中间遇到很多的问题.现在在这里记录一下. 第一步:导入jar包.这里使用maven导入jar包 <!-- thymeleaf 核心包 begin ...

  8. nand ECC 算法记录

    nandflash ECC 原理记录. nand ECC 全称是Error Checking and correction. 该算法分为列校验和行校验. 列校验有下图所示: * 如上图所示, CP0 ...

  9. u-boot中网口处理--软件部分

    u-boot中DM9000驱动分析 1. CSRs和PHY reg读写. static u16 phy_read(int reg) { u16 val; /* Fill the phyxcer reg ...

  10. 爱快AP-H1使用方法及排错

    ikuai云平台:https://yun.ikuai8.com/login 底下原文地址:http://bbs.ikuai8.com/thread-25939-1-1.html 前文:使用爱快AP-H ...