C++ based Server Something_server
has a method that prints ping
#include "Something.h"
#include <protocol/TBinaryProtocol.h>
#include <server/TSimpleServer.h>
#include <transport/TServerSocket.h>
#include <transport/TBufferTransports.h>
using namespace ::apache::thrift;
using namespace ::apache::thrift::protocol;
using namespace ::apache::thrift::transport;
using namespace ::apache::thrift::server;
using boost::shared_ptr;
using namespace Test;
class SomethingHandler : virtual public SomethingIf {
public:
SomethingHandler() {
// Your initialization goes here
}
int32_t ping() {
// Your implementation goes here
printf("ping\n");
return 0;
}
};
int main(int argc, char **argv) {
int port = 9090;
shared_ptr<SomethingHandler> handler(new SomethingHandler());
shared_ptr<TProcessor> processor(new SomethingProcessor(handler));
shared_ptr<TServerTransport> serverTransport(new TServerSocket(port));
shared_ptr<TTransportFactory>开发者_高级运维 transportFactory(new TBufferedTransportFactory());
shared_ptr<TProtocolFactory> protocolFactory(new TBinaryProtocolFactory());
TSimpleServer server(processor, serverTransport, transportFactory, protocolFactory);
server.serve();
return 0;
}
Something_client
is supposed to call this method in order to print out "ping"
#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;
}
instructions say "run the server and ping it with client"....no clue what this means...
I do
./Something_server
and nothing happens....as if the command were running forever and not terminating...so I am not quite sure how to proceed.
All help is appreciated.
It means that you should first run ./Something_server & (& puts the job in background so it doesnt clutter output). Then you run ./Something_client which apparently pings the server.
精彩评论