Mercurial > hg > Members > nobuyasu > tightVNCProxy
annotate src/myVncProxy/VncProxyService.java @ 125:e3dddee7b934
modify OptionsNofFrame.java
author | e085711 |
---|---|
date | Mon, 08 Aug 2011 16:54:34 +0900 |
parents | 2ff8d5a226c9 |
children | cb00150c223e |
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); |
80 | 109 accThread = new Thread(new AcceptThread(rfb, 5999)); |
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 | |
80 | 356 |
13 | 357 encodings[nEncodings++] = preferredEncoding; |
125 | 358 /* |
13 | 359 if (options.useCopyRect) { |
360 encodings[nEncodings++] = RfbProto.EncodingCopyRect; | |
361 } | |
362 if (preferredEncoding != RfbProto.EncodingTight) { | |
363 encodings[nEncodings++] = RfbProto.EncodingTight; | |
364 } | |
125 | 365 */ |
13 | 366 if (preferredEncoding != RfbProto.EncodingZRLE) { |
367 encodings[nEncodings++] = RfbProto.EncodingZRLE; | |
368 } | |
125 | 369 /* |
13 | 370 if (preferredEncoding != RfbProto.EncodingHextile) { |
371 encodings[nEncodings++] = RfbProto.EncodingHextile; | |
372 } | |
125 | 373 */ |
13 | 374 if (preferredEncoding != RfbProto.EncodingZlib) { |
375 encodings[nEncodings++] = RfbProto.EncodingZlib; | |
376 } | |
377 if (preferredEncoding != RfbProto.EncodingCoRRE) { | |
378 encodings[nEncodings++] = RfbProto.EncodingCoRRE; | |
379 } | |
380 if (preferredEncoding != RfbProto.EncodingRRE) { | |
381 encodings[nEncodings++] = RfbProto.EncodingRRE; | |
382 } | |
122 | 383 /* |
13 | 384 if (options.compressLevel >= 0 && options.compressLevel <= 9) { |
385 encodings[nEncodings++] = RfbProto.EncodingCompressLevel0 | |
386 + options.compressLevel; | |
387 } | |
388 if (options.jpegQuality >= 0 && options.jpegQuality <= 9) { | |
389 encodings[nEncodings++] = RfbProto.EncodingQualityLevel0 | |
390 + options.jpegQuality; | |
391 } | |
392 if (options.requestCursorUpdates) { | |
393 encodings[nEncodings++] = RfbProto.EncodingXCursor; | |
394 encodings[nEncodings++] = RfbProto.EncodingRichCursor; | |
395 if (!options.ignoreCursorUpdates) | |
396 encodings[nEncodings++] = RfbProto.EncodingPointerPos; | |
397 } | |
78 | 398 */ |
399 | |
13 | 400 encodings[nEncodings++] = RfbProto.EncodingLastRect; |
401 encodings[nEncodings++] = RfbProto.EncodingNewFBSize; | |
402 | |
403 boolean encodingsWereChanged = false; | |
404 if (nEncodings != nEncodingsSaved) { | |
405 encodingsWereChanged = true; | |
406 } else { | |
407 for (int i = 0; i < nEncodings; i++) { | |
408 if (encodings[i] != encodingsSaved[i]) { | |
409 encodingsWereChanged = true; | |
410 break; | |
411 } | |
412 } | |
413 } | |
414 | |
415 if (encodingsWereChanged) { | |
416 try { | |
122 | 417 rfb.writeSetEncodings(encodings, nEncodings); |
13 | 418 if (vc != null) { |
419 vc.softCursorFree(); | |
420 } | |
421 } catch (Exception e) { | |
422 e.printStackTrace(); | |
423 } | |
424 encodingsSaved = encodings; | |
425 nEncodingsSaved = nEncodings; | |
426 } | |
427 } | |
428 | |
429 // | |
430 // setCutText() - send the given cut text to the RFB server. | |
431 // | |
432 | |
433 void setCutText(String text) { | |
434 try { | |
435 if (rfb != null && rfb.inNormalProtocol) { | |
436 rfb.writeClientCutText(text); | |
437 } | |
438 } catch (Exception e) { | |
439 e.printStackTrace(); | |
440 } | |
441 } | |
442 | |
443 // | |
444 // Order change in session recording status. To stop recording, pass | |
445 // null in place of the fname argument. | |
446 // | |
447 | |
448 void setRecordingStatus(String fname) { | |
449 synchronized (recordingSync) { | |
450 sessionFileName = fname; | |
451 recordingStatusChanged = true; | |
452 } | |
453 } | |
454 | |
455 // | |
456 // Start or stop session recording. Returns true if this method call | |
457 // causes recording of a new session. | |
458 // | |
459 | |
460 boolean checkRecordingStatus() throws IOException { | |
461 synchronized (recordingSync) { | |
462 if (recordingStatusChanged) { | |
463 recordingStatusChanged = false; | |
464 if (sessionFileName != null) { | |
465 startRecording(); | |
466 return true; | |
467 } else { | |
468 stopRecording(); | |
469 } | |
470 } | |
471 } | |
472 return false; | |
473 } | |
474 | |
475 // | |
476 // Start session recording. | |
477 // | |
478 | |
479 protected void startRecording() throws IOException { | |
480 synchronized (recordingSync) { | |
481 if (!recordingActive) { | |
482 // Save settings to restore them after recording the session. | |
483 cursorUpdatesDef = options.choices[options.cursorUpdatesIndex] | |
484 .getSelectedItem(); | |
485 eightBitColorsDef = options.choices[options.eightBitColorsIndex] | |
486 .getSelectedItem(); | |
487 // Set options to values suitable for recording. | |
488 options.choices[options.cursorUpdatesIndex].select("Disable"); | |
489 options.choices[options.cursorUpdatesIndex].setEnabled(false); | |
490 options.setEncodings(); | |
491 options.choices[options.eightBitColorsIndex].select("No"); | |
492 options.choices[options.eightBitColorsIndex].setEnabled(false); | |
493 options.setColorFormat(); | |
494 } else { | |
495 rfb.closeSession(); | |
496 } | |
497 | |
498 System.out.println("Recording the session in " + sessionFileName); | |
499 rfb.startSession(sessionFileName); | |
500 recordingActive = true; | |
501 } | |
502 } | |
503 | |
504 // | |
505 // Stop session recording. | |
506 // | |
507 | |
508 protected void stopRecording() throws IOException { | |
509 synchronized (recordingSync) { | |
510 if (recordingActive) { | |
511 // Restore options. | |
512 options.choices[options.cursorUpdatesIndex] | |
513 .select(cursorUpdatesDef); | |
514 options.choices[options.cursorUpdatesIndex].setEnabled(true); | |
515 options.setEncodings(); | |
516 options.choices[options.eightBitColorsIndex] | |
517 .select(eightBitColorsDef); | |
518 options.choices[options.eightBitColorsIndex].setEnabled(true); | |
519 options.setColorFormat(); | |
520 | |
521 rfb.closeSession(); | |
522 System.out.println("Session recording stopped."); | |
523 } | |
524 sessionFileName = null; | |
525 recordingActive = false; | |
526 } | |
527 } | |
528 | |
529 // | |
530 // readParameters() - read parameters from the html source or from the | |
531 // command line. On the command line, the arguments are just a sequence of | |
532 // param_name/param_value pairs where the names and values correspond to | |
533 // those expected in the html applet tag source. | |
534 // | |
535 | |
536 void readParameters() { | |
537 | |
30 | 538 host = mainArgs[0]; |
31 | 539 if(mainArgs.length < 2){ |
30 | 540 port = 5900; |
541 }else{ | |
31 | 542 port = Integer.parseInt(mainArgs[1]); |
30 | 543 } |
544 | |
13 | 545 |
546 // Read "ENCPASSWORD" or "PASSWORD" parameter if specified. | |
547 // readPasswordParameters(); | |
548 | |
549 String str; | |
550 | |
551 // "Show Controls" set to "No" disables button panel. | |
552 showControls = true; | |
553 str = readParameter("Show Controls", false); | |
554 if (str != null && str.equalsIgnoreCase("No")) | |
555 showControls = false; | |
556 | |
557 // "Offer Relogin" set to "No" disables "Login again" and "Close | |
558 // window" buttons under error messages in applet mode. | |
559 offerRelogin = true; | |
560 str = readParameter("Offer Relogin", false); | |
561 if (str != null && str.equalsIgnoreCase("No")) | |
562 offerRelogin = false; | |
563 | |
564 // Do we continue showing desktop on remote disconnect? | |
565 showOfflineDesktop = false; | |
566 str = readParameter("Show Offline Desktop", false); | |
567 if (str != null && str.equalsIgnoreCase("Yes")) | |
568 showOfflineDesktop = true; | |
569 | |
570 // Fine tuning options. | |
571 deferScreenUpdates = readIntParameter("Defer screen updates", 20); | |
572 deferCursorUpdates = readIntParameter("Defer cursor updates", 10); | |
573 deferUpdateRequests = readIntParameter("Defer update requests", 0); | |
574 | |
575 // Debugging options. | |
576 debugStatsExcludeUpdates = readIntParameter("DEBUG_XU", 0); | |
577 debugStatsMeasureUpdates = readIntParameter("DEBUG_CU", 0); | |
578 | |
579 // SocketFactory. | |
580 socketFactory = readParameter("SocketFactory", false); | |
581 } | |
582 | |
583 // | |
584 // Read password parameters. If an "ENCPASSWORD" parameter is set, | |
585 // then decrypt the password into the passwordParam string. Otherwise, | |
586 // try to read the "PASSWORD" parameter directly to passwordParam. | |
587 // | |
588 | |
589 private void readPasswordParameters() { | |
590 // String encPasswordParam = readParameter("ENCPASSWORD", false); | |
31 | 591 String encPasswordParam = mainArgs[2]; |
13 | 592 |
593 if (encPasswordParam == null) { | |
594 // passwordParam = readParameter("PASSWORD", false); | |
595 | |
596 } else { | |
597 // ENCPASSWORD is hexascii-encoded. Decode. | |
598 byte[] pw = { 0, 0, 0, 0, 0, 0, 0, 0 }; | |
599 int len = encPasswordParam.length() / 2; | |
600 if (len > 8) | |
601 len = 8; | |
602 for (int i = 0; i < len; i++) { | |
603 String hex = encPasswordParam.substring(i * 2, i * 2 + 2); | |
604 Integer x = new Integer(Integer.parseInt(hex, 16)); | |
605 pw[i] = x.byteValue(); | |
606 } | |
607 // Decrypt the password. | |
608 byte[] key = { 23, 82, 107, 6, 35, 78, 88, 7 }; | |
609 DesCipher des = new DesCipher(key); | |
610 des.decrypt(pw, 0, pw, 0); | |
611 passwordParam = new String(pw); | |
612 | |
613 } | |
614 } | |
615 | |
616 public String readParameter(String name, boolean required) { | |
617 for (int i = 0; i < mainArgs.length; i += 2) { | |
618 if (mainArgs[i].equalsIgnoreCase(name)) { | |
619 try { | |
620 return mainArgs[i + 1]; | |
621 } catch (Exception e) { | |
622 if (required) { | |
623 fatalError(name + " parameter not specified"); | |
624 } | |
625 return null; | |
626 } | |
627 } | |
628 } | |
629 if (required) { | |
630 fatalError(name + " parameter not specified"); | |
631 } | |
632 return null; | |
633 } | |
634 | |
635 int readIntParameter(String name, int defaultValue) { | |
636 String str = readParameter(name, false); | |
637 int result = defaultValue; | |
638 if (str != null) { | |
639 try { | |
640 result = Integer.parseInt(str); | |
641 } catch (NumberFormatException e) { | |
642 } | |
643 } | |
644 return result; | |
645 } | |
646 | |
647 // | |
648 // disconnect() - close connection to server. | |
649 // | |
650 | |
651 synchronized public void disconnect() { | |
652 System.out.println("Disconnecting"); | |
653 | |
654 if (vc != null) { | |
655 double sec = (System.currentTimeMillis() - vc.statStartTime) / 1000.0; | |
656 double rate = Math.round(vc.statNumUpdates / sec * 100) / 100.0; | |
657 int nRealRects = vc.statNumPixelRects; | |
658 int nPseudoRects = vc.statNumTotalRects - vc.statNumPixelRects; | |
659 System.out.println("Updates received: " + vc.statNumUpdates + " (" | |
660 + nRealRects + " rectangles + " + nPseudoRects | |
661 + " pseudo), " + rate + " updates/sec"); | |
662 int numRectsOther = nRealRects - vc.statNumRectsTight | |
663 - vc.statNumRectsZRLE - vc.statNumRectsHextile | |
664 - vc.statNumRectsRaw - vc.statNumRectsCopy; | |
665 System.out.println("Rectangles:" + " Tight=" + vc.statNumRectsTight | |
666 + "(JPEG=" + vc.statNumRectsTightJPEG + ") ZRLE=" | |
667 + vc.statNumRectsZRLE + " Hextile=" | |
668 + vc.statNumRectsHextile + " Raw=" + vc.statNumRectsRaw | |
669 + " CopyRect=" + vc.statNumRectsCopy + " other=" | |
670 + numRectsOther); | |
671 | |
672 int raw = vc.statNumBytesDecoded; | |
673 int compressed = vc.statNumBytesEncoded; | |
674 if (compressed > 0) { | |
675 double ratio = Math.round((double) raw / compressed * 1000) / 1000.0; | |
676 System.out.println("Pixel data: " + vc.statNumBytesDecoded | |
677 + " bytes, " + vc.statNumBytesEncoded | |
678 + " compressed, ratio " + ratio); | |
679 } | |
680 } | |
681 | |
682 if (rfb != null && !rfb.closed()) | |
683 rfb.close(); | |
67 | 684 // options.dispose(); |
13 | 685 clipboard.dispose(); |
686 if (rec != null) | |
687 rec.dispose(); | |
688 | |
689 System.exit(0); | |
690 | |
691 } | |
692 | |
693 // | |
694 // fatalError() - print out a fatal error message. | |
695 // FIXME: Do we really need two versions of the fatalError() method? | |
696 // | |
697 | |
698 synchronized public void fatalError(String str) { | |
699 System.out.println(str); | |
700 System.exit(1); | |
701 } | |
702 | |
703 synchronized public void fatalError(String str, Exception e) { | |
704 | |
705 if (rfb != null && rfb.closed()) { | |
706 // Not necessary to show error message if the error was caused | |
707 // by I/O problems after the rfb.close() method call. | |
708 System.out.println("RFB thread finished"); | |
709 return; | |
710 } | |
711 | |
712 System.out.println(str); | |
713 e.printStackTrace(); | |
714 | |
715 if (rfb != null) | |
716 rfb.close(); | |
717 | |
718 System.exit(1); | |
719 | |
720 } | |
721 | |
722 // | |
723 // Show message text and optionally "Relogin" and "Close" buttons. | |
724 // | |
725 | |
726 void showMessage(String msg) { | |
727 vncContainer.removeAll(); | |
728 | |
729 Label errLabel = new Label(msg, Label.CENTER); | |
730 errLabel.setFont(new Font("Helvetica", Font.PLAIN, 12)); | |
731 | |
732 if (offerRelogin) { | |
733 /* | |
734 * Panel gridPanel = new Panel(new GridLayout(0, 1)); Panel | |
735 * outerPanel = new Panel(new FlowLayout(FlowLayout.LEFT)); | |
736 * outerPanel.add(gridPanel); vncContainer.setLayout(new | |
737 * FlowLayout(FlowLayout.LEFT, 30, 16)); | |
738 * vncContainer.add(outerPanel); Panel textPanel = new Panel(new | |
739 * FlowLayout(FlowLayout.CENTER)); textPanel.add(errLabel); | |
740 * gridPanel.add(textPanel); gridPanel.add(new ReloginPanel(this)); | |
741 */ | |
742 } else { | |
743 /* | |
744 * vncContainer.setLayout(new FlowLayout(FlowLayout.LEFT, 30, 30)); | |
745 * vncContainer.add(errLabel); | |
746 */ | |
747 } | |
748 | |
749 } | |
750 | |
751 // | |
752 // Stop the applet. | |
753 // Main applet thread will terminate on first exception | |
754 // after seeing that rfbThread has been set to null. | |
755 // | |
756 | |
757 public void stop() { | |
758 System.out.println("Stopping applet"); | |
759 rfbThread = null; | |
760 } | |
761 | |
762 // | |
763 // This method is called before the applet is destroyed. | |
764 // | |
765 | |
766 public void destroy() { | |
767 System.out.println("Destroying applet"); | |
768 | |
769 vncContainer.removeAll(); | |
67 | 770 // options.dispose(); |
13 | 771 clipboard.dispose(); |
772 if (rec != null) | |
773 rec.dispose(); | |
774 if (rfb != null && !rfb.closed()) | |
775 rfb.close(); | |
776 } | |
777 | |
778 // | |
779 // Start/stop receiving mouse events. | |
780 // | |
781 | |
782 public void enableInput(boolean enable) { | |
783 vc.enableInput(enable); | |
784 } | |
785 | |
786 // | |
787 // Close application properly on window close event. | |
788 // | |
789 | |
790 public void windowClosing(WindowEvent evt) { | |
791 System.out.println("Closing window"); | |
792 if (rfb != null) | |
793 disconnect(); | |
794 | |
795 vncContainer.hide(); | |
796 | |
797 } | |
798 | |
799 // | |
800 // Ignore window events we're not interested in. | |
801 // | |
802 | |
803 public void windowActivated(WindowEvent evt) { | |
804 } | |
805 | |
806 public void windowDeactivated(WindowEvent evt) { | |
807 } | |
808 | |
809 public void windowOpened(WindowEvent evt) { | |
810 } | |
811 | |
812 public void windowClosed(WindowEvent evt) { | |
813 } | |
814 | |
815 public void windowIconified(WindowEvent evt) { | |
816 } | |
817 | |
818 public void windowDeiconified(WindowEvent evt) { | |
819 } | |
820 } |