TSimpleServer:简单的阻塞式单线程模式
HelloTSimpleServer类
package com.simplemode;
import com.service.HelloServiceImpl;
import com.xxx.Hello;
import org.apache.thrift.TProcessor;
import org.apache.thrift.protocol.TBinaryProtocol;
import org.apache.thrift.server.TServer;
import org.apache.thrift.server.TSimpleServer;
import org.apache.thrift.transport.TServerSocket;
import org.apache.thrift.transport.TServerTransport;
import org.apache.thrift.transport.TTransportException;
/**
* @Auther: liuzhenbing
* @Date: 2018/7/31 15:09
* @Description:
*/
public class HelloTSimpleServer {
public static final int SERVER_PORT = 8080;
/**
* 单线程阻塞式IO
* @throws TTransportException
*/
public void startServer() throws TTransportException {
TProcessor processor = new Hello.Processor<HelloServiceImpl>(new HelloServiceImpl());
TServerTransport serverTransport = new TServerSocket(SERVER_PORT);
TServer.Args args = new TServer.Args(serverTransport);
args.processor(processor);
args.protocolFactory(new TBinaryProtocol.Factory());
TServer server = new TSimpleServer(args);
System.out.println("server starting.....");
server.serve();
}
public static void main(String[] args) throws TTransportException {
HelloTSimpleServer server = new HelloTSimpleServer();
server.startServer();
}
}
HelloClient类
package com.simplemode;
import com.xxx.Hello;
import org.apache.thrift.TException;
import org.apache.thrift.protocol.TBinaryProtocol;
import org.apache.thrift.protocol.TProtocol;
import org.apache.thrift.transport.TSocket;
import org.apache.thrift.transport.TTransport;
/**
* @Auther: liuzhenbing
* @Date: 2018/7/31 15:14
* @Description:
*/
public class HelloClient {
public static final String SERVER_IP = "localhost";
public static final int SERVER_PORT = 8080;
public static final int TIMEOUT = 3000;
public static void main(Stri