public interface MyService {
String doSomething();
}
public class MyServiceImpl implements MyService {
public String doSomething() {
return "This is the result of doing something";
}
}
public class Server {
public static void main(String[] args) {
Eventloop eventloop = Eventloop.create().withCurrentThread();
RpcServer rpcServer = RpcServer.create(eventloop)
.withListenAddress(new InetSocketAddress(9000))
.withMessageTypes(MyService.class)
.withHandler(MyService.class, new MyServiceImpl());
rpcServer.listen();
eventloop.run();
}
}
public class Client {
public static void main(String[] args) {
Eventloop eventloop = Eventloop.create().withCurrentThread();
RpcClient rpcClient = RpcClient.create(eventloop)
.withConnectAddress(new InetSocketAddress("localhost", 9000))
.withMessageTypes(MyService.class);
MyService myService = rpcClient.createStub(MyService.class);
String result = myService.doSomething();
System.out.println(result);
eventloop.run();
}
}