【发布时间】:2011-08-29 09:29:58
【问题描述】:
嗨 我刚开始用 thrift api 编程。我运行了一个示例代码,但我不知道如何运行节俭程序。我只是做了以下事情:
代码;
{#!/usr/local/bin/thrift --gen cpp
namespace cpp Test
service Something {
i32 ping()
}
比运行命令 thrift --gen cpp your_thrift_file.thrift
它会在一个名为 gen-cpp 的文件夹中生成七个文件,如下所示:
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
现在我通过以下命令将它们全部编译以获取可执行文件
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
比我写的客户端代码跟在后面
{ #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;
}
现在比我用命令编译它
g++ -Wall -I/usr/local/include/thrift -c something_client.cpp -o client.o
然后通过以下命令生成可执行文件
g++ -L/usr/local/lib -lthrift client.o Something.o constants.o types.o -o Something_client
但是当我运行它时它显示以下错误
命令:./Somthing_client 结果:Thrift:2011 年 5 月 20 日星期五 10:49:17 TSocket::open() connect() 连接被拒绝 在抛出 'apache::thrift::transport::TTransportException' 的实例后调用终止 什么():连接()失败:连接被拒绝 中止
现在我不明白我做错了什么? 谁能解释我节俭的工作? 如何正确运行此代码? 这段代码在做什么?
【问题讨论】:
-
你在这里已经有一段时间了。您没有花一些时间正确地格式化您的问题,这很烦人。如果你连这个都做不到,我们为什么要回答你的问题?
-
朋友告诉我格式,把我当作一个老手或新手,给我确切的步骤或写作方法,以便我得到答案请不要告诉我或给我一些超链接为此
-
恕我直言,成为会员 9 个月并提出 40 个问题的人不是新手。你有没有注意到在你写完之后你的问题看起来很糟糕?你没有看到你写问题的文本框上方的工具栏吗?尝试将鼠标放在每个图标上方,看看它们做了什么。
-
男人真的不知道你在说什么。你在说什么图标,我从来没有见过他们,请给我正确的信息,告诉我我的错误,提问的方式,我所做的就是提出越来越多的信息,是的,我很弱英文