-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
112 lines (80 loc) · 2.66 KB
/
main.cpp
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
#include <iostream>
#include <winsock2.h>
#include <string.h>
#include "rapidjson/document.h"
#include "rapidjson/writer.h"
#include "rapidjson/stringbuffer.h"
#include "file_handle.c"
#include "lang/lang.cpp"
using namespace std;
using namespace rapidjson;
int main()
{
WSADATA WSAData;
SOCKET server, client;
SOCKADDR_IN serverAddr, clientAddr;
WSAStartup(MAKEWORD(2,0), &WSAData);
server = socket(AF_INET, SOCK_STREAM, 0);
serverAddr.sin_addr.s_addr = INADDR_ANY;
serverAddr.sin_family = AF_INET;
serverAddr.sin_port = htons(5555);
bind(server, (SOCKADDR *)&serverAddr, sizeof(serverAddr));
listen(server, 0);
cout << "Welcome LeoDB Version 1.0.." << endl;
// string buffer;
int clientAddrSize = sizeof(clientAddr);
if((client = accept(server, (SOCKADDR *)&clientAddr, &clientAddrSize)) != INVALID_SOCKET)
{
cout << "Client connected!" << endl;
while(true){
char buffer[1024 * 1024] = "";
recv(client, buffer, sizeof(buffer), 0);
if(strncmp(buffer, "", 1) != 0 ){
cout << "Client says: " << buffer << endl;
Lang lang(buffer);
char *gpName;
//lang.getGraphName(gpName);
if(lang.isVaildPattern()){
cout << "Graph : " << lang.getGraphName() << endl;
cout << "Action : " << lang.getAction() << endl;
cout << "Data : " << lang.getData() << endl;
} else{
cout << "Invalid Input" << endl;
}
//
//
// Document d;
// d.Parse(buffer);
//
//
// Value &gpName = d["graph"];
// Value &gpData = d["data"];
//
// StringBuffer stBuffer;
// Writer<StringBuffer> writer(stBuffer);
// d.Accept(writer);
//
// char sm[16];
// char *data;
//
//
// strcpy(sm, gpName.GetString());
// strcpy(data, gpData.GetString());
//
//
// writeFile("test.ext", data);
// cout << "Sent : " << sm << endl;
// int BytesSent = send(client, sm , sizeof(sm), 0);
//
// char *dataFromFile;
// readFile("test.ext", dataFromFile);
// cout << "From File:" << dataFromFile << endl;
// if(BytesSent == SOCKET_ERROR) cout << "Error to send" << WSAGetLastError() << endl;
// strcpy(buffer, "");
memset(buffer, sizeof(buffer), 0);
}
}
closesocket(client);
cout << "Client disconnected." << endl;
}
}