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