当前位置:网站首页>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
边栏推荐
- Ocx control can be called by IE on some computers, but can not be called by IE on some computers
- Deberta (decoding enhanced Bert with distinguished attention)
- Niuke rearrangement rule taking method
- Use V-IF with V-for
- Solution to the eighth training competition of 2020 Provincial Games
- Bluetooth BT RF test (forwarding)
- Why won't gold depreciate???
- utils session&rpc
- 直播带货源码开发中,如何降低直播中的延迟?
- Distributed session
猜你喜欢

7. know JNI and NDK

Pytorch graduate warm LR installation

Express の post request

Idea setting automatic package Guide

Idea shortcut key settings

So the toolbar can still be used like this? The toolbar uses the most complete parsing. Netizen: finally, you don't have to always customize the title bar!

Distributed things

Handwriting sorter component

Small program learning path 1 - getting to know small programs

4. use ibinder interface flexibly for short-range communication
随机推荐
MySQL explain
NER – Named Entity Recognition Summary
ACM intensive training graph theory exercise 3 in the summer vacation of 2020 [problem solving]
八大排序(二)
I once met a girl whom I most wanted to take care of all my life. Later... No later
11.自定义hooks
OCX child thread cannot trigger event event (forward)
QR code generation and analysis
工作小记: sendto失败 errno 22
Deep Learning with Pytorch - autograd
云技能提升好伙伴,亚马逊云师兄今天正式营业
Self service terminal development process
Flutter 0001, environment configuration
ES6 learning path (IV) operator extension
Numpy (time date and time increment)
Electron, which can wrap web page programs into desktop applications
Flutter theme (skin) changes
Distributed session
Tutorial for beginners of small programs day01
thrift简单使用