-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.cpp
110 lines (90 loc) · 2.19 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
#include <winsock2.h>
#include <iostream>
#include "Traffic.h"
#include "Order.h"
#include <ctime>
#define DEFAULT_BUFLEN 19 // Size of The packet
#define FULL_SIZE 6 // 5 fingers + 1 Accel'
using namespace std;
void closeSocket(SOCKET s);
void sendToOrder(string temp[FULL_SIZE]);
int main()
{
Interpreter interPreter = Interpreter();
char recvbuf[DEFAULT_BUFLEN+1]; // More one for the NULL byte.
int iResult;
SOCKET ClientSocket = Traffic().getSocket();
// Receive until the peer shuts down the connection
do {
iResult = recv(ClientSocket, recvbuf, DEFAULT_BUFLEN, 0); // Recv Data from Client.
recvbuf[19] = NULL;
cout << recvbuf << endl;
if (iResult > 0)
{
InfoPacket temPacket = InfoPacket(recvbuf); // Make InfoPacket from the Data.
if (interPreter.addInfoPacket(temPacket)) // Check if the Gesture is done.
{
cout << "In !\n";
string toSend[FULL_SIZE];
interPreter.saveTheSymbol(toSend); // Save the "Symbol" in 'toSend'.
sendToOrder(toSend);
interPreter.clearAll(); // Clear the InterPreter.
}
interPreter.InfoPacketsDetails();
interPreter.showSeq();
}
else if (iResult == 0)
{
// interPreter.showSeq();
/*string temp[NUM_FINGERS];
interPreter.saveTheSymbol(temp);
interPreter.InfoPacketsDetails();
sendToOrder(temp);*/
printf("Connection closing...\n");
}
else
{
printf("recv failed with error: %d\n", WSAGetLastError());
closesocket(ClientSocket);
WSACleanup();
return 1;
}
} while (iResult > 0);
closeSocket(ClientSocket); // Close The socket.
system("pause");
return 0;
}
/*
The Function Closes the Socket.
Input:
SOCKET s - The socket.
Output:
none
*/
void closeSocket(SOCKET s)
{
int iResult;
iResult = shutdown(s, SD_SEND);
if (iResult == SOCKET_ERROR) {
cout << ("shutdown failed with error: %d\n", WSAGetLastError());
closesocket(s);
WSACleanup();
return;
}
// cleanup
closesocket(s);
WSACleanup();
return;
}
/*
The function sends the temp(5 fingers state and accel') to the Order.
Input:
string temp[6] - 5 fingers state and accel'
Output:
none
*/
void sendToOrder(string temp[FULL_SIZE])
{
Order doTheCommands;
doTheCommands.TheComparetion(temp);
}