forked from LupusNobilis/java-org.hwo
60 lines
933 B
Java
60 lines
933 B
Java
package org.hwo.rpc.simple;
|
|
|
|
import java.net.InetAddress;
|
|
|
|
public class SimpleRPCTest {
|
|
|
|
interface TestInterface {
|
|
|
|
public int add(Integer a,Integer b);
|
|
|
|
}
|
|
|
|
static class TestClass implements TestInterface{
|
|
|
|
public TestClass(){
|
|
}
|
|
|
|
@Override
|
|
public int add(Integer a, Integer b) {
|
|
return a + b;
|
|
}
|
|
}
|
|
|
|
|
|
public static void main(String[] args) {
|
|
|
|
|
|
|
|
try {
|
|
|
|
SimpleRPCServer server = new SimpleRPCServer(InetAddress.getLocalHost(),44352);
|
|
SimpleRPCService service = new SimpleRPCService(InetAddress.getLocalHost(), 44352);
|
|
|
|
TestClass tc = new TestClass();
|
|
server.registerObject(TestInterface.class, tc);
|
|
|
|
server.start();
|
|
|
|
TestInterface ti = service.createProxy(TestInterface.class);
|
|
|
|
System.err.println("ti.add(): " + ti.add(4, 5));
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
// TODO Auto-generated catch block
|
|
e.printStackTrace();
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|