generated from sfuad001/Project-CS180
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathtest.cc
137 lines (107 loc) · 4.32 KB
/
test.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#include<iostream>
#include <vector>
#include <boost/algorithm/string.hpp>
#include "./server.h"
// #include "./datastruct/database.h"
using namespace std;
/*
- Builds executable that will setup the server and except ONLY one (1) connection.
- Send any message containing 'QUIT' to close connection and server
*/
int main()
{
Server myServer;
char buffer[BUFFER_LEN];
// Setup server, accept connection from client, and read first message
myServer.setup_server();
int connection = myServer.accept_connection();
size_t messageSize = myServer.read_from(connection, buffer);
// // if(strcmp(buffer, "file"))
// // {
// // // First call to get the first line from the file
// // myServer.read_from(connection, buffer);
// // char * filePath = "testRecv.csv";
// // while(string(buffer).find("DONE") == string::npos)
// // {
// // // cout << "In here\n";
// // // myServer.write_file("src/testRecv.csv", buffer, 0);
// // myServer.write_file(filePath, buffer, 0);
// // // Gets the next line after sending in the first one
// // myServer.read_from(connection, buffer);
// // }
// // }
// // else
// // {
// cout << "Entered Else clause\n";
// size_t messageSize = myServer.read_from(connection, buffer);
string response; // Declare response string
// Send/recieve loop
while (string(buffer).find("QUIT") == string::npos)
{
cout << "In loop\n";
cout << "\033[35mThe message was: " << string(buffer) << "\033[0m"<<endl;
myServer.execute(buffer);
/* HELPER FUNCTIONS PROOF OF CONCEPT
// Tokenize word
vector<string> message = myServer.word_tokenize(buffer, ' ');
cout << "Tokenized word: " << endl;
for (string w : message) {
cout << w << endl;
}
// Rejoin word
string mes = myServer.join_words(message);
cout << "Rejoined message: " << mes << endl;
/*
//can be made into seperate function
/*
string temp = string(buffer);
string createDB = "BUILD DB";
if(temp.find(createDB)!= string::npos)
{
temp.erase(temp.find(createDB), createDB.size());
cout<<"create db called: "<<temp<<endl;
myServer.initDB(temp);
}
// BUILD TABLE <tableName> WITH <columns> <fields*>
string createTable = "BUILD TABLE ";
if(temp.find(createTable)!= string::npos)
{
string WITH = " WITH ";
if(temp.find(WITH)!= string::npos)
{
cout<<"create table called correctly"<<endl;
string tableName;
vector<string> colNames;
tableName = temp.substr(0, temp.find(WITH));
temp.erase(0, temp.find(WITH) + WITH.size());
// cout<<tableName;
cout<<"."<<endl;
while(temp.find(',') != string::npos)
{
string t = temp.substr(0, temp.find(','));
boost::trim(t);
colNames.push_back(t);
cout<<t;
temp.erase(0, temp.find(',')+1);
}
boost::trim(temp);
colNames.push_back(temp);
cout<<temp;
myServer.getDB()->createTable(tableName, colNames.size(), colNames);
vector<string> dummyRow = {"one","two","three"};
myServer.getDB()->getTable(tableName)->add_row(dummyRow);
myServer.getDB()->getTable(tableName)->print_all_data();
}
}
*/
response = "This is a response\n";
myServer.send_to(connection, response.c_str());
messageSize = myServer.read_from(connection, buffer);
// std::cout << buffer << std::endl;
// }
}
// Clean up
myServer.close_connection(connection);
myServer.close_server();
return 0;
}