/** * Created by wuchong on 15/10/7. */ publicclassAccountServiceimplementsAccount.Iface{ privatestatic Map<String, String> accounts = new HashMap<>();
@Override public String doAction(Request request)throws InvalidOperation { String name = request.getName(); String pass = request.getPassword(); Operation op = request.getOp();
if (name == null || name.length() == 0){ thrownew InvalidOperation(100, "param name should not be empty"); }
/** * Created by wuchong on 15/10/7. */ publicclassAccountServer{ publicstaticvoidmain(String[] args)throws Exception { TServerSocket socket = new TServerSocket(9999); Account.Processor processor = new Account.Processor<>(new AccountService()); TServer server = new TSimpleServer(new TServer.Args(socket).processor(processor)); System.out.println("Starting the Account server..."); server.serve(); } }
/** * Created by wuchong on 15/10/7. */ publicclassAccountClient{ publicstaticvoidmain(String[] args)throws TException { TTransport transport = new TSocket("localhost", 9999); transport.open(); //建立连接
TProtocol protocol = new TBinaryProtocol(transport); Account.Client client = new Account.Client(protocol);
Login failed!! please check your username and password Register success!! Hello wuchong Login success!! Hello wuchong param name should not be empty
而此时,服务端会打印出收到的请求信息。
Starting the Account server... Get request[name:wuchong, pass:1234, op:1] Get request[name:wuchong, pass:1234, op:2] Get request[name:wuchong, pass:1234, op:1] Get request[name:, pass:1234, op:1]