public interface RemoteService { String sayHello(String name); } public class RemoteServiceImpl implements RemoteService { @Override public String sayHello(String name) { return "Hello, " + name + "!"; } } public class Server { public static void main(String[] args) { RemoteService remoteService = new RemoteServiceImpl(); RemoteInvoker.registerService(RemoteService.class, remoteService); RemoteInvoker.startServer(); } } public class Client { public static void main(String[] args) { RemoteService remoteService = RemoteInvoker.createClient(RemoteService.class, "localhost", 8080); String result = remoteService.sayHello("John"); } }


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