Skip to content

Commit d7ff1e4

Browse files
author
ajonen
committed
initial add
0 parents  commit d7ff1e4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+1583
-0
lines changed

client/include/aTodo.h

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../server/include/aTodo.h

client/include/protoService.h

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../server/include/protoService.h

client/include/protocolBaseServer.h

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/opt/server/include/protocolBaseServer.h

client/include/todoExec.h

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../server/include/todoExec.h

client/include/todoFactory.h

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../server/include/todoFactory.h

client/makefile

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
###########
2+
#add new depend files below
3+
#add new ones here object files relating to .cpp filesF
4+
DEPS=client.o protocolBaseServer.o
5+
6+
EXE=driver
7+
8+
#######################
9+
#DO NOT EDIT BELOW
10+
#######################
11+
12+
###########
13+
#variables
14+
###########
15+
CC=g++
16+
CPPFLAGS= -Wall -c -I./include/ -I/usr/share/boost_1_58_0/
17+
CPPFLAGS+= -MD -MP -std=c++0x
18+
LFLAGS= -Wall -L/usr/share/boost_1_58_0/lib/ -lboost_serialization
19+
VPATH=src
20+
21+
all: $(EXE)
22+
23+
debug: CC+= -DDEBUG -g
24+
debug: $(EXE)
25+
###########
26+
#linker
27+
###########
28+
$(EXE): $(DEPS)
29+
$(CC) $(DEPS) $(LFLAGS) -o $(EXE).exe
30+
31+
##########
32+
#implicit calls for all object file builds
33+
#########
34+
35+
###########
36+
#include dependency files
37+
###########
38+
-include $(DEPS:%.o=%.d)
39+

client/old

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
std::string dataToSend = "Hello World! This is a string of any length ...";
2+
uint32_t dataLength = htonl(dataToSend.size()); // Ensure network byte order
3+
int ok=send(sockfd,&dataLength ,sizeof(uint32_t) ,MSG_CONFIRM); // Send the data length
4+
if(ok!=-1){
5+
uint32_t sent=0;
6+
while(dataLength >0){
7+
sent=send(sockfd,dataToSend.c_str(),dataLength,MSG_CONFIRM); // Send the string
8+
if(sent==0){
9+
std::cout << "socket Closed" << std::endl;
10+
break;
11+
}
12+
else if(sent<0){
13+
std::cout << "Error Sending" << std::endl;
14+
break;
15+
}
16+
dataToSend+=sent;
17+
dataLength-=sent;
18+
19+
}
20+
}
21+
else
22+
std::cout << "socket not connected" << std::endl;
23+
24+

client/src/.syntastic_cpp_config

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
-I./include
2+
-I/usr/share/boost_1_58_0/
3+

client/src/client.cpp

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
extern "C"{
2+
#include <sys/socket.h>
3+
#include <sys/types.h>
4+
#include <netinet/in.h>
5+
#include <netdb.h>
6+
#include <stdio.h>
7+
#include <string.h>
8+
#include <stdlib.h>
9+
#include <unistd.h>
10+
#include <errno.h>
11+
#include <arpa/inet.h>
12+
#include <ctype.h>
13+
#include <stdarg.h>
14+
#include <string.h>
15+
#include <stdint.h>
16+
#include <inttypes.h>
17+
}
18+
#include <string>
19+
#include <iostream>
20+
#include "protocolBaseServer.h"
21+
#include "todoFactory.h"
22+
BOOST_SERIALIZATION_ASSUME_ABSTRACT(atodo)
23+
BOOST_CLASS_EXPORT(todoExec)
24+
25+
26+
#include <memory>
27+
28+
int main(void)
29+
{
30+
int sockfd = 0,n = 0;
31+
struct sockaddr_in serv_addr;
32+
33+
// data
34+
if((sockfd = socket(AF_INET, SOCK_STREAM, 0))< 0)
35+
{
36+
printf("\n Error : Could not create socket \n");
37+
return 1;
38+
}
39+
40+
serv_addr.sin_family = AF_INET;
41+
serv_addr.sin_port = htons(3000);
42+
serv_addr.sin_addr.s_addr = inet_addr("127.0.0.1");
43+
44+
if(connect(sockfd, (struct sockaddr *)&serv_addr, sizeof(serv_addr))<0)
45+
{
46+
printf("\n Error : Connect Failed \n");
47+
return 1;
48+
}
49+
50+
//0x01 is and execute object
51+
char mtype=0x01;
52+
std::string dataToSend = "ls -al /home/ajonen";
53+
54+
auto tmpTodoFactory=todoFactory::create(); //create factory
55+
auto anExecTodo=tmpTodoFactory->createExec(dataToSend); //create ExecTodo from factory
56+
std::string toSend= tmpTodoFactory->save(anExecTodo);
57+
protocolBaseServer pclient(sockfd);
58+
pclient.DoWrite(toSend);
59+
60+
//read the object sent back
61+
std::string received;
62+
pclient.DoRead();
63+
64+
auto execReturned = tmpTodoFactory->load(pclient.getTotalMessage());
65+
execReturned->Do();
66+
67+
68+
//archive
69+
70+
return 0;
71+
}

client/src/client.cpptest

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
2+
#include <string>
3+
#include <iostream>
4+
#include "todoFactory.h"
5+
6+
#include <memory>
7+
8+
int main(void)
9+
{
10+
char mtype=0x01;
11+
std::string dataToSend = "ls -al /home/ajonen";
12+
13+
auto tmpTodoFactory=todoFactory::create(); //create factory
14+
auto anExecTodo=tmpTodoFactory->createExec(dataToSend); //create ExecTodo from factory
15+
std::string toSend= tmpTodoFactory->save(std::move(anExecTodo));
16+
return 0;
17+
}

client/src/client.cppv1

+172
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
extern "C"{
2+
#include <sys/socket.h>
3+
#include <sys/types.h>
4+
#include <netinet/in.h>
5+
#include <netdb.h>
6+
#include <stdio.h>
7+
#include <string.h>
8+
#include <stdlib.h>
9+
#include <unistd.h>
10+
#include <errno.h>
11+
#include <arpa/inet.h>
12+
#include <ctype.h>
13+
#include <stdarg.h>
14+
#include <string.h>
15+
#include <stdint.h>
16+
#include <inttypes.h>
17+
}
18+
#include <string>
19+
#include <iostream>
20+
#include "protocolBaseServer.h"
21+
#include "todoFactory.h"
22+
#include <memory>
23+
// various bits for floating point types--
24+
// varies for different architectures
25+
typedef float float32_t;
26+
typedef double float64_t;
27+
28+
/*
29+
** packi16() -- store a 16-bit int into a char buffer (like htons())
30+
*/
31+
void packi16(unsigned char *buf, unsigned int i)
32+
{
33+
*buf++ = i>>8; *buf++ = i;
34+
}
35+
36+
/*
37+
** packi32() -- store a 32-bit int into a char buffer (like htonl())
38+
*/
39+
/*
40+
void packi32(unsigned char *buf, unsigned long i)
41+
{
42+
*buf++ = i>>24; *buf++ = i>>16;
43+
*buf++ = i>>8; *buf++ = i;
44+
}
45+
46+
bool DoRead(const int & sock,void * data,uint32_t size){
47+
uint32_t bytesRead=0;
48+
while(bytesRead!=size){
49+
uint32_t readThisTime;
50+
do{
51+
readThisTime=recv(sock,data+bytesRead,size-bytesRead,0); // Receive the message length
52+
}while((readThisTime == -1) && (errno == EINTR));
53+
if(readThisTime<0){
54+
std::cout << "read failure" << std::endl;
55+
return false;
56+
}
57+
bytesRead+=readThisTime;
58+
}
59+
return true;
60+
}
61+
62+
63+
bool DoWrite(const int & sock,void * data,uint32_t size){
64+
uint32_t bytesWrite=0;
65+
// std::cout << "size: " << size << st::endl;
66+
while(bytesWrite!=size){
67+
uint32_t WriteThisTime;
68+
do{
69+
WriteThisTime=send(sock,data+bytesWrite,size-bytesWrite,0); // Receive the message length
70+
}while((WriteThisTime == -1) && (errno == EINTR));
71+
if(WriteThisTime<0){
72+
std::cout << "Write failure" << std::endl;
73+
return false;
74+
}
75+
bytesWrite+=WriteThisTime;
76+
}
77+
std::cout << "bytes Write: " << bytesWrite << std::endl;
78+
return true;
79+
}
80+
81+
*/
82+
int main(void)
83+
{
84+
int sockfd = 0,n = 0;
85+
unsigned char sendBuff[2];
86+
struct sockaddr_in serv_addr;
87+
int i = 200;
88+
packi16(sendBuff,i);
89+
90+
// data
91+
// strcat(total,(char*)sendBuffFloat);
92+
if((sockfd = socket(AF_INET, SOCK_STREAM, 0))< 0)
93+
{
94+
printf("\n Error : Could not create socket \n");
95+
return 1;
96+
}
97+
98+
serv_addr.sin_family = AF_INET;
99+
serv_addr.sin_port = htons(3000);
100+
serv_addr.sin_addr.s_addr = inet_addr("127.0.0.1");
101+
102+
if(connect(sockfd, (struct sockaddr *)&serv_addr, sizeof(serv_addr))<0)
103+
{
104+
printf("\n Error : Connect Failed \n");
105+
return 1;
106+
}
107+
/*
108+
n = write(sockfd, sendBuff, sizeof(sendBuff));
109+
while(n!=strlen((char*)sendBuff)&&n!=-1 ){
110+
n = write(sockfd, sendBuff, sizeof(sendBuff));
111+
}
112+
if(n<0){
113+
printf("Error Sending Data\n");
114+
}
115+
*/
116+
//framing up the execute class from the client side
117+
//here we are sending an execute statement and expecting some feedback
118+
//the type identifier goes first 0x01
119+
//the server reads this and knows what action it is to take
120+
char mtype=0x01;
121+
std::string smtype(1,mtype);
122+
std::string dataToSend = "ls -al /home/ajonen";
123+
124+
std::unique_ptr<todoFactory> tmpTodoFactory; //create factory
125+
std::unique_ptr<aTodo> anExecTodo=tmpTodoFactory->createAtodo(mtype,dataToSend); //create ExecTodo from factory
126+
protocolBaseServer pBase(sockfd); //create socket connection
127+
anExecTodo->SendBack(pBase);//send the exec through the socket for running
128+
//now read back in results , this functionality should be added to the factory as a member function
129+
//readATodo
130+
pBase.DoRead();
131+
char tmpType=pBase.getTotalMessage().at(0);
132+
std::string remainder=pBase.getTotalMessage().substr(1);
133+
//reset
134+
anExecTodo=tmpTodoFactory->retrieveAtodo(tmpType,remainder);
135+
//dataToSend=mtype+dataToSend;
136+
//std::cout << "datatosend: " << dataToSend << std::endl;
137+
//std::cout << "size: " << dataToSend.length() << std::endl;
138+
139+
//pBase.DoWrite(smtype);
140+
141+
//uint32_t dataLength = htonl(dataToSend.size()); // Ensure network byte order
142+
//bool ok;
143+
//ok=DoWrite(sockfd,&dataLength,sizeof(uint32_t));
144+
//ok=DoWrite(sockfd,&(dataToSend[0]),dataToSend.size());
145+
//std::cout << "Send ok: "<< ok << std::endl;
146+
147+
/*
148+
* now we are going to read in the results of std::cout and std::cerr
149+
//this needs to be debugged further
150+
pBase.DoRead();
151+
std::string strLengthOfOut=pBase.getTotalMessage().substr(0,sizeof(int32_t));
152+
//remove the length of stdcout from the message
153+
pBase.setMessage(pBase.getTotalMessage().substr(sizeof(int32_t)));
154+
//extract the length of std out which is the first 4 bytes in network byte order
155+
char clengthOfOut[sizeof(int32_t)];
156+
strcpy(clengthOfOut,strLengthOfOut.substr(0,sizeof(int32_t)).c_str());
157+
int32_t lengthOfStdOut;
158+
memcpy(&lengthOfStdOut,clengthOfOut+0,sizeof(int32_t));
159+
//convert to host byte order
160+
lengthOfStdOut=ntohl(lengthOfStdOut);
161+
//remove stdOut from string;
162+
std::string stdOut=pBase.getTotalMessage().substr(0,lengthOfStdOut);
163+
std::cout << "stdOut: " << stdOut << std::endl;
164+
//reset totalMessage
165+
*/
166+
//int num=send(sockfd,&dataLength ,sizeof(uint32_t) ,MSG_CONFIRM); // Send the data length
167+
//int numSent=send(sockfd,dataToSend.c_str(),dataToSend.size(),MSG_CONFIRM); // Send the string
168+
//std::cout << "actual sent: " << numSent;
169+
170+
171+
return 0;
172+
}

client/src/protoService.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../server/src/protoService.cpp

client/src/protocolBaseServer.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../../server/src/protocolBaseServer.cpp

0 commit comments

Comments
 (0)