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