public interface HelloService { String sayHello(String name); } public class HelloServiceImpl implements HelloService { public String sayHello(String name) { return "Hello, " + name + "!"; } } public class ServerConfig { public static void main(String[] args) { HelloService helloService = new HelloServiceImpl(); RpcServer server = new RpcServer(); server.publish(helloService, 8080); server.start(); } } public class ClientConfig { public static void main(String[] args) { RpcClient client = new RpcClient(); HelloService helloService = client.createProxy(HelloService.class, "localhost", 8080); String result = helloService.sayHello("Alice"); System.out.println(result); } }


上一篇:
下一篇:
切换中文