HADOOP_PRC 逃离我推掉我的手 2022-07-15 05:10 73阅读 0赞 服务 public interface MyBiz extends VersionedProtocol { long PROTOCOL_VERSION = 12321443L; String hello(String name); } public class MyBizImpl implements MyBiz { @Override public long getProtocolVersion(String arg0, long arg1) throws IOException { return PROTOCOL_VERSION; } @Override public String hello(String name) { System. out.println( "invoked"); return "hello " + name; } } 服务器 public class MyServer { public static final String SERVER_ADDRESS = "localhost"; public static final int SERVER_PORT = 12345; public static void main(String[] args) throws IOException { Server server = RPC. getServer(new MyBizImpl(), SERVER_ADDRESS, SERVER_PORT , new Configuration()); server.start(); } } 客户端 public class MyClient { public static void main(String[] args) throws IOException { MyBiz proxy = (MyBiz) RPC. getProxy(MyBiz.class, MyBiz.PROTOCOL_VERSION, new InetSocketAddress(MyServer. SERVER_ADDRESS,MyServer.SERVER_PORT), new Configuration()); String result = proxy.hello( "5"); System. out.println(result); RPC.stopProxy(proxy); } }
还没有评论,来说两句吧...