LoadRunner中winsocket协议学习

发表于:2013-04-18来源:Csdn作者:xuyubotest点击数: 标签:loadrunner
#include "lrs.h" Action() { int i; char *ActualBuffer;//定义字符指针 int NumberOfBytes;//定义int型变量保存长度

  #include "lrs.h"

  Action()

  {

  int i;

  char *ActualBuffer;//定义字符指针

  int NumberOfBytes;//定义int型变量保存长度

  //这是第一步initializes a socket

  lrs_create_socket("socket1", "UDP", "LocalHost=2425", LrsLastArg);

  //我这里是让脚本连续运行多次

  for(i=0;i<8;i++)

  {

  lr_start_transaction("send");

  lr_think_time(7);

  //这里是第二步,通过建立的socket1将buf1中的数据发送给远端MM-7QL3Z0JYUJN6用户,端口2425

  lrs_send("socket1", "buf1", "TargetSocket=MM-7QL3Z0JYUJN6:2425", LrsLastArg);

  //取得缓冲区数据

  lrs_get_buffer_by_name("buf1", &ActualBuffer, &NumberOfBytes);

  //输出缓冲区数据大小

  lr_output_message("The buffer's size is: %d/n", NumberOfBytes);

  //从buf2中接收返回的数据

  lrs_receive("socket1", "buf2", LrsLastArg);

  //取得缓冲区数据

  lrs_get_buffer_by_name("buf2", &ActualBuffer, &NumberOfBytes);

  //输出缓冲区数据大小

  lr_output_message("The buffer's size is: %d/n", NumberOfBytes);

  lr_end_transaction("send", LR_AUTO);

  }

  //第三步关闭释放socket连接

  lrs_close_socket("socket1");

  return 0;

  }

  下面我们来看buf中发送的数据,数据都会保存在data.ws文件中:

  发送的明文内容:xuyubo,但是可以看出,这里显示的都是密文,应该是按格式转换了编码。

  ;WSRData 2 1

  send buf1 371

  "1_lbt4_0#128#0016D3B50AA3#0#0#0:1246963533:Administrator:LND7DEMO:4194592:"

  "20002:21b56c1d54100180afb94c84050a7f371f1010472b26092920ea2629699a74b2cbfe"

  "242eb74b16e66e6fe90c4610ccb110ce400851e68e16c51470a91120dfcdf324444e647444"

  "864e823810539413ed0b6b29a8ed46d2f95839047dbe4555b141afb80f5cf9c06e8af0aa90"

  "afe852dbfedab05ee91932a95f6faef8207907fb:5f4c457c52738bfdfaf28c9303d292c6"

  "/x00/x00"

  recv buf2 87

  "1_lbt4_0#131#001109AB80C9#0#0#0:1246475216:Administrator:MM-7QL3Z0JYUJN6:3"

  "3:1246963533"

  "/x00"

  -1

原文转自:http://blog.csdn.net/xuyubotest/article/details/4677651