/*** Actions.c ***/
#include "lrs.h"
#define host "localhost"
#define port 23
#define socktype "TCP"
void Printf( char * str )
{
lr_message ( str );
}
int recv( char *sock, char *buffer, int bytes, int flags )
{
int size;
int byte;
int result;
char *data = (char *)malloc(1);
char input[12767]; // make as big or small as you want
sprintf(input,"");
for (byte = 0; byte < bytes; byte++)
{
lrs_set_recv_timeout(1,0);
result = lrs_receive_ex(sock, "WS_BufferIN", "NumberOfBytesToRecv=1", LrsLastArg);
lrs_get_last_received_buffer(sock, &data, &size);
if (size != 0)
sprintf(input,"%s%c",input,data[0]);
}
strncpy(buffer,input,strlen(input));
return strlen(input);
}
int send( char *sock, char *buffer, int bytes, int flags )
{
int size;
int byte;
int result;
char *data = (char *)malloc(1);
char input[12767];
sprintf(input,"");
lrs_set_send_buffer(sock,buffer,strlen(buffer));
//sprintf(WS_BufferOUT,"%s",buffer);
result = lrs_send(sock,"WS_BufferOUT",LrsLastArg);
return strlen(buffer);
}
Actions()
{
char WS_Sock[] = "socket0";
char *WS_SockType = (char *)malloc(3);
char *WS_RemoteHost = (char *)malloc(1024);
char *WS_Data = (char *)malloc(2024);
int WS_Result;
int size;
char *data = (char *)malloc(1024);
char temp[2024];
char buffer[1024];
sprintf(buffer,"RemoteHost=%s:%d",host,port);
strncpy(WS_SockType,socktype,3);
strncpy(WS_RemoteHost,buffer,strlen(buffer));
// Create & Connect to host specified in WS_RemoteHost
// the TCP/IP connection will be of WS_SockType
lrs_create_socket(WS_Sock, WS_SockType, WS_RemoteHost, LrsLastArg);
// read in 10 bytes from the remote host
recv(WS_Sock,data,10,0);
sprintf(temp,"%s",data);
Printf(temp);
sprintf(temp,"This is outgoing data...");
// send a string to the remote host
send(WS_Sock,temp,strlen(temp),0);
// close the connection
lrs_close_socket(WS_Sock);
return 0;
}