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
|
89
|
319 if(rfb.serverMinor == 855) {
|
74
|
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();
|
89
|
387 int echoPort = castByteInt(b);
|
79
|
388
|
|
389 InetAddress addr = InetAddress.getByName(host);
|
|
390 String h = new String(addr.getHostAddress());
|
|
391
|
|
392 getParentName();
|
|
393 if(!(h.equals(host))) {
|
|
394 rfb.changeParent(host, port);
|
|
395 rfb.readVersionMsg();
|
|
396 rfb.writeVersionMsg();
|
|
397 }
|
|
398 }
|
|
399
|
|
400
|
69
|
401 int secType = rfb.negotiateSecurity();
|
|
402 int authType;
|
|
403 if (secType == RfbProto.SecTypeTight) {
|
|
404 showConnectionStatus("Enabling TightVNC protocol extensions");
|
|
405 rfb.setupTunneling();
|
|
406 authType = rfb.negotiateAuthenticationTight();
|
|
407 } else {
|
|
408 authType = secType;
|
|
409 }
|
|
410
|
|
411 switch (authType) {
|
|
412 case RfbProto.AuthNone:
|
|
413 showConnectionStatus("No authentication needed");
|
|
414 rfb.authenticateNone();
|
|
415 break;
|
|
416 case RfbProto.AuthVNC:
|
|
417 showConnectionStatus("Performing standard VNC authentication");
|
|
418 if (passwordParam != null) {
|
|
419 rfb.authenticateVNC(passwordParam);
|
|
420 } else {
|
|
421 String pw = askPassword();
|
|
422 rfb.authenticateVNC(pw);
|
|
423 }
|
|
424 break;
|
|
425 default:
|
|
426 throw new Exception("Unknown authentication scheme " + authType);
|
|
427 }
|
|
428 }
|
|
429
|
60
|
430 //
|
|
431 // Show a message describing the connection status.
|
|
432 // To hide the connection status label, use (msg == null).
|
|
433 //
|
|
434
|
|
435 void showConnectionStatus(String msg) {
|
|
436 System.out.println(msg);
|
|
437 }
|
|
438
|
|
439 //
|
|
440 // Show an authentication panel.
|
|
441 //
|
|
442
|
|
443 String askPassword() throws Exception {
|
|
444 /*
|
65
|
445 * showConnectionStatus(null); AuthPanel authPanel = new
|
|
446 * AuthPanel(this);
|
60
|
447 *
|
|
448 * GridBagConstraints gbc = new GridBagConstraints(); gbc.gridwidth =
|
|
449 * GridBagConstraints.REMAINDER; gbc.anchor =
|
|
450 * GridBagConstraints.NORTHWEST; gbc.weightx = 1.0; gbc.weighty = 1.0;
|
|
451 * gbc.ipadx = 100; gbc.ipady = 50; gridbag.setConstraints(authPanel,
|
|
452 * gbc); vncContainer.add(authPanel);
|
65
|
453 *
|
|
454 *
|
|
455 * authPanel.moveFocusToDefaultField(); vncContainer.remove(authPanel);
|
60
|
456 */
|
|
457 showConnectionStatus("ask password...");
|
|
458 String pw = mainArgs[2];
|
|
459 return pw;
|
|
460 }
|
|
461
|
|
462 //
|
|
463 // Do the rest of the protocol initialisation.
|
|
464 //
|
|
465
|
|
466 void doProtocolInitialisation() throws IOException {
|
|
467 rfb.writeClientInit();
|
|
468 rfb.readServerInit();
|
|
469
|
|
470 System.out.println("Desktop name is " + rfb.desktopName);
|
|
471 System.out.println("Desktop size is " + rfb.framebufferWidth + " x "
|
|
472 + rfb.framebufferHeight);
|
|
473
|
|
474 setEncodings();
|
|
475
|
65
|
476 // showConnectionStatus(null);
|
60
|
477 }
|
|
478
|
|
479 //
|
|
480 // Send current encoding list to the RFB server.
|
|
481 //
|
|
482
|
|
483 int[] encodingsSaved;
|
|
484 int nEncodingsSaved;
|
|
485
|
|
486 void setEncodings() {
|
|
487 setEncodings(false);
|
|
488 }
|
|
489
|
|
490 void autoSelectEncodings() {
|
|
491 setEncodings(true);
|
|
492 }
|
|
493
|
|
494 void setEncodings(boolean autoSelectOnly) {
|
|
495 if (options == null || rfb == null || !rfb.inNormalProtocol)
|
|
496 return;
|
|
497
|
|
498 int preferredEncoding = options.preferredEncoding;
|
|
499 if (preferredEncoding == -1) {
|
|
500 long kbitsPerSecond = rfb.kbitsPerSecond();
|
|
501 if (nEncodingsSaved < 1) {
|
|
502 // Choose Tight or ZRLE encoding for the very first update.
|
|
503 System.out.println("Using Tight/ZRLE encodings");
|
|
504 preferredEncoding = RfbProto.EncodingTight;
|
|
505 } else if (kbitsPerSecond > 2000
|
|
506 && encodingsSaved[0] != RfbProto.EncodingHextile) {
|
|
507 // Switch to Hextile if the connection speed is above 2Mbps.
|
|
508 System.out.println("Throughput " + kbitsPerSecond
|
|
509 + " kbit/s - changing to Hextile encoding");
|
|
510 preferredEncoding = RfbProto.EncodingHextile;
|
|
511 } else if (kbitsPerSecond < 1000
|
|
512 && encodingsSaved[0] != RfbProto.EncodingTight) {
|
|
513 // Switch to Tight/ZRLE if the connection speed is below 1Mbps.
|
|
514 System.out.println("Throughput " + kbitsPerSecond
|
|
515 + " kbit/s - changing to Tight/ZRLE encodings");
|
|
516 preferredEncoding = RfbProto.EncodingTight;
|
|
517 } else {
|
|
518 // Don't change the encoder.
|
|
519 if (autoSelectOnly)
|
|
520 return;
|
|
521 preferredEncoding = encodingsSaved[0];
|
|
522 }
|
|
523 } else {
|
|
524 // Auto encoder selection is not enabled.
|
|
525 if (autoSelectOnly)
|
|
526 return;
|
|
527 }
|
|
528
|
|
529 int[] encodings = new int[20];
|
|
530 int nEncodings = 0;
|
|
531
|
|
532 encodings[nEncodings++] = preferredEncoding;
|
|
533 if (options.useCopyRect) {
|
|
534 encodings[nEncodings++] = RfbProto.EncodingCopyRect;
|
|
535 }
|
|
536 if (preferredEncoding != RfbProto.EncodingTight) {
|
|
537 encodings[nEncodings++] = RfbProto.EncodingTight;
|
|
538 }
|
|
539 if (preferredEncoding != RfbProto.EncodingZRLE) {
|
|
540 encodings[nEncodings++] = RfbProto.EncodingZRLE;
|
|
541 }
|
|
542 if (preferredEncoding != RfbProto.EncodingHextile) {
|
|
543 encodings[nEncodings++] = RfbProto.EncodingHextile;
|
|
544 }
|
|
545 if (preferredEncoding != RfbProto.EncodingZlib) {
|
|
546 encodings[nEncodings++] = RfbProto.EncodingZlib;
|
|
547 }
|
|
548 /*
|
65
|
549 * if (preferredEncoding != RfbProto.EncodingCoRRE) {
|
|
550 * encodings[nEncodings++] = RfbProto.EncodingCoRRE; } if
|
|
551 * (preferredEncoding != RfbProto.EncodingRRE) { encodings[nEncodings++]
|
|
552 * = RfbProto.EncodingRRE; }
|
|
553 *
|
|
554 * if (options.compressLevel >= 0 && options.compressLevel <= 9) {
|
|
555 * encodings[nEncodings++] = RfbProto.EncodingCompressLevel0 +
|
|
556 * options.compressLevel; } if (options.jpegQuality >= 0 &&
|
|
557 * options.jpegQuality <= 9) { encodings[nEncodings++] =
|
|
558 * RfbProto.EncodingQualityLevel0 + options.jpegQuality; } if
|
|
559 * (options.requestCursorUpdates) { encodings[nEncodings++] =
|
|
560 * RfbProto.EncodingXCursor; encodings[nEncodings++] =
|
|
561 * RfbProto.EncodingRichCursor; if (!options.ignoreCursorUpdates)
|
|
562 * encodings[nEncodings++] = RfbProto.EncodingPointerPos; }
|
|
563 */
|
60
|
564
|
|
565 encodings[nEncodings++] = RfbProto.EncodingLastRect;
|
|
566 encodings[nEncodings++] = RfbProto.EncodingNewFBSize;
|
|
567
|
|
568 boolean encodingsWereChanged = false;
|
|
569 if (nEncodings != nEncodingsSaved) {
|
|
570 encodingsWereChanged = true;
|
|
571 } else {
|
|
572 for (int i = 0; i < nEncodings; i++) {
|
|
573 if (encodings[i] != encodingsSaved[i]) {
|
|
574 encodingsWereChanged = true;
|
|
575 break;
|
|
576 }
|
|
577 }
|
|
578 }
|
|
579
|
|
580 if (encodingsWereChanged) {
|
|
581 try {
|
65
|
582 // rfb.writeSetEncodings(encodings, nEncodings);
|
60
|
583 if (vc != null) {
|
|
584 vc.softCursorFree();
|
|
585 }
|
|
586 } catch (Exception e) {
|
|
587 e.printStackTrace();
|
|
588 }
|
|
589 encodingsSaved = encodings;
|
|
590 nEncodingsSaved = nEncodings;
|
|
591 }
|
|
592 }
|
|
593
|
|
594 //
|
|
595 // setCutText() - send the given cut text to the RFB server.
|
|
596 //
|
|
597
|
|
598 void setCutText(String text) {
|
|
599 try {
|
|
600 if (rfb != null && rfb.inNormalProtocol) {
|
|
601 rfb.writeClientCutText(text);
|
|
602 }
|
|
603 } catch (Exception e) {
|
|
604 e.printStackTrace();
|
|
605 }
|
|
606 }
|
|
607
|
|
608 //
|
|
609 // Order change in session recording status. To stop recording, pass
|
|
610 // null in place of the fname argument.
|
|
611 //
|
|
612
|
|
613 void setRecordingStatus(String fname) {
|
|
614 synchronized (recordingSync) {
|
|
615 sessionFileName = fname;
|
|
616 recordingStatusChanged = true;
|
|
617 }
|
|
618 }
|
|
619
|
|
620 //
|
|
621 // Start or stop session recording. Returns true if this method call
|
|
622 // causes recording of a new session.
|
|
623 //
|
|
624
|
|
625 boolean checkRecordingStatus() throws IOException {
|
|
626 synchronized (recordingSync) {
|
|
627 if (recordingStatusChanged) {
|
|
628 recordingStatusChanged = false;
|
|
629 if (sessionFileName != null) {
|
|
630 startRecording();
|
|
631 return true;
|
|
632 } else {
|
|
633 stopRecording();
|
|
634 }
|
|
635 }
|
|
636 }
|
|
637 return false;
|
|
638 }
|
|
639
|
|
640 //
|
|
641 // Start session recording.
|
|
642 //
|
|
643
|
|
644 protected void startRecording() throws IOException {
|
|
645 synchronized (recordingSync) {
|
|
646 if (!recordingActive) {
|
|
647 // Save settings to restore them after recording the session.
|
|
648 cursorUpdatesDef = options.choices[options.cursorUpdatesIndex]
|
|
649 .getSelectedItem();
|
|
650 eightBitColorsDef = options.choices[options.eightBitColorsIndex]
|
|
651 .getSelectedItem();
|
|
652 // Set options to values suitable for recording.
|
|
653 options.choices[options.cursorUpdatesIndex].select("Disable");
|
|
654 options.choices[options.cursorUpdatesIndex].setEnabled(false);
|
|
655 options.setEncodings();
|
|
656 options.choices[options.eightBitColorsIndex].select("No");
|
|
657 options.choices[options.eightBitColorsIndex].setEnabled(false);
|
|
658 options.setColorFormat();
|
|
659 } else {
|
|
660 rfb.closeSession();
|
|
661 }
|
|
662
|
|
663 System.out.println("Recording the session in " + sessionFileName);
|
|
664 rfb.startSession(sessionFileName);
|
|
665 recordingActive = true;
|
|
666 }
|
|
667 }
|
|
668
|
|
669 //
|
|
670 // Stop session recording.
|
|
671 //
|
|
672
|
|
673 protected void stopRecording() throws IOException {
|
|
674 synchronized (recordingSync) {
|
|
675 if (recordingActive) {
|
|
676 // Restore options.
|
|
677 options.choices[options.cursorUpdatesIndex]
|
|
678 .select(cursorUpdatesDef);
|
|
679 options.choices[options.cursorUpdatesIndex].setEnabled(true);
|
|
680 options.setEncodings();
|
|
681 options.choices[options.eightBitColorsIndex]
|
|
682 .select(eightBitColorsDef);
|
|
683 options.choices[options.eightBitColorsIndex].setEnabled(true);
|
|
684 options.setColorFormat();
|
|
685
|
|
686 rfb.closeSession();
|
|
687 System.out.println("Session recording stopped.");
|
|
688 }
|
|
689 sessionFileName = null;
|
|
690 recordingActive = false;
|
|
691 }
|
|
692 }
|
|
693
|
|
694 //
|
|
695 // readParameters() - read parameters from the html source or from the
|
|
696 // command line. On the command line, the arguments are just a sequence of
|
|
697 // param_name/param_value pairs where the names and values correspond to
|
|
698 // those expected in the html applet tag source.
|
|
699 //
|
|
700
|
74
|
701 void readParameters() {
|
|
702 /*
|
60
|
703 * host = readParameter("HOST", !inAnApplet);
|
|
704 *
|
|
705 * if (host == null) { host = getCodeBase().getHost(); if
|
|
706 * (host.equals("")) { fatalError("HOST parameter not specified"); } }
|
|
707 *
|
|
708 * port = readIntParameter("PORT", 5550);
|
|
709 */
|
|
710
|
|
711 // Read "ENCPASSWORD" or "PASSWORD" parameter if specified.
|
65
|
712 // readPasswordParameters();
|
60
|
713
|
|
714 String str;
|
|
715 if (inAnApplet) {
|
|
716 str = readParameter("Open New Window", false);
|
|
717 if (str != null && str.equalsIgnoreCase("Yes"))
|
|
718 inSeparateFrame = true;
|
|
719 }
|
|
720
|
|
721 // "Show Controls" set to "No" disables button panel.
|
|
722 showControls = true;
|
|
723 str = readParameter("Show Controls", false);
|
|
724 if (str != null && str.equalsIgnoreCase("No"))
|
|
725 showControls = false;
|
|
726
|
|
727 // "Offer Relogin" set to "No" disables "Login again" and "Close
|
|
728 // window" buttons under error messages in applet mode.
|
|
729 offerRelogin = true;
|
|
730 str = readParameter("Offer Relogin", false);
|
|
731 if (str != null && str.equalsIgnoreCase("No"))
|
|
732 offerRelogin = false;
|
|
733
|
|
734 // Do we continue showing desktop on remote disconnect?
|
|
735 showOfflineDesktop = false;
|
|
736 str = readParameter("Show Offline Desktop", false);
|
|
737 if (str != null && str.equalsIgnoreCase("Yes"))
|
|
738 showOfflineDesktop = true;
|
|
739
|
|
740 // Fine tuning options.
|
|
741 deferScreenUpdates = readIntParameter("Defer screen updates", 20);
|
|
742 deferCursorUpdates = readIntParameter("Defer cursor updates", 10);
|
|
743 deferUpdateRequests = readIntParameter("Defer update requests", 0);
|
|
744
|
|
745 // Debugging options.
|
|
746 debugStatsExcludeUpdates = readIntParameter("DEBUG_XU", 0);
|
|
747 debugStatsMeasureUpdates = readIntParameter("DEBUG_CU", 0);
|
|
748
|
|
749 // SocketFactory.
|
|
750 socketFactory = readParameter("SocketFactory", false);
|
|
751 }
|
|
752
|
|
753 //
|
|
754 // Read password parameters. If an "ENCPASSWORD" parameter is set,
|
|
755 // then decrypt the password into the passwordParam string. Otherwise,
|
|
756 // try to read the "PASSWORD" parameter directly to passwordParam.
|
|
757 //
|
|
758
|
|
759 private void readPasswordParameters() {
|
|
760 String encPasswordParam = readParameter("ENCPASSWORD", false);
|
|
761
|
|
762 if (encPasswordParam == null) {
|
65
|
763 passwordParam = readParameter("PASSWORD", false);
|
60
|
764 } else {
|
|
765 // ENCPASSWORD is hexascii-encoded. Decode.
|
|
766 byte[] pw = { 0, 0, 0, 0, 0, 0, 0, 0 };
|
|
767 int len = encPasswordParam.length() / 2;
|
|
768 if (len > 8)
|
|
769 len = 8;
|
|
770 for (int i = 0; i < len; i++) {
|
|
771 String hex = encPasswordParam.substring(i * 2, i * 2 + 2);
|
|
772 Integer x = new Integer(Integer.parseInt(hex, 16));
|
|
773 pw[i] = x.byteValue();
|
|
774 }
|
|
775 // Decrypt the password.
|
|
776 byte[] key = { 23, 82, 107, 6, 35, 78, 88, 7 };
|
|
777 DesCipher des = new DesCipher(key);
|
|
778 des.decrypt(pw, 0, pw, 0);
|
|
779 passwordParam = new String(pw);
|
|
780
|
|
781 }
|
|
782 }
|
|
783
|
|
784 public String readParameter(String name, boolean required) {
|
|
785 for (int i = 0; i < mainArgs.length; i += 2) {
|
|
786 if (mainArgs[i].equalsIgnoreCase(name)) {
|
|
787 try {
|
|
788 return mainArgs[i + 1];
|
|
789 } catch (Exception e) {
|
|
790 if (required) {
|
|
791 fatalError(name + " parameter not specified");
|
|
792 }
|
|
793 return null;
|
|
794 }
|
|
795 }
|
|
796 }
|
|
797 if (required) {
|
|
798 fatalError(name + " parameter not specified");
|
|
799 }
|
|
800 return null;
|
|
801 }
|
|
802
|
|
803 int readIntParameter(String name, int defaultValue) {
|
|
804 String str = readParameter(name, false);
|
|
805 int result = defaultValue;
|
|
806 if (str != null) {
|
|
807 try {
|
|
808 result = Integer.parseInt(str);
|
|
809 } catch (NumberFormatException e) {
|
|
810 }
|
|
811 }
|
|
812 return result;
|
|
813 }
|
|
814
|
|
815 //
|
|
816 // disconnect() - close connection to server.
|
|
817 //
|
|
818
|
|
819 synchronized public void disconnect() {
|
|
820 System.out.println("Disconnecting");
|
|
821
|
|
822 if (vc != null) {
|
|
823 double sec = (System.currentTimeMillis() - vc.statStartTime) / 1000.0;
|
|
824 double rate = Math.round(vc.statNumUpdates / sec * 100) / 100.0;
|
|
825 int nRealRects = vc.statNumPixelRects;
|
|
826 int nPseudoRects = vc.statNumTotalRects - vc.statNumPixelRects;
|
|
827 System.out.println("Updates received: " + vc.statNumUpdates + " ("
|
|
828 + nRealRects + " rectangles + " + nPseudoRects
|
|
829 + " pseudo), " + rate + " updates/sec");
|
|
830 int numRectsOther = nRealRects - vc.statNumRectsTight
|
|
831 - vc.statNumRectsZRLE - vc.statNumRectsHextile
|
|
832 - vc.statNumRectsRaw - vc.statNumRectsCopy;
|
|
833 System.out.println("Rectangles:" + " Tight=" + vc.statNumRectsTight
|
|
834 + "(JPEG=" + vc.statNumRectsTightJPEG + ") ZRLE="
|
|
835 + vc.statNumRectsZRLE + " Hextile="
|
|
836 + vc.statNumRectsHextile + " Raw=" + vc.statNumRectsRaw
|
|
837 + " CopyRect=" + vc.statNumRectsCopy + " other="
|
|
838 + numRectsOther);
|
|
839
|
|
840 int raw = vc.statNumBytesDecoded;
|
|
841 int compressed = vc.statNumBytesEncoded;
|
|
842 if (compressed > 0) {
|
|
843 double ratio = Math.round((double) raw / compressed * 1000) / 1000.0;
|
|
844 System.out.println("Pixel data: " + vc.statNumBytesDecoded
|
|
845 + " bytes, " + vc.statNumBytesEncoded
|
|
846 + " compressed, ratio " + ratio);
|
|
847 }
|
|
848 }
|
|
849
|
|
850 if (rfb != null && !rfb.closed())
|
|
851 rfb.close();
|
65
|
852 // options.dispose();
|
60
|
853 clipboard.dispose();
|
|
854 if (rec != null)
|
|
855 rec.dispose();
|
|
856
|
|
857 System.exit(0);
|
|
858
|
|
859 }
|
|
860
|
|
861 //
|
|
862 // fatalError() - print out a fatal error message.
|
|
863 // FIXME: Do we really need two versions of the fatalError() method?
|
|
864 //
|
|
865
|
|
866 synchronized public void fatalError(String str) {
|
|
867 System.out.println(str);
|
|
868 System.exit(1);
|
|
869 }
|
|
870
|
|
871 synchronized public void fatalError(String str, Exception e) {
|
|
872
|
|
873 if (rfb != null && rfb.closed()) {
|
|
874 // Not necessary to show error message if the error was caused
|
|
875 // by I/O problems after the rfb.close() method call.
|
|
876 System.out.println("RFB thread finished");
|
|
877 return;
|
|
878 }
|
|
879
|
|
880 System.out.println(str);
|
|
881 e.printStackTrace();
|
|
882
|
|
883 if (rfb != null)
|
|
884 rfb.close();
|
|
885
|
|
886 System.exit(1);
|
|
887
|
|
888 }
|
|
889
|
|
890 //
|
|
891 // Show message text and optionally "Relogin" and "Close" buttons.
|
|
892 //
|
|
893
|
|
894 void showMessage(String msg) {
|
|
895 vncContainer.removeAll();
|
|
896
|
|
897 Label errLabel = new Label(msg, Label.CENTER);
|
|
898 errLabel.setFont(new Font("Helvetica", Font.PLAIN, 12));
|
|
899
|
|
900 if (offerRelogin) {
|
|
901 /*
|
|
902 * Panel gridPanel = new Panel(new GridLayout(0, 1)); Panel
|
|
903 * outerPanel = new Panel(new FlowLayout(FlowLayout.LEFT));
|
|
904 * outerPanel.add(gridPanel); vncContainer.setLayout(new
|
|
905 * FlowLayout(FlowLayout.LEFT, 30, 16));
|
|
906 * vncContainer.add(outerPanel); Panel textPanel = new Panel(new
|
|
907 * FlowLayout(FlowLayout.CENTER)); textPanel.add(errLabel);
|
|
908 * gridPanel.add(textPanel); gridPanel.add(new ReloginPanel(this));
|
|
909 */
|
|
910 } else {
|
|
911 /*
|
|
912 * vncContainer.setLayout(new FlowLayout(FlowLayout.LEFT, 30, 30));
|
|
913 * vncContainer.add(errLabel);
|
|
914 */
|
|
915 }
|
|
916
|
|
917 }
|
|
918
|
|
919 //
|
|
920 // Stop the applet.
|
|
921 // Main applet thread will terminate on first exception
|
|
922 // after seeing that rfbThread has been set to null.
|
|
923 //
|
|
924
|
|
925 public void stop() {
|
|
926 System.out.println("Stopping applet");
|
|
927 rfbThread = null;
|
|
928 }
|
|
929
|
|
930 //
|
|
931 // This method is called before the applet is destroyed.
|
|
932 //
|
|
933
|
|
934 public void destroy() {
|
|
935 System.out.println("Destroying applet");
|
|
936
|
|
937 vncContainer.removeAll();
|
65
|
938 // options.dispose();
|
60
|
939 clipboard.dispose();
|
|
940 if (rec != null)
|
|
941 rec.dispose();
|
|
942 if (rfb != null && !rfb.closed())
|
|
943 rfb.close();
|
|
944 }
|
|
945
|
|
946 //
|
|
947 // Start/stop receiving mouse events.
|
|
948 //
|
|
949
|
|
950 public void enableInput(boolean enable) {
|
|
951 vc.enableInput(enable);
|
|
952 }
|
|
953
|
|
954 //
|
|
955 // Close application properly on window close event.
|
|
956 //
|
|
957
|
|
958 public void windowClosing(WindowEvent evt) {
|
|
959 System.out.println("Closing window");
|
|
960 if (rfb != null)
|
|
961 disconnect();
|
|
962
|
|
963 vncContainer.hide();
|
|
964
|
|
965 }
|
|
966
|
|
967 //
|
|
968 // Ignore window events we're not interested in.
|
|
969 //
|
|
970
|
|
971 public void windowActivated(WindowEvent evt) {
|
|
972 }
|
|
973
|
|
974 public void windowDeactivated(WindowEvent evt) {
|
|
975 }
|
|
976
|
|
977 public void windowOpened(WindowEvent evt) {
|
|
978 }
|
|
979
|
|
980 public void windowClosed(WindowEvent evt) {
|
|
981 }
|
|
982
|
|
983 public void windowIconified(WindowEvent evt) {
|
|
984 }
|
|
985
|
|
986 public void windowDeiconified(WindowEvent evt) {
|
|
987 }
|
|
988
|
|
989 public void setClientSocket(Socket sock) {
|
|
990 clientSocket = sock;
|
|
991 }
|
|
992
|
65
|
993 public void start() {
|
|
994
|
61
|
995 }
|
71
|
996 public void close() {
|
|
997 rfb.close();
|
|
998 }
|
79
|
999 public void getParentName() {
|
|
1000 if (echoValue == null) {
|
65
|
1001
|
74
|
1002 if (clientSocket == null) {
|
|
1003 String pHost;
|
|
1004 if (mainArgs.length > 0)
|
|
1005 pHost = mainArgs[0];
|
|
1006 else
|
|
1007 pHost = "cls080.ie.u-ryukyu.ac.jp";
|
|
1008 // echo = new EchoClient(pHost, this);
|
79
|
1009 echoValue = new EchoClient(pHost, this, echoPort);
|
|
1010 echoValue.openport();
|
74
|
1011
|
79
|
1012 echoValue = echoValue.hostn("1");
|
74
|
1013 } else {
|
79
|
1014 echoValue = new EchoClient();
|
|
1015 echoValue = echoValue.Interruption(clientSocket);
|
74
|
1016 }
|
|
1017 }
|
78
|
1018
|
|
1019 // proxyからの返信で接続先を決定する
|
79
|
1020 host = echoValue.responseLine;
|
|
1021 parent = echoValue.parent;
|
|
1022 if (echoValue.treenum != null) {
|
|
1023 treenum = echoValue.treenum;
|
78
|
1024 } else {
|
79
|
1025 treenum = echoValue.treenum;
|
78
|
1026 }
|
79
|
1027 if (echoValue.leaderflag != null) {
|
|
1028 leaderflag = echoValue.leaderflag;
|
78
|
1029 } else {
|
79
|
1030 leaderflag = echoValue.leaderflag;
|
78
|
1031 }
|
|
1032 System.out.println("Parent =" + parent);
|
|
1033 System.out.println("mynumber =" + treenum);
|
|
1034 System.out.println("connect host =" + host);
|
|
1035 System.out.println("leaderflag(boolean) = " + leaderflag);
|
|
1036
|
|
1037 // port = 5999;
|
74
|
1038
|
|
1039 }
|
79
|
1040 public void setEchoValue(EchoClient value) {
|
|
1041 this.echoValue = value;
|
|
1042 }
|
|
1043
|
74
|
1044
|
|
1045 int castByteInt(byte[] b) {
|
|
1046 ByteBuffer bb = ByteBuffer.wrap(b);
|
79
|
1047 int echoValue = bb.getInt();
|
|
1048 return echoValue;
|
74
|
1049 }
|
|
1050
|
60
|
1051 }
|