Line | |
---|
1 | #include <iostream>
|
---|
2 |
|
---|
3 | #include <thrift/protocol/TBinaryProtocol.h>
|
---|
4 | #include <thrift/transport/TSocket.h>
|
---|
5 | #include <thrift/transport/TTransportUtils.h>
|
---|
6 |
|
---|
7 | #include "gen-cpp/myService.h"
|
---|
8 |
|
---|
9 | using namespace std;
|
---|
10 | using namespace boost;
|
---|
11 | using namespace apache::thrift;
|
---|
12 | using namespace apache::thrift::protocol;
|
---|
13 | using namespace apache::thrift::transport;
|
---|
14 |
|
---|
15 | class myService : virtual public myServiceIf {
|
---|
16 | public:
|
---|
17 | myService() {}
|
---|
18 | void answer(std::string& answ, const std::string& question) {
|
---|
19 | cout << "Server asks: " << question << endl;
|
---|
20 | answ = "I am well, thanks.";
|
---|
21 | }
|
---|
22 |
|
---|
23 | };
|
---|
24 |
|
---|
25 | int main(int argc, char** argv) {
|
---|
26 | int port = 9090;
|
---|
27 | shared_ptr<TSocket> socket(new TSocket("localhost", port));
|
---|
28 | shared_ptr<TTransport> transport(new TBufferedTransport(socket));
|
---|
29 | shared_ptr<TProtocol> protocol(new TBinaryProtocol(transport));
|
---|
30 |
|
---|
31 | shared_ptr<myService> service(new myService());
|
---|
32 | shared_ptr<TProcessor> processor(new myServiceProcessor(service));
|
---|
33 |
|
---|
34 | try {
|
---|
35 | transport->open();
|
---|
36 |
|
---|
37 | while (processor->process(protocol, protocol, 0)) {}
|
---|
38 |
|
---|
39 | transport->close();
|
---|
40 | } catch (TException& exc) {
|
---|
41 | cout << "Exception: " << exc.what() << endl;
|
---|
42 | }
|
---|
43 |
|
---|
44 | return 0;
|
---|
45 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.