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