loadrunner winsocket 通信 把接收到的数据包保存到本地
#include "lrs.h"
Action()
{
unsigned int recvlen;
char * recvcontext;
char * filename = "c:\\tmp\\lrrecvlog.txt";
long file_stream;
lr_start_transaction("同城跨行");
lrs_create_socket("socket0", "TCP", "RemoteHost=10.194.129.213:7990", LrsLastArg);
lrs_send("socket0", "buf0", LrsLastArg);
lrs_receive("socket0", "buf1", LrsLastArg);
recvlen = lrs_get_last_received_buffer_size("socket0");
if (recvlen < 1)
{
lr_error_message("没有任何数据收到");
return -1 ;
}
recvcontext = lrs_get_received_buffer("socket0", 0, recvlen , NULL);
if ((file_stream = fopen(filename, "a+")) == NULL ) {
lr_error_message("Cannot open %s", filename);
return -1;
}
fprintf(file_stream, "%s\n", recvcontext);
fclose(file_stream);
lrs_close_socket("socket0");
lr_end_transaction("同城跨行", LR_AUTO);
return 0;
}