forked from dase/CLAIMS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathboost.cpp
executable file
·249 lines (194 loc) · 5.16 KB
/
boost.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
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
/*
* boost.cpp
*
* Created on: May 11, 2013
* Author: wangli
*/
#include <Theron/Theron.h>
#include <stdio.h>
#include <unistd.h>
#include <string>
//#include <boost/archive/binary_oarchive.hpp>
//#include <boost/archive/binary_iarchive.hpp>
#include <fstream>
#include <iostream>
#include <sstream>
// Simple message type that can be copied with memcpy so safely sent over the network.
struct TextMessage
{
explicit TextMessage(const char *const text)
{
mText[0] = '\0';
strcpy(mText, text);
}
char mText[256];
};
// In order to be sent over the network, message types must be registered.
THERON_REGISTER_MESSAGE(TextMessage);
THERON_REGISTER_MESSAGE(double);
class Printer : public Theron::Actor
{
public:
Printer(int no,Theron::Framework &framework, const char *const name) :
Theron::Actor(framework, name),no(no)
{
RegisterHandler(this, &Printer::Handler);
}
private:
void Handler(const TextMessage &message, const Theron::Address from)
{
printf("%s\n", message.mText);
if (strcmp(message.mText, "exit") == 0)
{
// Signal we're done.
if(no==0)
;
//Send(0, Theron::Address("receiver"));
else
Send(0, Theron::Address("receiver1"));
}
}
int no;
};
class Printer1 : public Theron::Actor
{
public:
Printer1(int no,Theron::Framework &framework, const char *const name) :
Theron::Actor(framework, name),no(no)
{
RegisterHandler(this, &Printer1::Handler);
}
private:
void Handler(const double &message, const Theron::Address from)
{
printf("Printter1:%f\n",message);
// if (strcmp(message.mText, "exit") == 0)
// {
// // Signal we're done.
// if(no==0)
// Send(0, Theron::Address("receiver"));
// else
// Send(0, Theron::Address("receiver1"));
// }
}
int no;
};
int server();
int client();
/**
* The sender do not need to connect to the receiver, but it is not true vasa viser.
*/
int main234()
{
/*
printf("Begins!\n");
const A a(3);
const int iii=3;
std::ostringstream ss;
boost::archive::binary_oarchive oa(ss);
oa << a;
std::string str=ss.str();
printf("\nlength=%d",str.length());
std::istringstream is(str+" asf ");
boost::archive::binary_iarchive ia(is);
int b=10;
A bb(5);
ia >> bb;
bb.p();
//printf("b=%d",b);
//is.close();*/
char switcher;
scanf("%c",&switcher);
if(switcher=='s')
{
server();
}
else
{
client();
}
return 1;
}
int server()
{
printf("Give me the printer Number : 0 or 1");
int no;
scanf("%d",&no);
char buffer[256] = { '\0' };
// Create a local endpoint.
if(no==0)
sprintf(buffer, "tcp://58.198.176.121:5555");
else
sprintf(buffer, "tcp://58.198.176.121:5557");
Theron::EndPoint endPoint("server", buffer);
// Connect to the remote endpoint.
sprintf(buffer, "tcp://58.198.176.121:5556");
if (!endPoint.Connect(buffer))
{
printf("ERROR: Connection failed - check networking is enabled.\n");
return 1;
}
// The framework and receiver are tied to the endpoint.
if(no==0)
{
//Theron::Receiver receiver(endPoint, "receiver");
Theron::Framework framework(endPoint);
Printer printer(no,framework, "printer");
Printer1 printer1(no,framework, "printer1");
//receiver.Wait();
while(1);
}
else
{
Theron::Receiver receiver(endPoint, "receiver1");
Theron::Framework framework(endPoint);
Printer printer1(no,framework,"printer");
receiver.Wait();
}
}
int client()
{
char buffer[256] = { '\0' };
// Create a local endpoint.
sprintf(buffer, "tcp://58.198.176.121:5556");
Theron::EndPoint endPoint("client", buffer);
// Connect to the remote endpoint.
sprintf(buffer, "tcp://58.198.176.121:5555");
if (!endPoint.Connect(buffer))
{
printf("ERROR: Connection failed - check networking is enabled.\n");
return 1;
}
else
{
printf("Connected to %s\n",buffer);
}
sprintf(buffer, "tcp://58.198.176.121:5557");
if (!endPoint.Connect(buffer))
{
printf("ERROR: Connection failed - check networking is enabled.\n");
return 1;
}
else
{
printf("Connected to %s\n",buffer);
}
// The framework is tied to the endpoint.
Theron::Framework framework(endPoint);
// Send messages to the server in a loop until the user enters 'exit'.
// Note that if the server hasn't started listening yet it may miss the first messages!
printf("Enter lines of text (max 256 chars per line). Type 'exit' to end.\n");
while (strcmp(buffer, "exit") != 0)
{
// Send the text in a messages to the remote 'printer' actor using its unique name.
gets(buffer);
framework.Send(
TextMessage(buffer),
Theron::Address(),
Theron::Address("printer"));
framework.Send(
double(28.234),
Theron::Address(),
Theron::Address("printer1"));
}
}