1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
|
package tests.netsvcs.Naming;
import java.io.*;
import java.net.*;
import java.util.*;
import JACE.OS.*;
import JACE.Connection.*;
import JACE.SOCK_SAP.*;
import netsvcs.Naming.*;
public class ClientTest
{
void print_usage_and_die ()
{
System.out.println ("Usage: ClientTest <hostname> [<port>]");
System.exit (0);
}
public SOCKStream init (SOCKStream socket, String hostname, int port)
{
try
{
SOCKConnector sc = new SOCKConnector(socket, hostname, port);
}
catch (UnknownHostException e)
{
ACE.ERROR (e);
System.exit(0);
}
catch (SocketException e)
{
ACE.ERROR ("Connection refused");
System.exit(0);
}
catch (IOException e)
{
ACE.ERROR (e);
System.exit(0);
}
return socket;
}
public static void main (String [] args)
{
SOCKStream socket;
int port = ACE.DEFAULT_SERVER_PORT;
ClientTest clientTest = new ClientTest ();
if (args.length == 2)
{
try
{
port = Integer.parseInt (args[1]);
}
catch (NumberFormatException e)
{
clientTest.print_usage_and_die ();
}
}
System.out.println("Trying to open port " + port + " on " + args[0]);
socket = clientTest.init (new SOCKStream(), args[0], port);
NameProxy proxy = new NameProxy(socket);
System.out.println("---- Beginning tests ----");
try {
System.out.println("Binding (five, six, seven): " + proxy.bind("five", "six", "seven"));
System.out.println("Binding (filth, rat, eats): " + proxy.bind("filth", "rat", "eats"));
Vector res = proxy.resolve("five");
System.out.println("Resolve (five) : " + (String)res.elementAt(1) + " "
+ (String)res.elementAt(2));
System.out.println("Binding (fish, words, him): " + proxy.bind("fish", "words", "him"));
System.out.println("Unbind (five, six, seven): " + proxy.unbind("five"));
res = proxy.resolve("five");
System.out.println("Resolve (five) : " + (String)res.elementAt(1) + " "
+ (String)res.elementAt(2));
System.out.println("Binding (fiction, us, you): " + proxy.bind("fiction", "us", "you"));
System.out.println("\nGetting all records whose names begin with fi:\n");
Vector res2 = proxy.listNameEntries("fi");
Enumeration iter = res2.elements();
while (iter.hasMoreElements()) {
Vector res3 = (Vector)(iter.nextElement());
System.out.println((String)res3.elementAt(0) + "\t" + (String)res3.elementAt(1)
+ "\t" + (String)res3.elementAt(2));
}
} catch (IOException e)
{
ACE.ERROR("" + e);
}
finally
{
try {
socket.close();
} catch (IOException e) {
ACE.ERROR("" + e);
}
}
}
};
|