-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClientTest.java
More file actions
285 lines (227 loc) · 9.27 KB
/
ClientTest.java
File metadata and controls
285 lines (227 loc) · 9.27 KB
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
/*
ClientTest.java
Written by George Brinzea
Used for testing and understanding client-side Java networking code
This code is not a part of the final project build
*/
package com.purdue.LawsonNavigator;
import java.io.*;
import java.net.*;
import java.util.*;
import javax.imageio.ImageIO;
import java.awt.Image;
import java.awt.image.BufferedImage;
import javax.swing.ImageIcon;
import java.awt.Graphics2D;
public class ClientTest {
public static void main(String[] args) throws IOException {
Socket kkSocket = null;
PrintWriter out = null;
BufferedReader in = null;
ObjectInputStream ois = null;
ObjectOutputStream oos = null;
InputStream is = null;
//The IP address of moore01
byte[] IP = new byte[4];
IP[0] = (byte) 128;
IP[1] = (byte) 10;
IP[2] = (byte) 12;
IP[3] = (byte) 131;
try {
kkSocket = new Socket(InetAddress.getByAddress(IP), 4444);
out = new PrintWriter(kkSocket.getOutputStream(), true);
in = new BufferedReader(new InputStreamReader(kkSocket.getInputStream()));
ois = new ObjectInputStream(kkSocket.getInputStream());
oos = new ObjectOutputStream(kkSocket.getOutputStream());
is = kkSocket.getInputStream();
} catch (UnknownHostException e) {
System.err.println("Cannot find the host.");
System.exit(1);
} catch (IOException e) {
System.err.println("Couldn't get I/O for the connection to the host.");
System.exit(1);
}
BufferedReader stdIn = new BufferedReader(new InputStreamReader(System.in));
String fromServer;
String fromUser;
/*fromUser = "getID";
out.println(fromUser);
fromServer = in.readLine();
System.out.println("Connection #" + fromServer + " established");
System.out.println();*/
Data data = null;
ImageIcon image = null;
Image image2;
File file = null;
while(true){
System.out.print("Enter input: ");
fromUser = stdIn.readLine();
if(fromUser.equals("exit")){
out.println(fromUser);
break;
}else if(fromUser.equals("Image")){
//UserInput ui = new UserInput(Transport.STAIRS, Floor.FIRST, Display.MAP, ConvertAndDraw.yArraytoGPS(60), ConvertAndDraw.xArraytoGPS(23), "1142", null, null);
UserInput ui = new UserInput(Transport.STAIRS, Floor.BASEMENT, Display.MAP, ConvertAndDraw.yArraytoGPS(52), ConvertAndDraw.xArraytoGPS(5), "B160", null, null);
try{
oos.writeObject(ui);
}catch(Exception e){
System.err.println("Error in sending ui data");
e.printStackTrace();
System.exit(1);
}
ArrayList<String> textDirections1 = new ArrayList<String>();
ArrayList<Byte> images1 = new ArrayList<Byte>();
ArrayList<Byte> images11 = new ArrayList<Byte>();
ArrayList<Byte> images12 = new ArrayList<Byte>();
ArrayList<Byte> images13 = new ArrayList<Byte>();
ArrayList<Byte> images14 = new ArrayList<Byte>();
ArrayList<Byte> images15 = new ArrayList<Byte>();
ArrayList<Point> points1 = new ArrayList<Point>();
ArrayList<String> textDirections2 = new ArrayList<String>();
ArrayList<Byte> images2 = new ArrayList<Byte>();
ArrayList<Byte> images21 = new ArrayList<Byte>();
ArrayList<Byte> images22 = new ArrayList<Byte>();
ArrayList<Byte> images23 = new ArrayList<Byte>();
ArrayList<Byte> images24 = new ArrayList<Byte>();
ArrayList<Byte> images25 = new ArrayList<Byte>();
ArrayList<Point> points2 = new ArrayList<Point>();
try{
//images1 = (ArrayList<Byte>) ois.readObject();
//images11 = (ArrayList<Byte>) ois.readObject();
//images12 = (ArrayList<Byte>) ois.readObject();
//images13 = (ArrayList<Byte>) ois.readObject();
//images14 = (ArrayList<Byte>) ois.readObject();
//images15 = (ArrayList<Byte>) ois.readObject();
byte temp = (byte) is.read();
while(temp != -1){
images1.add(new Byte(temp));
temp = (byte) is.read();
}
textDirections1 = (ArrayList<String>) ois.readObject();
points1 = (ArrayList<Point>) ois.readObject();
//images2 = (ArrayList<Byte>) ois.readObject();
//images21 = (ArrayList<Byte>) ois.readObject();
//images22 = (ArrayList<Byte>) ois.readObject();
//images23 = (ArrayList<Byte>) ois.readObject();
//images24 = (ArrayList<Byte>) ois.readObject();
//images25 = (ArrayList<Byte>) ois.readObject();
temp = (byte) is.read();
while(temp != -1){
images2.add(new Byte(temp));
temp = (byte) is.read();
}
textDirections2 = (ArrayList<String>) ois.readObject();
points2 = (ArrayList<Point>) ois.readObject();
}catch(Exception e){
System.err.println("Error in recieving data from the server");
e.printStackTrace();
System.exit(1);
}
/*Byte images1Array[] = new Byte[images1.size()];
for(int i = 0; i < images1Array.length; i++){
images1Array[i] = images1.get(i);
System.out.print(images1Array[i] + ", ");
}*/
/*byte images1Array[] = new byte[images11.size() + images12.size() + images13.size() + images14.size() + images15.size()];
int j = 0;
for(int i = 0; i < images11.size(); i++){
images1Array[j] = images11.get(i).byteValue();
j++;
}
for(int i = 0; i < images12.size(); i++){
images1Array[j] = images12.get(i).byteValue();
j++;
}
for(int i = 0; i < images13.size(); i++){
images1Array[j] = images13.get(i).byteValue();
j++;
}
for(int i = 0; i < images14.size(); i++){
images1Array[j] = images14.get(i).byteValue();
j++;
}
for(int i = 0; i < images15.size(); i++){
images1Array[j] = images15.get(i).byteValue();
j++;
}
for(int i = 0; i < images1Array.length; i++){
System.out.print(images1Array[i] + ", ");
}*/
byte images1Array[] = new byte[images1.size()];
for(int i = 0; i < images1Array.length; i++){
images1Array[i] = images1.get(i).byteValue();
System.out.print(images1Array[i] + ", ");
}
System.out.println("\nCompleted");
System.exit(0);
}else if(fromUser.equals("Text")){
//UserInput ui = new UserInput(Transport.STAIRS, Floor.FIRST, Display.TEXTSPEECH, ConvertAndDraw.yArraytoGPS(60), ConvertAndDraw.xArraytoGPS(23), "1142", null, null);
UserInput ui = new UserInput(Transport.STAIRS, Floor.BASEMENT, Display.TEXTSPEECH, ConvertAndDraw.yArraytoGPS(52), ConvertAndDraw.xArraytoGPS(5), "B160", null, null);
try{
oos.writeObject(ui);
}catch(Exception e){
System.err.println("Error in sending ui data");
e.printStackTrace();
System.exit(1);
}
ArrayList<String> textDirections1 = new ArrayList<String>();
ArrayList<Byte> images1 = new ArrayList<Byte>();
ArrayList<Byte> images11 = new ArrayList<Byte>();
ArrayList<Byte> images12 = new ArrayList<Byte>();
ArrayList<Byte> images13 = new ArrayList<Byte>();
ArrayList<Byte> images14 = new ArrayList<Byte>();
ArrayList<Byte> images15 = new ArrayList<Byte>();
ArrayList<Point> points1 = new ArrayList<Point>();
ArrayList<String> textDirections2 = new ArrayList<String>();
ArrayList<Byte> images2 = new ArrayList<Byte>();
ArrayList<Byte> images21 = new ArrayList<Byte>();
ArrayList<Byte> images22 = new ArrayList<Byte>();
ArrayList<Byte> images23 = new ArrayList<Byte>();
ArrayList<Byte> images24 = new ArrayList<Byte>();
ArrayList<Byte> images25 = new ArrayList<Byte>();
ArrayList<Point> points2 = new ArrayList<Point>();
try{
//images1 = (ArrayList<Byte>) ois.readObject();
images11 = (ArrayList<Byte>) ois.readObject();
images12 = (ArrayList<Byte>) ois.readObject();
images13 = (ArrayList<Byte>) ois.readObject();
images14 = (ArrayList<Byte>) ois.readObject();
images15 = (ArrayList<Byte>) ois.readObject();
textDirections1 = (ArrayList<String>) ois.readObject();
points1 = (ArrayList<Point>) ois.readObject();
//images2 = (ArrayList<Byte>) ois.readObject();
images21 = (ArrayList<Byte>) ois.readObject();
images22 = (ArrayList<Byte>) ois.readObject();
images23 = (ArrayList<Byte>) ois.readObject();
images24 = (ArrayList<Byte>) ois.readObject();
images25 = (ArrayList<Byte>) ois.readObject();
textDirections2 = (ArrayList<String>) ois.readObject();
points2 = (ArrayList<Point>) ois.readObject();
}catch(Exception e){
System.err.println("Error in recieving data from the server");
e.printStackTrace();
System.exit(1);
}
for(int i = 0; i < textDirections1.size(); i++){
System.out.println(textDirections1.get(i));
}
System.out.println();
for(int i = 0; i < points1.size(); i++){
System.out.println(points1.get(i).getx() + " " + points1.get(i).gety());
}
System.out.println("\nCompleted");
System.exit(0);
}else{
out.println(fromUser);
fromServer = in.readLine();
System.out.println("Output from server: " + fromServer);
System.out.println();
}
}
ois.close();
in.close();
out.close();
stdIn.close();
kkSocket.close();
}
}