21
|
1
|
|
2 /*
|
|
3 * @(#)TestPSXLinda.java 1.1 06/04/01
|
|
4 *
|
|
5 * Copyright 2006 Shinji KONO
|
|
6 *
|
|
7
|
|
8 Test PSX Lidna
|
|
9
|
|
10 */
|
|
11
|
|
12 package fdl.test;
|
|
13
|
|
14 import java.io.IOException;
|
22
|
15 import java.net.InetAddress;
|
|
16 import java.net.InetSocketAddress;
|
|
17 import java.net.UnknownHostException;
|
21
|
18 import java.nio.ByteBuffer;
|
|
19
|
|
20 import fdl.FederatedLinda;
|
66
|
21 import fdl.PSX;
|
25
|
22 import fdl.PSXLinda;
|
21
|
23 import fdl.PSXReply;
|
|
24
|
|
25
|
|
26 /**
|
|
27 * PSXLinda stream
|
|
28 *
|
|
29 * @author Shinji Kono
|
|
30 *
|
53
|
31 * @param localhost The host to connect to
|
|
32 * @param Port The port to connect to at the host
|
21
|
33
|
|
34 */
|
|
35
|
|
36
|
|
37 class TestPSXLinda {
|
23
|
38 static int id;
|
|
39 public static void main (String args[]) {
|
|
40
|
|
41 FederatedLinda fdl;
|
25
|
42 PSXLinda psx;
|
23
|
43 String host;
|
|
44 int port = 10000;
|
|
45 PSXReply r;
|
|
46 InetSocketAddress localAddress;
|
21
|
47
|
22
|
48
|
23
|
49 try {
|
|
50 localAddress = new InetSocketAddress(InetAddress.getLocalHost(), port);
|
|
51 host = localAddress.getHostName();
|
|
52 } catch (UnknownHostException e) {
|
|
53 host = "localhost";
|
|
54 }
|
|
55
|
|
56 try {
|
|
57 fdl = FederatedLinda.init();
|
|
58 psx = fdl.open(host,port);
|
|
59 r = psx.in(65535);
|
|
60 fdl.sync(1);
|
|
61 System.out.println("Connected.");
|
21
|
62
|
23
|
63 ByteBuffer data = ByteBuffer.allocate(10);
|
|
64 data.putInt(10);
|
|
65 data.flip();
|
|
66
|
|
67 psx.out(1,data);
|
21
|
68
|
23
|
69 int cnt=0;
|
|
70 while(!r.ready()) {
|
|
71 // psx.sync(1000);
|
97
|
72 psx.sync(0);
|
23
|
73 System.out.println("Waiting...."+(cnt++));
|
|
74 }
|
25
|
75
|
|
76 print_id(r);
|
26
|
77
|
|
78 data.clear();
|
|
79 psx.out(PSX.META_STOP, data);
|
97
|
80 psx.sync(0);
|
26
|
81
|
25
|
82 } catch (IOException e) {
|
|
83 System.err.println("Communication failure.");
|
23
|
84 }
|
21
|
85 }
|
|
86
|
93
|
87 public static void print_id (PSXReply ans) throws IOException {
|
23
|
88 ByteBuffer r = ans.getData();
|
|
89 System.out.print("ID = ");
|
93
|
90 System.out.write(r.array());
|
23
|
91 }
|
21
|
92 }
|
|
93
|