当前位置:网站首页>Thrift easy to use
Thrift easy to use
2022-06-30 09:41:00 【Zip-List】
git clone https://github.com/apache/thrift.git
// Official website readme.md
install
install bison flex package
https://blog.csdn.net/Tosonw/article/details/102640385
openssl/opensslv.h: No such file or directory
sudo apt-get install libssl-dev
thriftl.cc Can't find
thrift updating lex.yythrift/thriftl.cc mv: cannot move ‘tmp-thriftl.cc’ to ‘…/lex.yythrift/thriftl.cc’: No such file or directory
https://github.com/sunchao/parquet-rs/issues/74
again ./boosttrap.sh + ./configure
make
make install
thrift --version
Easy to use
https://diwakergupta.github.io/thrift-missing-guide/
https://blog.csdn.net/tuwenqi2013/article/details/105541475
---gen-cpp
---Serv_server.skeleton.cpp
---Serv.cpp
---Serv.h
---student_types.cpp
---student_types.h
cleint.cpp
server.cpp
student.thrift
1 Definition thrift file
student.thrift
Use , And there's no ;
struct Student{
1: i32 sno,
2: string sname,
3: bool ssex,
4: i16 sage,
}
service Serv{
void put(1: Student s),
}
thrift -r --gen cpp student.thrift Generate gen-cpp Folder
- No in the tutorial xxx_constant.cpp The document is because thrift It's not in the definition const Constant , No effect
- Generate the file Serv_server.skeleton.cpp It's similar to svr Part of the code , No need to deal with it , No logic will be written in the generated folder
2 server.cpp/client.cpp
server Realization put Functional handler
// This autogenerated skeleton file illustrates how to build a server.
// You should copy it to another filename to avoid overwriting it.
#include "gen-cpp/Serv.h""
#include <thrift/protocol/TBinaryProtocol.h>
#include <thrift/server/TSimpleServer.h>
#include <thrift/transport/TServerSocket.h>
#include <thrift/transport/TBufferTransports.h>
using namespace ::apache::thrift;
using namespace ::apache::thrift::protocol;
using namespace ::apache::thrift::transport;
using namespace ::apache::thrift::server;
class ServHandler : virtual public ServIf {
public:
ServHandler() {
// Your initialization goes here
}
void put(const Student& s) {
// Your implementation goes here
printf("put\n");
printf("name:%s\n", s.sname.c_str());
printf("sex:%d\n", s.ssex);
}
};
int main(int argc, char **argv) {
int port = 9090;
::std::shared_ptr<ServHandler> handler(new ServHandler());
::std::shared_ptr<TProcessor> processor(new ServProcessor(handler));
::std::shared_ptr<TServerTransport> serverTransport(new TServerSocket(port));
::std::shared_ptr<TTransportFactory> transportFactory(new TBufferedTransportFactory());
::std::shared_ptr<TProtocolFactory> protocolFactory(new TBinaryProtocolFactory());
TSimpleServer server(processor, serverTransport, transportFactory, protocolFactory);
server.serve();
return 0;
}
client With the corresponding handler Server establishes connection , Make a remote call
#include "gen-cpp/Serv.h"
#include </usr/local/include/thrift/transport/TSocket.h>
#include </usr/local/include/thrift/transport/TBufferTransports.h>
#include </usr/local/include/thrift/protocol/TBinaryProtocol.h>
#include <iostream>
using namespace apache::thrift;
using namespace apache::thrift::protocol;
using namespace apache::thrift::transport;
//using boost::shared_ptr;
int main(int argc, char **argv) {
std::shared_ptr<TSocket> socket(new TSocket("127.0.0.1", 9090));
std::shared_ptr<TTransport> transport(new TBufferedTransport(socket));
std::shared_ptr<TProtocol> protocol(new TBinaryProtocol(transport));
transport->open();
//***************** Add part ******************
Student s;
s.sno = 123;
s.sname = "xiaoshe";
s.ssex = 1;
s.sage = 30;
ServClient client(protocol);
std::cout<<"client send a data"<<std::endl;;
client.put(s);
//***************** Add part ******************
transport->close();
return 0;
}
3 compile
g++ -g -o server -Ithrift ./gen-cpp/Serv.cpp ./gen-cpp/student_types.cpp server.cpp -lthrift
g++ -g -o client -Ithrift ./gen-cpp/Serv.cpp ./gen-cpp/student_types.cpp client.cpp -lthrift
cannot find libthrift.so
ldd ./server
sudo find / -name libthrift-0.17.0.so See if you have this file
1、 stay usr/lib There are these library files in the directory
Just fix the following links , For example, execute in sequence
ln -s lib***.so.6( Some number ) lib***.so
2、 stay usr/lib There are no such files in the directory
Search these library files directly in the root directory of the system , And use
sudo cp Library filename /usr/lib
Command to copy the corresponding library file to the directory
边栏推荐
- Solution to pychart's failure in importing torch package
- Simple redis lock
- 7. know JNI and NDK
- Pipe pipe --namedpipe and anonymouspipe
- Linear-gradient()
- 5. Messager framework and imessager interface
- Framework program of browser self-service terminal based on IE kernel
- GPT (improving language understanding generative pre training) paper notes
- Tclistener server and tcpclient client
- Numpy (data type)
猜你喜欢

机器学习笔记 九:预测模型优化(防止欠拟合和过拟合问题发生)

ES6 learning path (III) deconstruction assignment

Pytorch graduate warm LR installation

Deberta (decoding enhanced Bert with distinguished attention)

仿照微信Oauth2.0接入方案

Small program learning path 1 - getting to know small programs

近期学习遇到的比较问题

Electron, which can wrap web page programs into desktop applications

八大排序(二)

About the smart platform solution for business hall Terminal Desktop System
随机推荐
How do I start? (continuously updating)
Deep Learning with Pytorch - autograd
I once met a girl whom I most wanted to take care of all my life. Later... No later
Tclistener server and tcpclient client use -- socket listening server and socketclient use
Task summary in NLP
银河麒麟server-V10配置镜像源
MySQL优化
ReturnJson,让返回数据多一些自定义数据或类名
MySQL-- Entity Framework Code First(EF Code First)
What is the difference between ZigBee, Bluetooth and WiFi (copy and reprint)
Recommend a very easy-to-use network communication framework HP socket
MySQL internal component structure
ABAP-时间函数
Deep Learning with Pytorch- A 60 Minute Blitz
8.8 heap insertion and deletion
Idea setting automatic package Guide
Distributed session
Pipe pipe --namedpipe and anonymouspipe
utils 协程
ES6 learning path (IV) operator extension