<dependency> <groupId>com.example</groupId> <artifactId>core-remote-procedure-call</artifactId> <version>1.0.0</version> </dependency> public interface RemoteService { String sayHello(String name); } public class RemoteServiceImpl implements RemoteService { public String sayHello(String name) { return "Hello, " + name + "!"; } } public class RemoteServiceServer { public static void main(String[] args) { RemoteService remoteService = new RemoteServiceImpl(); try { CoreRPCServer server = new CoreRPCServer(); server.bind(remoteService, 8080); System.out.println("Remote service started on port 8080."); } catch (Exception e) { e.printStackTrace(); } } } public class RemoteServiceClient { public static void main(String[] args) { try { CoreRPCClient client = new CoreRPCClient("localhost", 8080); RemoteService remoteService = client.createProxy(RemoteService.class); String response = remoteService.sayHello("Alice"); System.out.println(response); } catch (Exception e) { e.printStackTrace(); } } }


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