60
|
1 package myVncClient;
|
65
|
2
|
60
|
3 import java.awt.*;
|
|
4 import java.awt.event.*;
|
|
5 import java.io.*;
|
|
6 import java.net.*;
|
74
|
7 import java.nio.ByteBuffer;
|
67
|
8 import java.util.Random;
|
60
|
9
|
|
10 import myVncClient.AcceptThread;
|
|
11 import myVncClient.OptionsNoFrame;
|
|
12
|
69
|
13 public class CuiMyVncClient implements InterfaceForViewer {
|
65
|
14
|
|
15
|
60
|
16 String[] mainArgs;
|
|
17 String username;
|
65
|
18
|
60
|
19 // RfbProto rfb;
|
|
20 MyRfbProto rfb;
|
|
21 Thread rfbThread;
|
|
22 Thread accThread;
|
|
23 Thread clientThread;
|
|
24
|
|
25 Frame vncFrame;
|
|
26 Container vncContainer;
|
|
27 ScrollPane desktopScrollPane;
|
|
28 GridBagLayout gridbag;
|
|
29 ButtonPanel buttonPanel;
|
|
30 Label connStatusLabel;
|
|
31 CuiVncCanvas vc;
|
65
|
32 // OptionsFrame options;
|
60
|
33 OptionsNoFrame options;
|
|
34 ClipboardFrame clipboard;
|
|
35 RecordingFrame rec;
|
|
36
|
|
37 // Control session recording.
|
|
38 Object recordingSync;
|
|
39 String sessionFileName;
|
|
40 boolean recordingActive;
|
|
41 boolean recordingStatusChanged;
|
|
42 String cursorUpdatesDef;
|
|
43 String eightBitColorsDef;
|
|
44
|
|
45 // Variables read from parameter values.
|
|
46 String socketFactory;
|
|
47 String host;
|
|
48 int port;
|
|
49 String passwordParam;
|
|
50 boolean showControls;
|
|
51 boolean offerRelogin;
|
|
52 boolean showOfflineDesktop;
|
|
53 int deferScreenUpdates;
|
|
54 int deferCursorUpdates;
|
|
55 int deferUpdateRequests;
|
|
56 int debugStatsExcludeUpdates;
|
|
57 int debugStatsMeasureUpdates;
|
|
58
|
|
59 private static final long serialVersionUID = 1L;
|
|
60 boolean inAnApplet = true;
|
|
61 boolean inSeparateFrame = false;
|
|
62 Socket clientSocket = null;
|
|
63 String parent, treenum;
|
|
64 private String leaderflag;
|
|
65 boolean runflag = false;
|
69
|
66 boolean first = true;
|
60
|
67
|
79
|
68 EchoClient echoValue;
|
|
69 int echoPort;
|
80
|
70 String pHost;
|
|
71
|
|
72 public static void main(String[] argv) {
|
|
73 CuiMyVncClient v = new CuiMyVncClient();
|
|
74 v.echoValue = null;
|
|
75 v.runClient(argv, v);
|
|
76
|
|
77 }
|
|
78
|
|
79 private void runClient(String[] argv, CuiMyVncClient v) {
|
|
80 mainArgs = argv;
|
|
81
|
|
82 if (mainArgs.length > 0)
|
|
83 pHost = mainArgs[0];
|
|
84 else
|
|
85 pHost = "cls080.ie.u-ryukyu.ac.jp";
|
|
86 if (mainArgs.length > 1)
|
|
87 port = Integer.parseInt(mainArgs[1]);
|
|
88 else
|
|
89 port = 5999;
|
|
90
|
|
91 v.init();
|
|
92 v.start_threads();
|
|
93
|
|
94 }
|
79
|
95
|
74
|
96
|
65
|
97 void checkArgs(String[] argv) {
|
|
98 if (argv.length > 3) {
|
|
99 username = argv[3];
|
|
100 } else if (argv.length < 2) {
|
60
|
101 System.out.println("Please enter argv");
|
|
102 System.out.println("hostname(IPaddress) port password");
|
|
103 System.exit(0);
|
65
|
104 } else {
|
60
|
105 username = argv[0];
|
|
106 }
|
|
107 }
|
65
|
108
|
60
|
109 //
|
|
110 // init()
|
|
111 //
|
|
112
|
74
|
113 public void init() {
|
70
|
114
|
69
|
115 Random rnd = new Random();
|
|
116 long ran = rnd.nextInt(5000);
|
|
117 try {
|
|
118 Thread.sleep(ran);
|
70
|
119 } catch (InterruptedException e) {
|
|
120 e.printStackTrace();
|
69
|
121 }
|
74
|
122
|
|
123 readParameters();
|
|
124 //readParameters(value);
|
60
|
125
|
|
126 options = new OptionsNoFrame(this);
|
|
127 recordingSync = new Object();
|
|
128
|
|
129 sessionFileName = null;
|
|
130 recordingActive = false;
|
|
131 recordingStatusChanged = false;
|
|
132 cursorUpdatesDef = null;
|
|
133 eightBitColorsDef = null;
|
|
134
|
67
|
135 /*
|
|
136 * try { connectAndAuthenticate(); } catch (NoRouteToHostException e) {
|
|
137 * fatalError("Network error: no route to server: " + host, e); } catch
|
|
138 * (UnknownHostException e) {
|
|
139 * fatalError("Network error: server name unknown: " + host, e); } catch
|
|
140 * (ConnectException e) {
|
|
141 * fatalError("Network error: could not connect to server: " + host +
|
|
142 * ":" + port, e); } catch (Exception e) { }
|
|
143 */
|
60
|
144 rfbThread = new Thread(this);
|
|
145
|
|
146 }
|
|
147
|
|
148 //
|
|
149 // run() - executed by the rfbThread to deal with the RFB socket.
|
|
150 //
|
|
151
|
65
|
152 public void start_threads() {
|
60
|
153 rfbThread.start();
|
|
154 }
|
65
|
155
|
60
|
156 public void run() {
|
|
157
|
|
158 try {
|
69
|
159 if (first) {
|
|
160 connectAndAuthenticate();
|
70
|
161 accThread = new Thread(new AcceptThread(rfb, 5999));
|
|
162 accThread.start();
|
69
|
163 first = false;
|
|
164 }else {
|
|
165 reConnectAndAuthenticate();
|
|
166 }
|
60
|
167 doProtocolInitialisation();
|
67
|
168
|
60
|
169 vc = new CuiVncCanvas(this, 0, 0);
|
|
170 vc.updateFramebufferSize();
|
65
|
171
|
67
|
172 } catch (IOException e) {
|
70
|
173
|
67
|
174 System.out.println("Socket error");
|
|
175 // parent no find
|
|
176 Random rnd = new Random();
|
|
177 long ran = rnd.nextInt(5000) + 5000;
|
|
178 System.out.println(ran);
|
|
179 // 親がいない場合の処理はここに書く!!!!
|
|
180 /**
|
|
181 * this while reconnection
|
|
182 */
|
|
183
|
|
184 int counter = 0;
|
69
|
185
|
67
|
186 /*
|
69
|
187 vncFrame.setVisible(false);
|
|
188 vncFrame.dispose();
|
|
189 */
|
67
|
190 while (true) {
|
|
191 /**
|
|
192 * if my last node case reconnectoion stop
|
|
193 */
|
|
194
|
79
|
195 echoValue = new EchoClient(echoValue, this);
|
67
|
196 try {
|
|
197 Thread.sleep(ran);
|
|
198 } catch (InterruptedException e1) {
|
|
199 e1.printStackTrace();
|
|
200 }
|
|
201
|
|
202 if (counter >= 3) {
|
79
|
203 echoValue.openport();
|
|
204 echoValue.notfoundParent();
|
67
|
205 }
|
|
206
|
79
|
207 echoValue.openport();
|
67
|
208 // runflag = echo.losthost();
|
79
|
209 if (echoValue.losthost()) {
|
71
|
210 break;
|
67
|
211 }
|
|
212 counter++;
|
|
213 }
|
|
214 // System.exit(0);
|
69
|
215 }catch (Exception e) {
|
67
|
216 System.out.println(e);
|
|
217 System.exit(0);
|
|
218 }
|
69
|
219 try{
|
|
220
|
60
|
221 processNormalProtocol();// main loop
|
|
222
|
|
223 } catch (NoRouteToHostException e) {
|
|
224 fatalError("Network error: no route to server: " + host, e);
|
|
225 } catch (UnknownHostException e) {
|
|
226 fatalError("Network error: server name unknown: " + host, e);
|
|
227 } catch (ConnectException e) {
|
|
228 fatalError("Network error: could not connect to server: " + host
|
|
229 + ":" + port, e);
|
|
230 } catch (EOFException e) {
|
65
|
231
|
|
232 if (leaderflag != null) {
|
|
233 while (true) {
|
79
|
234 echoValue = new EchoClient(echoValue, this);
|
|
235 echoValue.openport();
|
65
|
236 // runflag = echo.losthost();
|
79
|
237 if (echoValue.losthost()) {
|
65
|
238 break;
|
|
239 }
|
60
|
240 }
|
|
241 } else {
|
65
|
242 if (showOfflineDesktop) {
|
|
243 e.printStackTrace();
|
|
244 System.out
|
|
245 .println("Network error: remote side closed connection");
|
|
246 if (vc != null) {
|
|
247 vc.enableInput(false);
|
|
248 }
|
|
249 if (rfb != null && !rfb.closed())
|
|
250 rfb.close();
|
|
251 if (showControls && buttonPanel != null) {
|
|
252 buttonPanel.disableButtonsOnDisconnect();
|
|
253 }
|
|
254 } else {
|
67
|
255 fatalError("Network error: remote side closed connection",
|
|
256 e);
|
65
|
257 }
|
60
|
258 }
|
|
259 } catch (IOException e) {
|
|
260 String str = e.getMessage();
|
|
261 if (str != null && str.length() != 0) {
|
|
262 fatalError("Network Error: " + str, e);
|
|
263 } else {
|
|
264 fatalError(e.toString(), e);
|
|
265 }
|
65
|
266 } catch (Exception e) {
|
60
|
267 String str = e.getMessage();
|
|
268 if (str != null && str.length() != 0) {
|
|
269 fatalError("Error: " + str, e);
|
|
270 } else {
|
|
271 fatalError(e.toString(), e);
|
|
272 }
|
|
273 }
|
|
274
|
|
275 }
|
|
276
|
|
277 //
|
|
278 // Process RFB socket messages.
|
|
279 // If the rfbThread is being stopped, ignore any exceptions,
|
|
280 // otherwise rethrow the exception so it can be handled.
|
|
281 //
|
|
282
|
|
283 void processNormalProtocol() throws Exception {
|
|
284 try {
|
|
285 vc.processNormalProtocol();// main loop
|
|
286 } catch (Exception e) {
|
|
287 if (rfbThread == null) {
|
|
288 System.out.println("Ignoring RFB socket exceptions"
|
|
289 + " because applet is stopping");
|
|
290 } else {
|
|
291 throw e;
|
|
292 }
|
|
293 }
|
|
294 }
|
|
295
|
|
296 //
|
|
297 // Connect to the RFB server and authenticate the user.
|
|
298 //
|
|
299
|
|
300 void connectAndAuthenticate() throws Exception {
|
|
301 showConnectionStatus("Initializing...");
|
|
302
|
|
303 showConnectionStatus("Connecting to " + host + ", port " + port + "...");
|
|
304
|
|
305 // rfb = new RfbProto(host, port, this);
|
80
|
306 rfb = new MyRfbProto(pHost, port);
|
65
|
307
|
60
|
308 showConnectionStatus("Connected to server");
|
|
309
|
|
310 rfb.readVersionMsg();
|
|
311 showConnectionStatus("RFB server supports protocol version "
|
|
312 + rfb.serverMajor + "." + rfb.serverMinor);
|
|
313
|
|
314 rfb.writeVersionMsg();
|
|
315 showConnectionStatus("Using RFB protocol version " + rfb.clientMajor
|
|
316 + "." + rfb.clientMinor);
|
|
317
|
80
|
318
|
74
|
319 if(rfb.serverMinor == 998) {
|
|
320 byte[] b = new byte[4];
|
|
321 b = rfb.readEchoPort();
|
79
|
322 echoPort = castByteInt(b);
|
76
|
323
|
80
|
324 InetAddress addr = InetAddress.getByName(pHost);
|
76
|
325 String h = new String(addr.getHostAddress());
|
|
326
|
79
|
327 getParentName();
|
76
|
328 if(!(h.equals(host))) {
|
74
|
329 rfb.changeParent(host, port);
|
|
330 rfb.readVersionMsg();
|
76
|
331 rfb.writeVersionMsg();
|
74
|
332 }
|
|
333 }
|
|
334
|
|
335
|
60
|
336 int secType = rfb.negotiateSecurity();
|
|
337 int authType;
|
|
338 if (secType == RfbProto.SecTypeTight) {
|
|
339 showConnectionStatus("Enabling TightVNC protocol extensions");
|
|
340 rfb.setupTunneling();
|
|
341 authType = rfb.negotiateAuthenticationTight();
|
|
342 } else {
|
|
343 authType = secType;
|
|
344 }
|
|
345
|
|
346 switch (authType) {
|
|
347 case RfbProto.AuthNone:
|
|
348 showConnectionStatus("No authentication needed");
|
|
349 rfb.authenticateNone();
|
|
350 break;
|
|
351 case RfbProto.AuthVNC:
|
|
352 showConnectionStatus("Performing standard VNC authentication");
|
|
353 if (passwordParam != null) {
|
|
354 rfb.authenticateVNC(passwordParam);
|
|
355 } else {
|
|
356 String pw = askPassword();
|
|
357 rfb.authenticateVNC(pw);
|
|
358 }
|
|
359 break;
|
|
360 default:
|
|
361 throw new Exception("Unknown authentication scheme " + authType);
|
|
362 }
|
|
363 }
|
|
364
|
70
|
365
|
|
366
|
69
|
367 void reConnectAndAuthenticate() throws Exception {
|
|
368 showConnectionStatus("Initializing...");
|
|
369
|
|
370 showConnectionStatus("Connecting to " + host + ", port " + port + "...");
|
|
371
|
|
372 rfb.changeParent(host, port);
|
|
373
|
|
374 showConnectionStatus("Connected to server");
|
|
375
|
|
376 rfb.readVersionMsg();
|
|
377 showConnectionStatus("RFB server supports protocol version "
|
|
378 + rfb.serverMajor + "." + rfb.serverMinor);
|
|
379
|
|
380 rfb.writeVersionMsg();
|
|
381 showConnectionStatus("Using RFB protocol version " + rfb.clientMajor
|
|
382 + "." + rfb.clientMinor);
|
|
383
|
79
|
384 if(rfb.serverMinor == 998) {
|
|
385 byte[] b = new byte[4];
|
|
386 b = rfb.readEchoPort();
|
|
387 echoPort = castByteInt(b);
|
|
388
|
|
389 String hs = host;
|
|
390 InetAddress addr = InetAddress.getByName(host);
|
|
391 String h = new String(addr.getHostAddress());
|
|
392
|
|
393 getParentName();
|
|
394 if(!(h.equals(host))) {
|
|
395 rfb.changeParent(host, port);
|
|
396 rfb.readVersionMsg();
|
|
397 rfb.writeVersionMsg();
|
|
398 }
|
|
399 }
|
|
400
|
|
401
|
69
|
402 int secType = rfb.negotiateSecurity();
|
|
403 int authType;
|
|
404 if (secType == RfbProto.SecTypeTight) {
|
|
405 showConnectionStatus("Enabling TightVNC protocol extensions");
|
|
406 rfb.setupTunneling();
|
|
407 authType = rfb.negotiateAuthenticationTight();
|
|
408 } else {
|
|
409 authType = secType;
|
|
410 }
|
|
411
|
|
412 switch (authType) {
|
|
413 case RfbProto.AuthNone:
|
|
414 showConnectionStatus("No authentication needed");
|
|
415 rfb.authenticateNone();
|
|
416 break;
|
|
417 case RfbProto.AuthVNC:
|
|
418 showConnectionStatus("Performing standard VNC authentication");
|
|
419 if (passwordParam != null) {
|
|
420 rfb.authenticateVNC(passwordParam);
|
|
421 } else {
|
|
422 String pw = askPassword();
|
|
423 rfb.authenticateVNC(pw);
|
|
424 }
|
|
425 break;
|
|
426 default:
|
|
427 throw new Exception("Unknown authentication scheme " + authType);
|
|
428 }
|
|
429 }
|
|
430
|
60
|
431 //
|
|
432 // Show a message describing the connection status.
|
|
433 // To hide the connection status label, use (msg == null).
|
|
434 //
|
|
435
|
|
436 void showConnectionStatus(String msg) {
|
|
437 System.out.println(msg);
|
|
438 }
|
|
439
|
|
440 //
|
|
441 // Show an authentication panel.
|
|
442 //
|
|
443
|
|
444 String askPassword() throws Exception {
|
|
445 /*
|
65
|
446 * showConnectionStatus(null); AuthPanel authPanel = new
|
|
447 * AuthPanel(this);
|
60
|
448 *
|
|
449 * GridBagConstraints gbc = new GridBagConstraints(); gbc.gridwidth =
|
|
450 * GridBagConstraints.REMAINDER; gbc.anchor =
|
|
451 * GridBagConstraints.NORTHWEST; gbc.weightx = 1.0; gbc.weighty = 1.0;
|
|
452 * gbc.ipadx = 100; gbc.ipady = 50; gridbag.setConstraints(authPanel,
|
|
453 * gbc); vncContainer.add(authPanel);
|
65
|
454 *
|
|
455 *
|
|
456 * authPanel.moveFocusToDefaultField(); vncContainer.remove(authPanel);
|
60
|
457 */
|
|
458 showConnectionStatus("ask password...");
|
|
459 String pw = mainArgs[2];
|
|
460 return pw;
|
|
461 }
|
|
462
|
|
463 //
|
|
464 // Do the rest of the protocol initialisation.
|
|
465 //
|
|
466
|
|
467 void doProtocolInitialisation() throws IOException {
|
|
468 rfb.writeClientInit();
|
|
469 rfb.readServerInit();
|
|
470
|
|
471 System.out.println("Desktop name is " + rfb.desktopName);
|
|
472 System.out.println("Desktop size is " + rfb.framebufferWidth + " x "
|
|
473 + rfb.framebufferHeight);
|
|
474
|
|
475 setEncodings();
|
|
476
|
65
|
477 // showConnectionStatus(null);
|
60
|
478 }
|
|
479
|
|
480 //
|
|
481 // Send current encoding list to the RFB server.
|
|
482 //
|
|
483
|
|
484 int[] encodingsSaved;
|
|
485 int nEncodingsSaved;
|
|
486
|
|
487 void setEncodings() {
|
|
488 setEncodings(false);
|
|
489 }
|
|
490
|
|
491 void autoSelectEncodings() {
|
|
492 setEncodings(true);
|
|
493 }
|
|
494
|
|
495 void setEncodings(boolean autoSelectOnly) {
|
|
496 if (options == null || rfb == null || !rfb.inNormalProtocol)
|
|
497 return;
|
|
498
|
|
499 int preferredEncoding = options.preferredEncoding;
|
|
500 if (preferredEncoding == -1) {
|
|
501 long kbitsPerSecond = rfb.kbitsPerSecond();
|
|
502 if (nEncodingsSaved < 1) {
|
|
503 // Choose Tight or ZRLE encoding for the very first update.
|
|
504 System.out.println("Using Tight/ZRLE encodings");
|
|
505 preferredEncoding = RfbProto.EncodingTight;
|
|
506 } else if (kbitsPerSecond > 2000
|
|
507 && encodingsSaved[0] != RfbProto.EncodingHextile) {
|
|
508 // Switch to Hextile if the connection speed is above 2Mbps.
|
|
509 System.out.println("Throughput " + kbitsPerSecond
|
|
510 + " kbit/s - changing to Hextile encoding");
|
|
511 preferredEncoding = RfbProto.EncodingHextile;
|
|
512 } else if (kbitsPerSecond < 1000
|
|
513 && encodingsSaved[0] != RfbProto.EncodingTight) {
|
|
514 // Switch to Tight/ZRLE if the connection speed is below 1Mbps.
|
|
515 System.out.println("Throughput " + kbitsPerSecond
|
|
516 + " kbit/s - changing to Tight/ZRLE encodings");
|
|
517 preferredEncoding = RfbProto.EncodingTight;
|
|
518 } else {
|
|
519 // Don't change the encoder.
|
|
520 if (autoSelectOnly)
|
|
521 return;
|
|
522 preferredEncoding = encodingsSaved[0];
|
|
523 }
|
|
524 } else {
|
|
525 // Auto encoder selection is not enabled.
|
|
526 if (autoSelectOnly)
|
|
527 return;
|
|
528 }
|
|
529
|
|
530 int[] encodings = new int[20];
|
|
531 int nEncodings = 0;
|
|
532
|
|
533 encodings[nEncodings++] = preferredEncoding;
|
|
534 if (options.useCopyRect) {
|
|
535 encodings[nEncodings++] = RfbProto.EncodingCopyRect;
|
|
536 }
|
|
537 if (preferredEncoding != RfbProto.EncodingTight) {
|
|
538 encodings[nEncodings++] = RfbProto.EncodingTight;
|
|
539 }
|
|
540 if (preferredEncoding != RfbProto.EncodingZRLE) {
|
|
541 encodings[nEncodings++] = RfbProto.EncodingZRLE;
|
|
542 }
|
|
543 if (preferredEncoding != RfbProto.EncodingHextile) {
|
|
544 encodings[nEncodings++] = RfbProto.EncodingHextile;
|
|
545 }
|
|
546 if (preferredEncoding != RfbProto.EncodingZlib) {
|
|
547 encodings[nEncodings++] = RfbProto.EncodingZlib;
|
|
548 }
|
|
549 /*
|
65
|
550 * if (preferredEncoding != RfbProto.EncodingCoRRE) {
|
|
551 * encodings[nEncodings++] = RfbProto.EncodingCoRRE; } if
|
|
552 * (preferredEncoding != RfbProto.EncodingRRE) { encodings[nEncodings++]
|
|
553 * = RfbProto.EncodingRRE; }
|
|
554 *
|
|
555 * if (options.compressLevel >= 0 && options.compressLevel <= 9) {
|
|
556 * encodings[nEncodings++] = RfbProto.EncodingCompressLevel0 +
|
|
557 * options.compressLevel; } if (options.jpegQuality >= 0 &&
|
|
558 * options.jpegQuality <= 9) { encodings[nEncodings++] =
|
|
559 * RfbProto.EncodingQualityLevel0 + options.jpegQuality; } if
|
|
560 * (options.requestCursorUpdates) { encodings[nEncodings++] =
|
|
561 * RfbProto.EncodingXCursor; encodings[nEncodings++] =
|
|
562 * RfbProto.EncodingRichCursor; if (!options.ignoreCursorUpdates)
|
|
563 * encodings[nEncodings++] = RfbProto.EncodingPointerPos; }
|
|
564 */
|
60
|
565
|
|
566 encodings[nEncodings++] = RfbProto.EncodingLastRect;
|
|
567 encodings[nEncodings++] = RfbProto.EncodingNewFBSize;
|
|
568
|
|
569 boolean encodingsWereChanged = false;
|
|
570 if (nEncodings != nEncodingsSaved) {
|
|
571 encodingsWereChanged = true;
|
|
572 } else {
|
|
573 for (int i = 0; i < nEncodings; i++) {
|
|
574 if (encodings[i] != encodingsSaved[i]) {
|
|
575 encodingsWereChanged = true;
|
|
576 break;
|
|
577 }
|
|
578 }
|
|
579 }
|
|
580
|
|
581 if (encodingsWereChanged) {
|
|
582 try {
|
65
|
583 // rfb.writeSetEncodings(encodings, nEncodings);
|
60
|
584 if (vc != null) {
|
|
585 vc.softCursorFree();
|
|
586 }
|
|
587 } catch (Exception e) {
|
|
588 e.printStackTrace();
|
|
589 }
|
|
590 encodingsSaved = encodings;
|
|
591 nEncodingsSaved = nEncodings;
|
|
592 }
|
|
593 }
|
|
594
|
|
595 //
|
|
596 // setCutText() - send the given cut text to the RFB server.
|
|
597 //
|
|
598
|
|
599 void setCutText(String text) {
|
|
600 try {
|
|
601 if (rfb != null && rfb.inNormalProtocol) {
|
|
602 rfb.writeClientCutText(text);
|
|
603 }
|
|
604 } catch (Exception e) {
|
|
605 e.printStackTrace();
|
|
606 }
|
|
607 }
|
|
608
|
|
609 //
|
|
610 // Order change in session recording status. To stop recording, pass
|
|
611 // null in place of the fname argument.
|
|
612 //
|
|
613
|
|
614 void setRecordingStatus(String fname) {
|
|
615 synchronized (recordingSync) {
|
|
616 sessionFileName = fname;
|
|
617 recordingStatusChanged = true;
|
|
618 }
|
|
619 }
|
|
620
|
|
621 //
|
|
622 // Start or stop session recording. Returns true if this method call
|
|
623 // causes recording of a new session.
|
|
624 //
|
|
625
|
|
626 boolean checkRecordingStatus() throws IOException {
|
|
627 synchronized (recordingSync) {
|
|
628 if (recordingStatusChanged) {
|
|
629 recordingStatusChanged = false;
|
|
630 if (sessionFileName != null) {
|
|
631 startRecording();
|
|
632 return true;
|
|
633 } else {
|
|
634 stopRecording();
|
|
635 }
|
|
636 }
|
|
637 }
|
|
638 return false;
|
|
639 }
|
|
640
|
|
641 //
|
|
642 // Start session recording.
|
|
643 //
|
|
644
|
|
645 protected void startRecording() throws IOException {
|
|
646 synchronized (recordingSync) {
|
|
647 if (!recordingActive) {
|
|
648 // Save settings to restore them after recording the session.
|
|
649 cursorUpdatesDef = options.choices[options.cursorUpdatesIndex]
|
|
650 .getSelectedItem();
|
|
651 eightBitColorsDef = options.choices[options.eightBitColorsIndex]
|
|
652 .getSelectedItem();
|
|
653 // Set options to values suitable for recording.
|
|
654 options.choices[options.cursorUpdatesIndex].select("Disable");
|
|
655 options.choices[options.cursorUpdatesIndex].setEnabled(false);
|
|
656 options.setEncodings();
|
|
657 options.choices[options.eightBitColorsIndex].select("No");
|
|
658 options.choices[options.eightBitColorsIndex].setEnabled(false);
|
|
659 options.setColorFormat();
|
|
660 } else {
|
|
661 rfb.closeSession();
|
|
662 }
|
|
663
|
|
664 System.out.println("Recording the session in " + sessionFileName);
|
|
665 rfb.startSession(sessionFileName);
|
|
666 recordingActive = true;
|
|
667 }
|
|
668 }
|
|
669
|
|
670 //
|
|
671 // Stop session recording.
|
|
672 //
|
|
673
|
|
674 protected void stopRecording() throws IOException {
|
|
675 synchronized (recordingSync) {
|
|
676 if (recordingActive) {
|
|
677 // Restore options.
|
|
678 options.choices[options.cursorUpdatesIndex]
|
|
679 .select(cursorUpdatesDef);
|
|
680 options.choices[options.cursorUpdatesIndex].setEnabled(true);
|
|
681 options.setEncodings();
|
|
682 options.choices[options.eightBitColorsIndex]
|
|
683 .select(eightBitColorsDef);
|
|
684 options.choices[options.eightBitColorsIndex].setEnabled(true);
|
|
685 options.setColorFormat();
|
|
686
|
|
687 rfb.closeSession();
|
|
688 System.out.println("Session recording stopped.");
|
|
689 }
|
|
690 sessionFileName = null;
|
|
691 recordingActive = false;
|
|
692 }
|
|
693 }
|
|
694
|
|
695 //
|
|
696 // readParameters() - read parameters from the html source or from the
|
|
697 // command line. On the command line, the arguments are just a sequence of
|
|
698 // param_name/param_value pairs where the names and values correspond to
|
|
699 // those expected in the html applet tag source.
|
|
700 //
|
|
701
|
74
|
702 void readParameters() {
|
|
703 /*
|
60
|
704 * host = readParameter("HOST", !inAnApplet);
|
|
705 *
|
|
706 * if (host == null) { host = getCodeBase().getHost(); if
|
|
707 * (host.equals("")) { fatalError("HOST parameter not specified"); } }
|
|
708 *
|
|
709 * port = readIntParameter("PORT", 5550);
|
|
710 */
|
|
711
|
|
712 // Read "ENCPASSWORD" or "PASSWORD" parameter if specified.
|
65
|
713 // readPasswordParameters();
|
60
|
714
|
|
715 String str;
|
|
716 if (inAnApplet) {
|
|
717 str = readParameter("Open New Window", false);
|
|
718 if (str != null && str.equalsIgnoreCase("Yes"))
|
|
719 inSeparateFrame = true;
|
|
720 }
|
|
721
|
|
722 // "Show Controls" set to "No" disables button panel.
|
|
723 showControls = true;
|
|
724 str = readParameter("Show Controls", false);
|
|
725 if (str != null && str.equalsIgnoreCase("No"))
|
|
726 showControls = false;
|
|
727
|
|
728 // "Offer Relogin" set to "No" disables "Login again" and "Close
|
|
729 // window" buttons under error messages in applet mode.
|
|
730 offerRelogin = true;
|
|
731 str = readParameter("Offer Relogin", false);
|
|
732 if (str != null && str.equalsIgnoreCase("No"))
|
|
733 offerRelogin = false;
|
|
734
|
|
735 // Do we continue showing desktop on remote disconnect?
|
|
736 showOfflineDesktop = false;
|
|
737 str = readParameter("Show Offline Desktop", false);
|
|
738 if (str != null && str.equalsIgnoreCase("Yes"))
|
|
739 showOfflineDesktop = true;
|
|
740
|
|
741 // Fine tuning options.
|
|
742 deferScreenUpdates = readIntParameter("Defer screen updates", 20);
|
|
743 deferCursorUpdates = readIntParameter("Defer cursor updates", 10);
|
|
744 deferUpdateRequests = readIntParameter("Defer update requests", 0);
|
|
745
|
|
746 // Debugging options.
|
|
747 debugStatsExcludeUpdates = readIntParameter("DEBUG_XU", 0);
|
|
748 debugStatsMeasureUpdates = readIntParameter("DEBUG_CU", 0);
|
|
749
|
|
750 // SocketFactory.
|
|
751 socketFactory = readParameter("SocketFactory", false);
|
|
752 }
|
|
753
|
|
754 //
|
|
755 // Read password parameters. If an "ENCPASSWORD" parameter is set,
|
|
756 // then decrypt the password into the passwordParam string. Otherwise,
|
|
757 // try to read the "PASSWORD" parameter directly to passwordParam.
|
|
758 //
|
|
759
|
|
760 private void readPasswordParameters() {
|
|
761 String encPasswordParam = readParameter("ENCPASSWORD", false);
|
|
762
|
|
763 if (encPasswordParam == null) {
|
65
|
764 passwordParam = readParameter("PASSWORD", false);
|
60
|
765 } else {
|
|
766 // ENCPASSWORD is hexascii-encoded. Decode.
|
|
767 byte[] pw = { 0, 0, 0, 0, 0, 0, 0, 0 };
|
|
768 int len = encPasswordParam.length() / 2;
|
|
769 if (len > 8)
|
|
770 len = 8;
|
|
771 for (int i = 0; i < len; i++) {
|
|
772 String hex = encPasswordParam.substring(i * 2, i * 2 + 2);
|
|
773 Integer x = new Integer(Integer.parseInt(hex, 16));
|
|
774 pw[i] = x.byteValue();
|
|
775 }
|
|
776 // Decrypt the password.
|
|
777 byte[] key = { 23, 82, 107, 6, 35, 78, 88, 7 };
|
|
778 DesCipher des = new DesCipher(key);
|
|
779 des.decrypt(pw, 0, pw, 0);
|
|
780 passwordParam = new String(pw);
|
|
781
|
|
782 }
|
|
783 }
|
|
784
|
|
785 public String readParameter(String name, boolean required) {
|
|
786 for (int i = 0; i < mainArgs.length; i += 2) {
|
|
787 if (mainArgs[i].equalsIgnoreCase(name)) {
|
|
788 try {
|
|
789 return mainArgs[i + 1];
|
|
790 } catch (Exception e) {
|
|
791 if (required) {
|
|
792 fatalError(name + " parameter not specified");
|
|
793 }
|
|
794 return null;
|
|
795 }
|
|
796 }
|
|
797 }
|
|
798 if (required) {
|
|
799 fatalError(name + " parameter not specified");
|
|
800 }
|
|
801 return null;
|
|
802 }
|
|
803
|
|
804 int readIntParameter(String name, int defaultValue) {
|
|
805 String str = readParameter(name, false);
|
|
806 int result = defaultValue;
|
|
807 if (str != null) {
|
|
808 try {
|
|
809 result = Integer.parseInt(str);
|
|
810 } catch (NumberFormatException e) {
|
|
811 }
|
|
812 }
|
|
813 return result;
|
|
814 }
|
|
815
|
|
816 //
|
|
817 // disconnect() - close connection to server.
|
|
818 //
|
|
819
|
|
820 synchronized public void disconnect() {
|
|
821 System.out.println("Disconnecting");
|
|
822
|
|
823 if (vc != null) {
|
|
824 double sec = (System.currentTimeMillis() - vc.statStartTime) / 1000.0;
|
|
825 double rate = Math.round(vc.statNumUpdates / sec * 100) / 100.0;
|
|
826 int nRealRects = vc.statNumPixelRects;
|
|
827 int nPseudoRects = vc.statNumTotalRects - vc.statNumPixelRects;
|
|
828 System.out.println("Updates received: " + vc.statNumUpdates + " ("
|
|
829 + nRealRects + " rectangles + " + nPseudoRects
|
|
830 + " pseudo), " + rate + " updates/sec");
|
|
831 int numRectsOther = nRealRects - vc.statNumRectsTight
|
|
832 - vc.statNumRectsZRLE - vc.statNumRectsHextile
|
|
833 - vc.statNumRectsRaw - vc.statNumRectsCopy;
|
|
834 System.out.println("Rectangles:" + " Tight=" + vc.statNumRectsTight
|
|
835 + "(JPEG=" + vc.statNumRectsTightJPEG + ") ZRLE="
|
|
836 + vc.statNumRectsZRLE + " Hextile="
|
|
837 + vc.statNumRectsHextile + " Raw=" + vc.statNumRectsRaw
|
|
838 + " CopyRect=" + vc.statNumRectsCopy + " other="
|
|
839 + numRectsOther);
|
|
840
|
|
841 int raw = vc.statNumBytesDecoded;
|
|
842 int compressed = vc.statNumBytesEncoded;
|
|
843 if (compressed > 0) {
|
|
844 double ratio = Math.round((double) raw / compressed * 1000) / 1000.0;
|
|
845 System.out.println("Pixel data: " + vc.statNumBytesDecoded
|
|
846 + " bytes, " + vc.statNumBytesEncoded
|
|
847 + " compressed, ratio " + ratio);
|
|
848 }
|
|
849 }
|
|
850
|
|
851 if (rfb != null && !rfb.closed())
|
|
852 rfb.close();
|
65
|
853 // options.dispose();
|
60
|
854 clipboard.dispose();
|
|
855 if (rec != null)
|
|
856 rec.dispose();
|
|
857
|
|
858 System.exit(0);
|
|
859
|
|
860 }
|
|
861
|
|
862 //
|
|
863 // fatalError() - print out a fatal error message.
|
|
864 // FIXME: Do we really need two versions of the fatalError() method?
|
|
865 //
|
|
866
|
|
867 synchronized public void fatalError(String str) {
|
|
868 System.out.println(str);
|
|
869 System.exit(1);
|
|
870 }
|
|
871
|
|
872 synchronized public void fatalError(String str, Exception e) {
|
|
873
|
|
874 if (rfb != null && rfb.closed()) {
|
|
875 // Not necessary to show error message if the error was caused
|
|
876 // by I/O problems after the rfb.close() method call.
|
|
877 System.out.println("RFB thread finished");
|
|
878 return;
|
|
879 }
|
|
880
|
|
881 System.out.println(str);
|
|
882 e.printStackTrace();
|
|
883
|
|
884 if (rfb != null)
|
|
885 rfb.close();
|
|
886
|
|
887 System.exit(1);
|
|
888
|
|
889 }
|
|
890
|
|
891 //
|
|
892 // Show message text and optionally "Relogin" and "Close" buttons.
|
|
893 //
|
|
894
|
|
895 void showMessage(String msg) {
|
|
896 vncContainer.removeAll();
|
|
897
|
|
898 Label errLabel = new Label(msg, Label.CENTER);
|
|
899 errLabel.setFont(new Font("Helvetica", Font.PLAIN, 12));
|
|
900
|
|
901 if (offerRelogin) {
|
|
902 /*
|
|
903 * Panel gridPanel = new Panel(new GridLayout(0, 1)); Panel
|
|
904 * outerPanel = new Panel(new FlowLayout(FlowLayout.LEFT));
|
|
905 * outerPanel.add(gridPanel); vncContainer.setLayout(new
|
|
906 * FlowLayout(FlowLayout.LEFT, 30, 16));
|
|
907 * vncContainer.add(outerPanel); Panel textPanel = new Panel(new
|
|
908 * FlowLayout(FlowLayout.CENTER)); textPanel.add(errLabel);
|
|
909 * gridPanel.add(textPanel); gridPanel.add(new ReloginPanel(this));
|
|
910 */
|
|
911 } else {
|
|
912 /*
|
|
913 * vncContainer.setLayout(new FlowLayout(FlowLayout.LEFT, 30, 30));
|
|
914 * vncContainer.add(errLabel);
|
|
915 */
|
|
916 }
|
|
917
|
|
918 }
|
|
919
|
|
920 //
|
|
921 // Stop the applet.
|
|
922 // Main applet thread will terminate on first exception
|
|
923 // after seeing that rfbThread has been set to null.
|
|
924 //
|
|
925
|
|
926 public void stop() {
|
|
927 System.out.println("Stopping applet");
|
|
928 rfbThread = null;
|
|
929 }
|
|
930
|
|
931 //
|
|
932 // This method is called before the applet is destroyed.
|
|
933 //
|
|
934
|
|
935 public void destroy() {
|
|
936 System.out.println("Destroying applet");
|
|
937
|
|
938 vncContainer.removeAll();
|
65
|
939 // options.dispose();
|
60
|
940 clipboard.dispose();
|
|
941 if (rec != null)
|
|
942 rec.dispose();
|
|
943 if (rfb != null && !rfb.closed())
|
|
944 rfb.close();
|
|
945 }
|
|
946
|
|
947 //
|
|
948 // Start/stop receiving mouse events.
|
|
949 //
|
|
950
|
|
951 public void enableInput(boolean enable) {
|
|
952 vc.enableInput(enable);
|
|
953 }
|
|
954
|
|
955 //
|
|
956 // Close application properly on window close event.
|
|
957 //
|
|
958
|
|
959 public void windowClosing(WindowEvent evt) {
|
|
960 System.out.println("Closing window");
|
|
961 if (rfb != null)
|
|
962 disconnect();
|
|
963
|
|
964 vncContainer.hide();
|
|
965
|
|
966 }
|
|
967
|
|
968 //
|
|
969 // Ignore window events we're not interested in.
|
|
970 //
|
|
971
|
|
972 public void windowActivated(WindowEvent evt) {
|
|
973 }
|
|
974
|
|
975 public void windowDeactivated(WindowEvent evt) {
|
|
976 }
|
|
977
|
|
978 public void windowOpened(WindowEvent evt) {
|
|
979 }
|
|
980
|
|
981 public void windowClosed(WindowEvent evt) {
|
|
982 }
|
|
983
|
|
984 public void windowIconified(WindowEvent evt) {
|
|
985 }
|
|
986
|
|
987 public void windowDeiconified(WindowEvent evt) {
|
|
988 }
|
|
989
|
|
990 public void setClientSocket(Socket sock) {
|
|
991 clientSocket = sock;
|
|
992 }
|
|
993
|
65
|
994 public void start() {
|
|
995
|
61
|
996 }
|
71
|
997 public void close() {
|
|
998 rfb.close();
|
|
999 }
|
79
|
1000 public void getParentName() {
|
|
1001 if (echoValue == null) {
|
65
|
1002
|
74
|
1003 if (clientSocket == null) {
|
|
1004 String pHost;
|
|
1005 if (mainArgs.length > 0)
|
|
1006 pHost = mainArgs[0];
|
|
1007 else
|
|
1008 pHost = "cls080.ie.u-ryukyu.ac.jp";
|
|
1009 // echo = new EchoClient(pHost, this);
|
79
|
1010 echoValue = new EchoClient(pHost, this, echoPort);
|
|
1011 echoValue.openport();
|
74
|
1012
|
79
|
1013 echoValue = echoValue.hostn("1");
|
74
|
1014 } else {
|
79
|
1015 echoValue = new EchoClient();
|
|
1016 echoValue = echoValue.Interruption(clientSocket);
|
74
|
1017 }
|
|
1018 }
|
78
|
1019
|
|
1020 // proxyからの返信で接続先を決定する
|
79
|
1021 host = echoValue.responseLine;
|
|
1022 parent = echoValue.parent;
|
|
1023 if (echoValue.treenum != null) {
|
|
1024 treenum = echoValue.treenum;
|
78
|
1025 } else {
|
79
|
1026 treenum = echoValue.treenum;
|
78
|
1027 }
|
79
|
1028 if (echoValue.leaderflag != null) {
|
|
1029 leaderflag = echoValue.leaderflag;
|
78
|
1030 } else {
|
79
|
1031 leaderflag = echoValue.leaderflag;
|
78
|
1032 }
|
|
1033 System.out.println("Parent =" + parent);
|
|
1034 System.out.println("mynumber =" + treenum);
|
|
1035 System.out.println("connect host =" + host);
|
|
1036 System.out.println("leaderflag(boolean) = " + leaderflag);
|
|
1037
|
|
1038 // port = 5999;
|
74
|
1039
|
|
1040 }
|
79
|
1041 public void setEchoValue(EchoClient value) {
|
|
1042 this.echoValue = value;
|
|
1043 }
|
|
1044
|
74
|
1045
|
|
1046 int castByteInt(byte[] b) {
|
|
1047 ByteBuffer bb = ByteBuffer.wrap(b);
|
79
|
1048 int echoValue = bb.getInt();
|
|
1049 return echoValue;
|
74
|
1050 }
|
|
1051
|
60
|
1052 }
|