LR_protocol script_windows sockets

来源:互联网 发布:it男装 编辑:程序博客网 时间:2024/05/21 17:35
本文介绍Loadrunner测试TCP/IP报文的样例,其中报文内容为16进制。
LR protocol: windows sockets 
LR script:
==vuser_init初始化部分,根据业务需求决定create socket函数放在这里或者放在action中===================
#include "lrs.h"
#include "lrun.h"
vuser_init()
{
    lrs_startup(257); 
 //create socket
 lr_start_transaction("01CreateSocket");
 lrs_create_socket("socket0","TCP","LocalHost=0","RemoteHost={ip}:{port}",LrsLastArg);
 lr_end_transaction("01CreateSocket", LR_AUTO);

    return 0;
}

==Action该部分主要是报文发送与接收,注意:需要包括默认外的预处理器lrun.h===================
#include "lrs.h"
#include "lrun.h"
// #include "stdlib.h"
Action()
{
//  //create socket
//  lr_start_transaction("01CreateSocket");
//  lrs_create_socket("socket0","TCP","LocalHost=0","RemoteHost={ip}:{port}",LrsLastArg);
//  lr_end_transaction("01CreateSocket", LR_AUTO);

//start:message
 lr_start_transaction("01message");
    //send message
 lr_start_transaction("0101SendMessage");
    lrs_send("socket0","buf0",LrsLastArg);
 lr_end_transaction("0101SendMessage", LR_AUTO);

    //receive message
 lr_start_transaction("0102ReceiveMessage");
    lrs_receive("socket0","buf1",LrsLastArg);
 lr_end_transaction("0102ReceiveMessage", LR_AUTO);
//end:message
    lr_end_transaction("01message", LR_AUTO);
 
//     //close socket
//  lr_start_transaction("91CloseSocket");
//  lrs_close_socket("socket0");
//  lr_end_transaction("91CloseSocket", LR_AUTO);
 
    return 0;
}

==vuser_end结束部分,注意:在lrs_cleanup()前close socket=================== 
 
 #include "lrs.h"
#include "lrun.h"
vuser_end()
{
   
     //close socket
 lr_start_transaction("91CloseSocket");
 lrs_close_socket("socket0");
 lr_end_transaction("91CloseSocket", LR_AUTO);
 lrs_cleanup();
    return 0;
}

==data.ws发送与接收报文的buffer及data=================== 
;WSRData 2 1
 send buf0 200
 "<TCPmessage>"
 recv buf1 200
 
-1
==说明===================
其中,传输的数据为十六进制报文,
1. 参数化时<TCPmessage>格式如下:\\x23\\x23\\x01\\xFE\\x4c\\x4a
2. 若不做参数化,直接将数据放在data.ws中时,格式如下:\x23\x23\x01\xFE\x4c\x4a
3. 报文的内容放在“”中