-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNyanSync_client.cpp
72 lines (55 loc) · 1.4 KB
/
NyanSync_client.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
#include "NyanSync.h"
#include <iostream>
#include <fstream>
#include <transport/TSocket.h>
#include <transport/TBufferTransports.h>
#include <protocol/TBinaryProtocol.h>
#include "thread"
#include "Nyancat.cpp"
using namespace apache::thrift;
using namespace apache::thrift::protocol;
using namespace apache::thrift::transport;
using namespace nyan;
int clientId = 0;
int drawFrame = 0;
std::ofstream myfile;
int clientThread(char* server, int port) {
boost::shared_ptr<TSocket> socket(new TSocket(server, port));
boost::shared_ptr<TTransport> transport(new TFramedTransport(socket));
boost::shared_ptr<TProtocol> protocol(new TBinaryProtocol(transport));
SyncPacket packet;
NyanSyncClient client(protocol);
transport->open();
while (1) {
client.sync(packet);
if (packet.server == clientId) {
drawFrame = packet.frame;
}
usleep(FRAMESPEED);
}
transport->close();
return 0;
}
int drawThread() {
while(1) {
run_nyan(drawFrame);
usleep(FRAMESPEED);
}
return 0;
}
int main(int argc, char **argv) {
//check clientId
if (argc < 3) {
printf("need clientId/serverHost/serverPort to work\n");
return 1;
}
clientId = atoi(argv[1]);
char* serverHost = argv[2];
char* serverPort = argv[3];
std::thread clt(clientThread, serverHost, atoi(serverPort));
std::thread drw(drawThread);
clt.join();
drw.join();
myfile.close();
return 0;
}