libtasks Documentation  1.6
ip_service_client/thrift_http_client.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013-2014 ADTECH GmbH
3  * Licensed under MIT (https://github.com/adtechlabs/libtasks/blob/master/COPYING)
4  *
5  * Author: Andreas Pohl
6  */
7 
8 #include <iostream>
9 #include <arpa/inet.h>
10 #include <thrift/protocol/TBinaryProtocol.h>
11 #include <thrift/transport/THttpClient.h>
12 #include <boost/shared_ptr.hpp>
13 #include <IpService.h>
14 
15 int main(int argc, char** argv) {
16  using namespace apache::thrift::protocol;
17  using namespace apache::thrift::transport;
18  boost::shared_ptr<THttpClient> transport(new THttpClient("localhost", 8080, "/"));
19  boost::shared_ptr<TBinaryProtocol> protocol(new TBinaryProtocol(transport));
20  IpServiceClient client(protocol);
21 
22  try {
23  transport->open();
24 
25  std::cout << "Sending request" << std::endl;
26  int32_t ip = 123456789;
27  ipv6_type ipv6;
28  response_type r;
29  client.lookup(r, ip, ipv6);
30 
31  for (auto& kv : r.key_values) {
32  std::cout << "key.id=" << kv.key.id << " key.name=" << kv.key.name << std::endl;
33  for (auto& val : kv.values) {
34  std::cout << " val.id=" << val.id << " val.name=" << val.name << std::endl;
35  }
36  }
37 
38  transport->close();
39  } catch (TTransportException& e) {
40  std::cerr << e.what() << std::endl;
41  }
42 
43  return 0;
44 }
int main(int argc, char **argv)