Rev | Line | |
---|
[4942] | 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 |
|
---|
[4944] | 15 | class myService : virtual public myServiceIf {
|
---|
[4942] | 16 | public:
|
---|
[4944] | 17 | myService() {}
|
---|
[4951] | 18 | void answer(const std::string& question) {
|
---|
[4942] | 19 | cout << "Server asks: " << question << endl;
|
---|
| 20 | }
|
---|
| 21 |
|
---|
| 22 | };
|
---|
| 23 |
|
---|
| 24 | int main(int argc, char** argv) {
|
---|
| 25 | int port = 9090;
|
---|
[4944] | 26 | shared_ptr<TSocket> socket(new TSocket("localhost", port));
|
---|
| 27 | shared_ptr<TTransport> transport(new TBufferedTransport(socket));
|
---|
| 28 | shared_ptr<TProtocol> protocol(new TBinaryProtocol(transport));
|
---|
[4942] | 29 |
|
---|
[4944] | 30 | shared_ptr<myService> service(new myService());
|
---|
| 31 | shared_ptr<TProcessor> processor(new myServiceProcessor(service));
|
---|
[4942] | 32 |
|
---|
| 33 | try {
|
---|
| 34 | transport->open();
|
---|
| 35 |
|
---|
| 36 | while (processor->process(protocol, protocol, 0)) {}
|
---|
| 37 |
|
---|
| 38 | transport->close();
|
---|
| 39 | } catch (TException& exc) {
|
---|
| 40 | cout << "Exception: " << exc.what() << endl;
|
---|
| 41 | }
|
---|
| 42 |
|
---|
| 43 | return 0;
|
---|
| 44 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.