首先让我们从 Hello World 开始。
服务器
package hprose.tcphelloexam;import hprose.server.HproseTcpServer;public class TCPHelloServer { public static String hello(String name) { return "Hello " + name + "!"; } public static void main(String[] args) throws Exception { HproseTcpServer server = new HproseTcpServer("tcp://localhost:4321"); server.add("hello", TCPHelloServer.class); server.start(); System.out.println("START"); System.in.read(); server.stop(); System.out.println("STOP"); }}
客户端
package hprose.tcphelloexam;import hprose.client.HproseTcpClient;interface IHello { String hello(String name);}public class TCPHelloClient { public static void main(String[] args) throws Throwable { System.out.println("START"); HproseTcpClient client = new HproseTcpClient("tcp://localhost:4321"); IHello helloClient = client.useService(IHello.class); System.out.println(helloClient.hello("World")); System.out.println("END"); }}