user513164
user513164

Reputation: 1858

thrift programming problem

hi i just start programming with thrift api . i run a sample code but i dont know how to run thrift program. i just did following :

code;

{#!/usr/local/bin/thrift --gen cpp

namespace cpp Test

service Something {
  i32 ping()
}

than run command thrift --gen cpp your_thrift_file.thrift

it generate seven file in a folder name gen-cpp which are following:

Something.cpp
Something.h

Something_server.skeleton.cpp
your_thrift_file_constants.cpp
your_thrift_file_constants.h
your_thrift_file_types.cpp
your_thrift_file_types.h

now i compile them all together to get executable by following command

g++ -Wall -I/usr/local/include/thrift -c Something.cpp -o something.o
g++ -Wall -I/usr/local/include/thrift -c Something_server.cpp -o server.o
g++ -Wall -I/usr/local/include/thrift -c your_thrift_file_constants.cpp -o constants.o
g++ -Wall -I/usr/local/include/thrift -c your_thrift_file_types.cpp -o types.o

than i write a client code which is following

{  #include "Something.h"  // As an example

#include <transport/TSocket.h>
#include <transport/TBufferTransports.h>
#include <protocol/TBinaryProtocol.h>

using namespace apache::thrift;
using namespace apache::thrift::protocol;
using namespace apache::thrift::transport;

using namespace Test;

int main(int argc, char **argv) {
  boost::shared_ptr<TSocket> socket(new TSocket("localhost", 9090));
  boost::shared_ptr<TTransport> transport(new TBufferedTransport(socket));
  boost::shared_ptr<TProtocol> protocol(new TBinaryProtocol(transport));

  SomethingClient client(protocol);
  transport->open();
  client.ping();
  transport->close();

  return 0;
}

now than i compile it with command

g++ -Wall -I/usr/local/include/thrift -c something_client.cpp -o client.o

and than make the executable by following command

g++ -L/usr/local/lib -lthrift client.o Something.o constants.o types.o -o Something_client

But when i run it it shows following error

command: ./Somthing_client result:Thrift: Fri May 20 10:49:17 2011 TSocket::open() connect() Connection refused terminate called after throwing an instance of 'apache::thrift::transport::TTransportException' what(): connect() failed: Connection refused Aborted

now i don't understand what I'm doing wrong? can anybody explain me thrift working ? how to run this code properly ? what is this code doing ?

Upvotes: 0

Views: 6784

Answers (1)

pmont
pmont

Reputation: 2129

Is your Thrift server running too? The client needs something to connect to. The error looks like there's no open socket on port 9090 (set in your code).

Upvotes: 1

Related Questions