EchoClient.java revision b5a588df
1b5a588dfSShuo Chenpackage echo; 2b5a588dfSShuo Chen 3b5a588dfSShuo Chenimport java.net.InetSocketAddress; 4b5a588dfSShuo Chen 5b5a588dfSShuo Chenimport muduo.rpc.RpcChannel; 6b5a588dfSShuo Chenimport muduo.rpc.RpcClient; 7b5a588dfSShuo Chenimport echo.EchoProto.EchoRequest; 8b5a588dfSShuo Chenimport echo.EchoProto.EchoResponse; 9b5a588dfSShuo Chenimport echo.EchoProto.EchoService; 10b5a588dfSShuo Chenimport echo.EchoProto.EchoService.BlockingInterface; 11b5a588dfSShuo Chen 12b5a588dfSShuo Chenpublic class EchoClient { 13b5a588dfSShuo Chen 14b5a588dfSShuo Chen public static void main(String[] args) throws Exception { 15b5a588dfSShuo Chen RpcClient client = new RpcClient(); 16b5a588dfSShuo Chen RpcChannel channel = client.blockingConnect(new InetSocketAddress("localhost", 8888)); 17b5a588dfSShuo Chen BlockingInterface remoteService = EchoService.newBlockingStub(channel); 18b5a588dfSShuo Chen String payload = new String(new byte[100]); 19b5a588dfSShuo Chen payload = "Hello"; 20b5a588dfSShuo Chen EchoRequest request = EchoRequest.newBuilder().setPayload(payload).build(); 21b5a588dfSShuo Chen long start = System.currentTimeMillis(); 22b5a588dfSShuo Chen int N = 20000; 23b5a588dfSShuo Chen for (int i = 0; i < N; ++i) { 24b5a588dfSShuo Chen EchoResponse response = remoteService.echo(null, request); 25b5a588dfSShuo Chen assert response.getPayload().equals(payload); 26b5a588dfSShuo Chen //System.out.println(response); 27b5a588dfSShuo Chen } 28b5a588dfSShuo Chen long end = System.currentTimeMillis(); 29b5a588dfSShuo Chen System.err.println(end-start); 30b5a588dfSShuo Chen System.err.println(N*1000L/(end-start)); 31b5a588dfSShuo Chen // System.out.println(response); 32b5a588dfSShuo Chen channel.disconnect(); 33b5a588dfSShuo Chen client.stop(); 34b5a588dfSShuo Chen } 35b5a588dfSShuo Chen 36b5a588dfSShuo Chen} 37