1 package org.sourceforge.jemmrpc.example.echo;
2
3 import java.io.IOException;
4
5 import org.apache.log4j.Logger;
6 import org.sourceforge.jemmrpc.client.RPCClient;
7
8
9
10
11 public class EchoClient implements EchoClientIF
12 {
13 protected static final Logger logger = Logger.getLogger(EchoClient.class);
14
15 String hostname;
16
17 int port;
18
19 RPCClient client;
20
21 EchoServerIF echoServerIF;
22
23
24
25
26
27
28
29
30 public EchoClient(String hostname, int port) throws IOException
31 {
32 this.hostname = hostname;
33 this.port = port;
34 client = new RPCClient(hostname, port);
35 client.registerIF(EchoClientIF.class, this);
36 client.connect();
37 echoServerIF = (EchoServerIF) client.getServerIF(EchoServerIF.class);
38 }
39
40
41
42
43
44
45
46 public String sendEcho(String message)
47 {
48 logger.debug("Synchronous client message send");
49 return echoServerIF.echo(message);
50 }
51
52
53
54
55
56
57 public void sendAsyncEcho(String message)
58 {
59 logger.debug("Async client message send");
60 echoServerIF.asyncEcho(message);
61 }
62
63
64
65
66
67
68 public void asyncEchoReply(String reply)
69 {
70 logger.info("Got async echo reply: " + reply);
71 }
72
73
74
75
76 public void close()
77 {
78 client.close();
79 }
80 }