I am trying to build a script for testing a python based desktop application which sends files to the server.
I have created the script after recording the actual application.
How can I send the contents of different file to the server (instead of sending the same data while recording) each iteration.
The code for init is
/*********************************************************************
* Created by Windows Sockets Recorder
*
* Created on: Thu Jan 29 02:22:11
*********************************************************************/
#include "lrs.h"
#define SEEK_SET 0 /* beginning of file. */
#define SEEK_CUR 1 /* current position. */
#define SEEK_END 3726
vuser_init()
{
char *recvbuf;
int recvlen=0;
int rc;
lrs_startup(257);
lr_start_transaction("VV_01_AMT_000_Conn_socket");
rc=lrs_create_socket("socket0", "TCP", "RemoteHost=am-us-tos-vvsit.hughestelematics.net:15557", LrsLastArg);
if (rc != 0 )
{
lr_output_message("%s","Unable to connect to host");
lr_end_transaction("VV_01_AMT_000_Conn_socket", LR_FAIL);
return 0;
}
lrs_send("socket0", "buf0", LrsLastArg);
lrs_receive("socket0", "buf1", LrsLastArg);
lrs_get_last_received_buffer("socket0",&recvbuf,&recvlen);
if(recvlen==53)
{
lr_output_message("%s","Unable to connect to host");
lr_end_transaction("VV_01_AMT_000_Conn_socket", LR_FAIL);
return 0;
}
lr_end_transaction("VV_01_AMT_000_Conn_socket", LR_AUTO);
return 0;
}
for Action is
/*********************************************************************
* Created by Windows Sockets Recorder
*
* Created on: Thu Jan 29 02:22:11
*********************************************************************/
#include "lrs.h"
Action()
{
char *recvbuf;
int recvlen=0;
int rc=0;
char filename[100];
char *file_contents;
int input_file_size;
long packetFile;
// strcpy(filename,lr_eval_string("{P_FileName}"));
// packetFile= fopen(filename,"rb+");
// if( packetFile == NULL )
// {
// lr_output_message("Error while opening the file.\n");
// }
// file_contents = (char*)malloc(3726 * (sizeof(char)));
// fread(file_contents, sizeof(char), 3726, packetFile);
// fclose(packetFile);
// lr_output_message("%s",file_contents);
lr_start_transaction("VV_01_AMT_010_SendPacket");
// lrs_set_send_buffer("socket0",file_contents,3726);
// rc=lrs_length_send("socket0", "buf2",0,"Encoding=0",LrsLastArg);
rc=lrs_send("socket0", "buf2", LrsLastArg);
if(rc==WSAECONNRESET || rc==WSAECONNABORTED)
{
lr_stop_transaction("VV_01_AMT_010_SendPacket");
lr_output_message("Connection Lost midway trying to reconnect Error=%d",rc);
ConnectHost();
lr_resume_transaction("VV_01_AMT_010_SendPacket");
// lrs_set_send_buffer("socket0",file_contents,3726);
rc=lrs_send("socket0", "buf2", LrsLastArg);
}
rc=lrs_receive("socket0", "buf3", LrsLastArg);
lrs_get_last_received_buffer("socket0",&recvbuf,&recvlen);
if(recvlen>=15)
{
lr_output_message("Received Buffer = %s",recvbuf);
lr_end_transaction("VV_01_AMT_010_SendPacket", LR_PASS);
}
else
{
lr_error_message("Unable to send packet Error =%d",rc);
lr_end_transaction("VV_01_AMT_010_SendPacket", LR_FAIL);
}
// lr_think_time(300);
return 0;
}
the above line in orange sends the recorded data(i.e. a file data).
How can we send custom data from specified file??