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