0
|
1 package treeVnc;
|
|
2
|
|
3 import java.awt.*;
|
|
4 import java.awt.event.*;
|
|
5 import java.io.*;
|
|
6 import java.net.*;
|
|
7 import java.util.Random;
|
|
8
|
|
9 import java.nio.ByteBuffer;
|
|
10
|
|
11 public class MyVncClient extends VncViewer implements InterfaceForViewer,
|
|
12 java.lang.Runnable, WindowListener {
|
|
13
|
|
14 /**
|
|
15 *
|
|
16 */
|
|
17 private static final long serialVersionUID = 1L;
|
|
18 private boolean inAnApplet = true;
|
|
19 private boolean inSeparateFrame = false;
|
|
20 private Socket clientSocket = null;
|
|
21 private String parent, treenum;
|
|
22 private String leaderflag;
|
|
23 // private boolean runflag = false;
|
|
24 private boolean first = true;
|
|
25
|
|
26 private EchoClient echoValue;
|
|
27 private int echoPort;
|
|
28 private String pHost;
|
|
29 private TextBoxClient getHost;
|
|
30 private GetBroadCastClient getBcast;
|
|
31 private Thread runBcast;
|
|
32 private BroadCastClient bCast;
|
|
33 boolean isClient = false;
|
|
34
|
|
35 //
|
|
36 // main() is called when run as a java program from the command line.
|
|
37 // It simply runs the applet inside a newly-created frame.
|
|
38 //
|
|
39
|
|
40 public void treeVncClient(String[] argv) {
|
|
41 isClient = true;
|
|
42 MyVncClient v = new MyVncClient();
|
|
43 v.echoValue = null;
|
|
44 v.runClient(argv);
|
|
45 }
|
|
46
|
|
47 private void runClient(String[] argv) {
|
|
48 mainArgs = argv;
|
|
49 System.out.println(mainArgs.length);
|
|
50 inAnApplet = false;
|
|
51 inSeparateFrame = true;
|
|
52 if (mainArgs.length != 0) {
|
|
53 if ("-c".equals(argv[0])) {
|
|
54 if(argv.length==3){
|
|
55 pHost = argv[1];
|
|
56 port = Integer.parseInt(argv[2]);
|
3
|
57 } else {
|
0
|
58 getHost = new TextBoxClient();
|
|
59 getHost.ipRegister();
|
|
60 pHost = getHost.getAddressOption();
|
|
61 port = Integer.parseInt(getHost.getPortOption());
|
|
62 }
|
|
63 } else {
|
|
64 bCast = new BroadCastClient("who");
|
|
65 bCast.createSocket();
|
|
66 bCast.sendData();
|
|
67 getBcast = new GetBroadCastClient();
|
|
68 if ("-reg".equals(argv[0]) && getNamePort() != null) {
|
|
69 getBcast.text.checkBox(getNamePort());
|
|
70 getBcast.text.setButton();
|
|
71 getBcast.text.visible();
|
|
72 } else {
|
|
73 runBcast = new Thread(getBcast);
|
|
74 runBcast.start();
|
|
75 getBcast.setStopFlag(true);
|
|
76 }
|
|
77 pHost = getBcast.text.getAddress();
|
|
78 port = Integer.parseInt(getBcast.text.getPort());
|
|
79 if (!("-reg".equals(argv[0])))
|
|
80 getBcast.socketClose();
|
|
81 }
|
|
82 } else {
|
|
83 bCast = new BroadCastClient("who");
|
|
84 bCast.createSocket();
|
|
85 bCast.sendData();
|
|
86 getBcast = new GetBroadCastClient();
|
|
87 runBcast = new Thread(getBcast);
|
|
88 runBcast.start();
|
|
89 getBcast.setStopFlag(true);
|
|
90 pHost = getBcast.text.getAddress();
|
3
|
91 if("notFound".equals(pHost)) {
|
|
92 getHost = new TextBoxClient();
|
|
93 getHost.ipRegister();
|
|
94 pHost = getHost.getAddressOption();
|
|
95 port = Integer.parseInt(getHost.getPortOption());
|
|
96 } else {
|
|
97 port = Integer.parseInt(getBcast.text.getPort());
|
|
98 }
|
0
|
99 }
|
|
100
|
|
101 // getBcast.text.checkBox(getNamePort());
|
|
102 /*
|
|
103 * try { Thread.sleep(1000); } catch (InterruptedException e) {
|
|
104 * e.printStackTrace(); }
|
|
105 */
|
|
106
|
|
107 /*
|
|
108 *
|
|
109 * if(mainArgs.length == 0) getBcast.setStopFlag(true); else { getHost =
|
|
110 * new TextBoxClient(); getHost.ipRegister(); }
|
|
111 *
|
|
112 * if (mainArgs.length > 0) pHost = getHost.getAddressOption(); //pHost
|
|
113 * = mainArgs[0]; else { pHost = getBcast.text.getAddress(); }
|
|
114 *
|
|
115 *
|
|
116 * //pHost = "cls080.ie.u-ryukyu.ac.jp"; if (mainArgs.length > 0) port =
|
|
117 * Integer.parseInt(getHost.getPortOption()); //port =
|
|
118 * Integer.parseInt(mainArgs[1]); else { port =
|
|
119 * Integer.parseInt(getBcast.text.getPort()); getBcast.socketClose(); //
|
|
120 * port = 5999; }
|
|
121 */
|
|
122 init();
|
|
123 start_threads();
|
|
124 start();
|
|
125
|
|
126 }
|
|
127
|
|
128 public void init() {
|
|
129
|
|
130 readParameters();
|
|
131
|
|
132 refApplet = this;
|
|
133
|
|
134 if (inSeparateFrame) {
|
|
135 vncFrame = new Frame("TightVNC");
|
|
136 if (!inAnApplet) {
|
|
137 vncFrame.add("Center", this);
|
|
138 }
|
|
139 vncContainer = vncFrame;
|
|
140 } else {
|
|
141 vncContainer = this;
|
|
142 }
|
|
143
|
|
144 recordingSync = new Object();
|
|
145
|
|
146 options = new OptionsFrame(this);
|
|
147 clipboard = new ClipboardFrame(this);
|
|
148 if (RecordingFrame.checkSecurity())
|
|
149 rec = new RecordingFrame(this);
|
|
150
|
|
151 sessionFileName = null;
|
|
152 recordingActive = false;
|
|
153 recordingStatusChanged = false;
|
|
154 cursorUpdatesDef = null;
|
|
155 eightBitColorsDef = null;
|
|
156
|
|
157 if (inSeparateFrame)
|
|
158 vncFrame.addWindowListener(this);
|
|
159
|
|
160 rfbThread = new Thread(this);
|
|
161 }
|
|
162
|
|
163 public void update(Graphics g) {
|
|
164 }
|
|
165
|
|
166 //
|
|
167 // run() - executed by the rfbThread to deal with the RFB socket.
|
|
168 //
|
|
169
|
|
170 public void start_threads() {
|
|
171 rfbThread.start();
|
|
172 }
|
|
173
|
|
174 public void run() {
|
|
175
|
|
176 gridbag = new GridBagLayout();
|
|
177 vncContainer.setLayout(gridbag);
|
|
178
|
|
179 GridBagConstraints gbc = new GridBagConstraints();
|
|
180 gbc.gridwidth = GridBagConstraints.REMAINDER;
|
|
181 gbc.anchor = GridBagConstraints.NORTHWEST;
|
|
182
|
|
183 if (showControls) {
|
|
184 buttonPanel = new ButtonPanel(this);
|
|
185 gridbag.setConstraints(buttonPanel, gbc);
|
|
186 vncContainer.add(buttonPanel);
|
|
187 }
|
|
188
|
|
189 try {
|
|
190
|
|
191 if (first) {
|
|
192 connectAndAuthenticate();
|
1
|
193 //accThread = new Thread(new AcceptThread(rfb, 5999));
|
|
194 //accThread.start();
|
0
|
195 first = false;
|
|
196 } else {
|
|
197 System.out.println("reConnectAndAuthenticate() ");
|
|
198 reConnectAndAuthenticate();
|
|
199 // accThread = new Thread(new AcceptThread(rfb, 5999));
|
|
200 // accThread.start();
|
|
201 }
|
|
202
|
|
203 doProtocolInitialisation();
|
|
204
|
|
205 createCanvas(0, 0);
|
|
206
|
|
207 } catch (IOException e) {
|
|
208 try {
|
|
209 rfb.sock.close();
|
|
210
|
|
211 } catch (IOException e2) {
|
|
212 e2.printStackTrace();
|
|
213 }
|
|
214 System.out.println("Socket error");
|
|
215 // parent no find
|
|
216 Random rnd = new Random();
|
|
217 long ran = rnd.nextInt(3000) + 3000;
|
|
218 System.out.println(ran);
|
|
219
|
|
220 /**
|
|
221 * this while reconnection
|
|
222 */
|
|
223
|
|
224 int counter = 0;
|
|
225 vncFrame.setVisible(false);
|
|
226 vncFrame.dispose();
|
|
227
|
|
228 while (true) {
|
|
229 /**
|
|
230 * if my last node case reconnectoion stop
|
|
231 */
|
|
232
|
|
233 echoValue = new EchoClient(echoValue, this);
|
|
234 // echoValue = new EchoClient(echoValue);
|
|
235
|
|
236 try {
|
|
237 Thread.sleep(ran);
|
|
238 } catch (InterruptedException e1) {
|
|
239 e1.printStackTrace();
|
|
240 }
|
|
241
|
|
242 if (counter >= 3) {
|
|
243 echoValue.openport();
|
2
|
244 echoValue.notFoundParent();
|
0
|
245 }
|
|
246
|
|
247 echoValue.openport();
|
|
248
|
|
249 if (echoValue.lostHost()) {
|
|
250 break;
|
|
251 }
|
|
252
|
|
253 counter++;
|
|
254 }
|
|
255 } catch (Exception e) {
|
|
256 System.out.println(e);
|
|
257 System.exit(0);
|
|
258 }
|
|
259 gbc.weightx = 1.0;
|
|
260 gbc.weighty = 1.0;
|
|
261
|
|
262 if (inSeparateFrame) {
|
|
263 // Create a panel which itself is resizeable and can hold
|
|
264 // non-resizeable VncCanvas component at the top left corner.
|
|
265 Panel canvasPanel = new Panel();
|
|
266 canvasPanel.setLayout(new FlowLayout(FlowLayout.LEFT, 0, 0));
|
|
267 canvasPanel.add(vc);
|
|
268 // Create a ScrollPane which will hold a panel with VncCanvas
|
|
269 // inside.
|
|
270 desktopScrollPane = new ScrollPane(ScrollPane.SCROLLBARS_AS_NEEDED);
|
|
271 gbc.fill = GridBagConstraints.BOTH;
|
|
272 gridbag.setConstraints(desktopScrollPane, gbc);
|
|
273 desktopScrollPane.add(canvasPanel);
|
|
274 // Finally, add our ScrollPane to the Frame window.
|
|
275 vncFrame.add(desktopScrollPane);
|
|
276 vncFrame.setTitle(rfb.desktopName);
|
|
277 vncFrame.pack();
|
|
278 vc.resizeDesktopFrame();
|
|
279 } else {
|
|
280 // Just add the VncCanvas component to the Applet.
|
|
281 gridbag.setConstraints(vc, gbc);
|
|
282 add(vc);
|
|
283 validate();
|
|
284
|
|
285 }
|
|
286
|
|
287 try {
|
|
288 if (showControls)
|
|
289 buttonPanel.enableButtons();
|
|
290
|
|
291 moveFocusToDesktop();
|
|
292
|
|
293 processNormalProtocol();// main loop
|
|
294
|
|
295 } catch (NoRouteToHostException e) {
|
|
296 fatalError("Network error: no route to server: " + host, e);
|
|
297 } catch (UnknownHostException e) {
|
|
298 fatalError("Network error: server name unknown: " + host, e);
|
|
299 } catch (ConnectException e) {
|
|
300 fatalError("Network error: could not connect to server: " + host
|
|
301 + ":" + port, e);
|
|
302 } catch (EOFException e) {
|
|
303
|
|
304 vncFrame.setVisible(false);
|
|
305 vncFrame.dispose();
|
|
306 // num4
|
|
307 if (leaderflag != null) {
|
|
308 while (true) {
|
|
309 // echoValue = new EchoClient(echoValue, this);
|
|
310 echoValue = new EchoClient(echoValue);
|
|
311 echoValue.openport();
|
|
312 // runflag = echo.losthost();
|
|
313 if (echoValue.lostHost()) {
|
|
314 break;
|
|
315 }
|
|
316
|
|
317 }
|
|
318 } else {
|
|
319
|
|
320 if (showOfflineDesktop) {
|
|
321 e.printStackTrace();
|
|
322 System.out
|
|
323 .println("Network error: remote side closed connection");
|
|
324 if (vc != null) {
|
|
325 vc.enableInput(false);
|
|
326 }
|
|
327 if (inSeparateFrame) {
|
|
328 vncFrame.setTitle(rfb.desktopName + " [disconnected]");
|
|
329 }
|
|
330 if (rfb != null && !rfb.closed())
|
|
331 rfb.close();
|
|
332 if (showControls && buttonPanel != null) {
|
|
333 buttonPanel.disableButtonsOnDisconnect();
|
|
334 if (inSeparateFrame) {
|
|
335 vncFrame.pack();
|
|
336 } else {
|
|
337 validate();
|
|
338 }
|
|
339 }
|
|
340 } else {
|
|
341 fatalError("Network error: remote side closed connection",
|
|
342 e);
|
|
343 }
|
|
344 }
|
|
345 } catch (IOException e) {
|
|
346 String str = e.getMessage();
|
|
347 if (str != null && str.length() != 0) {
|
|
348 fatalError("Network Error: " + str, e);
|
|
349 } else {
|
|
350 fatalError(e.toString(), e);
|
|
351 }
|
|
352 } catch (Exception e) {
|
|
353 String str = e.getMessage();
|
|
354 if (str != null && str.length() != 0) {
|
|
355 fatalError("Error: " + str, e);
|
|
356 } else {
|
|
357 fatalError(e.toString(), e);
|
|
358 }
|
|
359 }
|
|
360
|
|
361 }
|
|
362
|
|
363 //
|
|
364 // Create a VncCanvas instance.
|
|
365 //
|
|
366
|
|
367 void createCanvas(int maxWidth, int maxHeight) throws IOException {
|
|
368 // Determine if Java 2D API is available and use a special
|
|
369 // version of VncCanvas if it is present.
|
|
370 vc = null;
|
|
371 try {
|
|
372 // This throws ClassNotFoundException if there is no Java 2D API.
|
|
373 Class cl = Class.forName("java.awt.Graphics2D");
|
|
374 // If we could load Graphics2D class, then we can use VncCanvas2D.
|
|
375 cl = Class.forName("VncCanvas2");
|
|
376 Class[] argClasses = { this.getClass(), Integer.TYPE, Integer.TYPE };
|
|
377 java.lang.reflect.Constructor cstr = cl.getConstructor(argClasses);
|
|
378 Object[] argObjects = { this, new Integer(maxWidth),
|
|
379 new Integer(maxHeight) };
|
|
380 vc = (VncCanvas) cstr.newInstance(argObjects);
|
|
381 } catch (Exception e) {
|
|
382 System.out.println("Warning: Java 2D API is not available");
|
|
383 }
|
|
384
|
|
385 // If we failed to create VncCanvas2D, use old VncCanvas.
|
|
386 if (vc == null)
|
|
387 vc = new VncCanvas(this, maxWidth, maxHeight);
|
|
388 }
|
|
389
|
|
390 //
|
|
391 // Process RFB socket messages.
|
|
392 // If the rfbThread is being stopped, ignore any exceptions,
|
|
393 // otherwise rethrow the exception so it can be handled.
|
|
394 //
|
|
395
|
|
396 void processNormalProtocol() throws Exception {
|
|
397 try {
|
|
398 vc.processNormalProtocol();// main loop
|
|
399 } catch (Exception e) {
|
|
400 if (rfbThread == null) {
|
|
401 System.out.println("Ignoring RFB socket exceptions"
|
|
402 + " because applet is stopping");
|
|
403 } else {
|
|
404 throw e;
|
|
405 }
|
|
406 }
|
|
407 }
|
|
408
|
|
409 //
|
|
410 // Connect to the RFB server and authenticate the user.
|
|
411 //
|
|
412
|
|
413 void connectAndAuthenticate() throws Exception {
|
|
414
|
|
415 showConnectionStatus("Initializing...");
|
|
416 if (inSeparateFrame) {
|
|
417 vncFrame.pack();
|
|
418 vncFrame.setVisible(true);
|
|
419 } else {
|
|
420 validate();
|
|
421 }
|
|
422
|
|
423 showConnectionStatus("Connecting to " + host + ", port " + port + "...");
|
|
424
|
|
425 rfb = new MyRfbProtoClient(pHost, port, this);
|
|
426 showConnectionStatus("Connected to server");
|
|
427
|
|
428 rfb.readVersionMsg();
|
|
429 showConnectionStatus("RFB server supports protocol version "
|
|
430 + rfb.serverMajor + "." + rfb.serverMinor);
|
|
431
|
|
432 rfb.writeVersionMsg();
|
|
433 showConnectionStatus("Using RFB protocol version " + rfb.clientMajor
|
|
434 + "." + rfb.clientMinor);
|
|
435
|
|
436 if (rfb.serverMinor == 855) {
|
|
437 /*
|
|
438 * if connect to proxy, userEchoPortFlag is true. if connect to
|
|
439 * client, userEchoPortFlag is false.
|
|
440 */
|
|
441 boolean useEchoPortFlag = rfb.readProxyFlag();
|
|
442 if (useEchoPortFlag) {
|
|
443 byte[] b = new byte[4];
|
|
444 b = rfb.readEchoPort();
|
|
445 echoPort = castByteInt(b);
|
|
446
|
|
447 InetAddress addr = InetAddress.getByName(pHost);
|
|
448 String h = new String(addr.getHostAddress());
|
|
449
|
|
450 getParentName();
|
|
451 if (!(h.equals(host))) {
|
|
452 rfb.changeParent(host, port);
|
|
453 rfb.readVersionMsg();
|
|
454 rfb.writeVersionMsg();
|
|
455 boolean flag = rfb.readProxyFlag();
|
|
456 }
|
|
457 }
|
|
458 }
|
|
459
|
|
460 int secType = rfb.negotiateSecurity();
|
|
461 int authType;
|
|
462 if (secType == RfbProto.SecTypeTight) {
|
|
463 showConnectionStatus("Enabling TightVNC protocol extensions");
|
|
464 rfb.setupTunneling();
|
|
465 authType = rfb.negotiateAuthenticationTight();
|
|
466 } else {
|
|
467 authType = secType;
|
|
468 }
|
|
469
|
|
470 switch (authType) {
|
|
471 case RfbProto.AuthNone:
|
|
472 showConnectionStatus("No authentication needed");
|
|
473 rfb.authenticateNone();
|
|
474 break;
|
|
475 case RfbProto.AuthVNC:
|
|
476 showConnectionStatus("Performing standard VNC authentication");
|
|
477 if (passwordParam != null) {
|
|
478 rfb.authenticateVNC(passwordParam);
|
|
479 } else {
|
|
480 String pw = askPassword();
|
|
481 rfb.authenticateVNC(pw);
|
|
482 }
|
|
483 break;
|
|
484 default:
|
|
485 throw new Exception("Unknown authentication scheme " + authType);
|
|
486 }
|
|
487 }
|
|
488
|
|
489 void reConnectAndAuthenticate() throws Exception {
|
|
490
|
|
491 showConnectionStatus("Initializing...");
|
|
492
|
|
493 if (inSeparateFrame) {
|
|
494 vncFrame.pack();
|
|
495 vncFrame.setVisible(true);
|
|
496 } else {
|
|
497 validate();
|
|
498 }
|
|
499
|
|
500 showConnectionStatus("Connecting to " + host + ", port " + port + "...");
|
|
501
|
|
502 rfb.changeParent(host, port);
|
|
503
|
|
504 showConnectionStatus("Connected to server");
|
|
505
|
|
506 rfb.readVersionMsg();
|
|
507 showConnectionStatus("RFB server supports protocol version "
|
|
508 + rfb.serverMajor + "." + rfb.serverMinor);
|
|
509
|
|
510 rfb.writeVersionMsg();
|
|
511 showConnectionStatus("Using RFB protocol version " + rfb.clientMajor
|
|
512 + "." + rfb.clientMinor);
|
|
513
|
|
514 if (rfb.serverMinor == 855) {
|
|
515 boolean useEchoPortFlag = rfb.readProxyFlag();
|
|
516 if (useEchoPortFlag) {
|
|
517 byte[] b = new byte[4];
|
|
518 b = rfb.readEchoPort();
|
|
519 echoPort = castByteInt(b);
|
|
520
|
|
521 InetAddress addr = InetAddress.getByName(pHost);
|
|
522 String h = new String(addr.getHostAddress());
|
|
523
|
|
524 getParentName();
|
|
525 if (!(h.equals(host))) {
|
|
526 rfb.changeParent(host, port);
|
|
527 rfb.readVersionMsg();
|
|
528 rfb.writeVersionMsg();
|
|
529 boolean flag = rfb.readProxyFlag();
|
|
530 }
|
|
531 }
|
|
532 }
|
|
533 int secType = rfb.negotiateSecurity();
|
|
534 int authType;
|
|
535 if (secType == RfbProto.SecTypeTight) {
|
|
536 showConnectionStatus("Enabling TightVNC protocol extensions");
|
|
537 rfb.setupTunneling();
|
|
538 authType = rfb.negotiateAuthenticationTight();
|
|
539 } else {
|
|
540 authType = secType;
|
|
541 }
|
|
542
|
|
543 switch (authType) {
|
|
544 case RfbProto.AuthNone:
|
|
545 showConnectionStatus("No authentication needed");
|
|
546 rfb.authenticateNone();
|
|
547 break;
|
|
548 case RfbProto.AuthVNC:
|
|
549 showConnectionStatus("Performing standard VNC authentication");
|
|
550 if (passwordParam != null) {
|
|
551 rfb.authenticateVNC(passwordParam);
|
|
552 } else {
|
|
553 String pw = askPassword();
|
|
554 rfb.authenticateVNC(pw);
|
|
555 }
|
|
556 break;
|
|
557 default:
|
|
558 throw new Exception("Unknown authentication scheme " + authType);
|
|
559 }
|
|
560 }
|
|
561
|
|
562 //
|
|
563 // Show a message describing the connection status.
|
|
564 // To hide the connection status label, use (msg == null).
|
|
565 //
|
|
566
|
|
567 void showConnectionStatus(String msg) {
|
|
568 if (msg == null) {
|
|
569 if (vncContainer.isAncestorOf(connStatusLabel)) {
|
|
570 vncContainer.remove(connStatusLabel);
|
|
571 }
|
|
572 return;
|
|
573 }
|
|
574
|
|
575 System.out.println(msg);
|
|
576
|
|
577 if (connStatusLabel == null) {
|
|
578 connStatusLabel = new Label("Status: " + msg);
|
|
579 connStatusLabel.setFont(new Font("Helvetica", Font.PLAIN, 12));
|
|
580 } else {
|
|
581 connStatusLabel.setText("Status: " + msg);
|
|
582 }
|
|
583
|
|
584 if (!vncContainer.isAncestorOf(connStatusLabel)) {
|
|
585 GridBagConstraints gbc = new GridBagConstraints();
|
|
586 gbc.gridwidth = GridBagConstraints.REMAINDER;
|
|
587 gbc.fill = GridBagConstraints.HORIZONTAL;
|
|
588 gbc.anchor = GridBagConstraints.NORTHWEST;
|
|
589 gbc.weightx = 1.0;
|
|
590 gbc.weighty = 1.0;
|
|
591 gbc.insets = new Insets(20, 30, 20, 30);
|
|
592 gridbag.setConstraints(connStatusLabel, gbc);
|
|
593 vncContainer.add(connStatusLabel);
|
|
594 }
|
|
595
|
|
596 if (inSeparateFrame) {
|
|
597 vncFrame.pack();
|
|
598 } else {
|
|
599 validate();
|
|
600 }
|
|
601 }
|
|
602
|
|
603 //
|
|
604 // Show an authentication panel.
|
|
605 //
|
|
606
|
|
607 String askPassword() throws Exception {
|
|
608 showConnectionStatus(null);
|
|
609
|
|
610 AuthPanel authPanel = new AuthPanel(this);
|
|
611
|
|
612 GridBagConstraints gbc = new GridBagConstraints();
|
|
613 gbc.gridwidth = GridBagConstraints.REMAINDER;
|
|
614 gbc.anchor = GridBagConstraints.NORTHWEST;
|
|
615 gbc.weightx = 1.0;
|
|
616 gbc.weighty = 1.0;
|
|
617 gbc.ipadx = 100;
|
|
618 gbc.ipady = 50;
|
|
619 gridbag.setConstraints(authPanel, gbc);
|
|
620 vncContainer.add(authPanel);
|
|
621
|
|
622 if (inSeparateFrame) {
|
|
623 vncFrame.pack();
|
|
624 } else {
|
|
625 validate();
|
|
626 }
|
|
627
|
|
628 authPanel.moveFocusToDefaultField();
|
|
629 String pw = authPanel.getPassword();
|
|
630 vncContainer.remove(authPanel);
|
|
631 return pw;
|
|
632 }
|
|
633
|
|
634 //
|
|
635 // Do the rest of the protocol initialisation.
|
|
636 //
|
|
637
|
|
638 void doProtocolInitialisation() throws IOException {
|
|
639 rfb.writeClientInit();
|
|
640 rfb.readServerInit();
|
|
641
|
|
642 System.out.println("Desktop name is " + rfb.desktopName);
|
|
643 System.out.println("Desktop size is " + rfb.framebufferWidth + " x "
|
|
644 + rfb.framebufferHeight);
|
|
645
|
|
646 setEncodings();
|
|
647
|
|
648 showConnectionStatus(null);
|
|
649 }
|
|
650
|
|
651 //
|
|
652 // Send current encoding list to the RFB server.
|
|
653 //
|
|
654
|
|
655 int[] encodingsSaved;
|
|
656 int nEncodingsSaved;
|
|
657
|
|
658 void setEncodings() {
|
|
659 setEncodings(false);
|
|
660 }
|
|
661
|
|
662 void autoSelectEncodings() {
|
|
663 setEncodings(true);
|
|
664 }
|
|
665
|
|
666 void setEncodings(boolean autoSelectOnly) {
|
|
667 if (options == null || rfb == null || !rfb.inNormalProtocol)
|
|
668 return;
|
|
669
|
|
670 int preferredEncoding = options.preferredEncoding;
|
|
671 if (preferredEncoding == -1) {
|
|
672 long kbitsPerSecond = rfb.kbitsPerSecond();
|
|
673 if (nEncodingsSaved < 1) {
|
|
674 // Choose Tight or ZRLE encoding for the very first update.
|
|
675 System.out.println("Using Tight/ZRLE encodings");
|
|
676 preferredEncoding = RfbProto.EncodingTight;
|
|
677 } else if (kbitsPerSecond > 2000
|
|
678 && encodingsSaved[0] != RfbProto.EncodingHextile) {
|
|
679 // Switch to Hextile if the connection speed is above 2Mbps.
|
|
680 System.out.println("Throughput " + kbitsPerSecond
|
|
681 + " kbit/s - changing to Hextile encoding");
|
|
682 preferredEncoding = RfbProto.EncodingHextile;
|
|
683 } else if (kbitsPerSecond < 1000
|
|
684 && encodingsSaved[0] != RfbProto.EncodingTight) {
|
|
685 // Switch to Tight/ZRLE if the connection speed is below 1Mbps.
|
|
686 System.out.println("Throughput " + kbitsPerSecond
|
|
687 + " kbit/s - changing to Tight/ZRLE encodings");
|
|
688 preferredEncoding = RfbProto.EncodingTight;
|
|
689 } else {
|
|
690 // Don't change the encoder.
|
|
691 if (autoSelectOnly)
|
|
692 return;
|
|
693 preferredEncoding = encodingsSaved[0];
|
|
694 }
|
|
695 } else {
|
|
696 // Auto encoder selection is not enabled.
|
|
697 if (autoSelectOnly)
|
|
698 return;
|
|
699 }
|
|
700
|
|
701 int[] encodings = new int[20];
|
|
702 int nEncodings = 0;
|
|
703
|
|
704 encodings[nEncodings++] = preferredEncoding;
|
|
705 if (options.useCopyRect) {
|
|
706 encodings[nEncodings++] = RfbProto.EncodingCopyRect;
|
|
707 }
|
|
708
|
|
709 if (preferredEncoding != RfbProto.EncodingTight) {
|
|
710 encodings[nEncodings++] = RfbProto.EncodingTight;
|
|
711 }
|
|
712 if (preferredEncoding != RfbProto.EncodingZRLE) {
|
|
713 encodings[nEncodings++] = RfbProto.EncodingZRLE;
|
|
714 }
|
|
715 if (preferredEncoding != RfbProto.EncodingHextile) {
|
|
716 encodings[nEncodings++] = RfbProto.EncodingHextile;
|
|
717 }
|
|
718 if (preferredEncoding != RfbProto.EncodingZlib) {
|
|
719 encodings[nEncodings++] = RfbProto.EncodingZlib;
|
|
720 }
|
|
721 if (preferredEncoding != RfbProto.EncodingCoRRE) {
|
|
722 encodings[nEncodings++] = RfbProto.EncodingCoRRE;
|
|
723 }
|
|
724 if (preferredEncoding != RfbProto.EncodingRRE) {
|
|
725 encodings[nEncodings++] = RfbProto.EncodingRRE;
|
|
726 }
|
|
727
|
|
728 if (options.compressLevel >= 0 && options.compressLevel <= 9) {
|
|
729 encodings[nEncodings++] = RfbProto.EncodingCompressLevel0
|
|
730 + options.compressLevel;
|
|
731 }
|
|
732 if (options.jpegQuality >= 0 && options.jpegQuality <= 9) {
|
|
733 encodings[nEncodings++] = RfbProto.EncodingQualityLevel0
|
|
734 + options.jpegQuality;
|
|
735 }
|
|
736
|
|
737 if (options.requestCursorUpdates) {
|
|
738 encodings[nEncodings++] = RfbProto.EncodingXCursor;
|
|
739 encodings[nEncodings++] = RfbProto.EncodingRichCursor;
|
|
740 if (!options.ignoreCursorUpdates)
|
|
741 encodings[nEncodings++] = RfbProto.EncodingPointerPos;
|
|
742 }
|
|
743
|
|
744 encodings[nEncodings++] = RfbProto.EncodingLastRect;
|
|
745 encodings[nEncodings++] = RfbProto.EncodingNewFBSize;
|
|
746
|
|
747 boolean encodingsWereChanged = false;
|
|
748 if (nEncodings != nEncodingsSaved) {
|
|
749 encodingsWereChanged = true;
|
|
750 } else {
|
|
751 for (int i = 0; i < nEncodings; i++) {
|
|
752 if (encodings[i] != encodingsSaved[i]) {
|
|
753 encodingsWereChanged = true;
|
|
754 break;
|
|
755 }
|
|
756 }
|
|
757 }
|
|
758
|
|
759 if (encodingsWereChanged) {
|
|
760 try {
|
|
761 rfb.writeSetEncodings(encodings, nEncodings);
|
|
762 if (vc != null) {
|
|
763 vc.softCursorFree();
|
|
764 }
|
|
765 } catch (Exception e) {
|
|
766 e.printStackTrace();
|
|
767 }
|
|
768 encodingsSaved = encodings;
|
|
769 nEncodingsSaved = nEncodings;
|
|
770 }
|
|
771 }
|
|
772
|
|
773 //
|
|
774 // setCutText() - send the given cut text to the RFB server.
|
|
775 //
|
|
776
|
|
777 void setCutText(String text) {
|
|
778 try {
|
|
779 if (rfb != null && rfb.inNormalProtocol) {
|
|
780 rfb.writeClientCutText(text);
|
|
781 }
|
|
782 } catch (Exception e) {
|
|
783 e.printStackTrace();
|
|
784 }
|
|
785 }
|
|
786
|
|
787 //
|
|
788 // Order change in session recording status. To stop recording, pass
|
|
789 // null in place of the fname argument.
|
|
790 //
|
|
791
|
|
792 void setRecordingStatus(String fname) {
|
|
793 synchronized (recordingSync) {
|
|
794 sessionFileName = fname;
|
|
795 recordingStatusChanged = true;
|
|
796 }
|
|
797 }
|
|
798
|
|
799 //
|
|
800 // Start or stop session recording. Returns true if this method call
|
|
801 // causes recording of a new session.
|
|
802 //
|
|
803
|
|
804 boolean checkRecordingStatus() throws IOException {
|
|
805 synchronized (recordingSync) {
|
|
806 if (recordingStatusChanged) {
|
|
807 recordingStatusChanged = false;
|
|
808 if (sessionFileName != null) {
|
|
809 startRecording();
|
|
810 return true;
|
|
811 } else {
|
|
812 stopRecording();
|
|
813 }
|
|
814 }
|
|
815 }
|
|
816 return false;
|
|
817 }
|
|
818
|
|
819 //
|
|
820 // Start session recording.
|
|
821 //
|
|
822
|
|
823 protected void startRecording() throws IOException {
|
|
824 synchronized (recordingSync) {
|
|
825 if (!recordingActive) {
|
|
826 // Save settings to restore them after recording the session.
|
|
827 cursorUpdatesDef = options.choices[options.cursorUpdatesIndex]
|
|
828 .getSelectedItem();
|
|
829 eightBitColorsDef = options.choices[options.eightBitColorsIndex]
|
|
830 .getSelectedItem();
|
|
831 // Set options to values suitable for recording.
|
|
832 options.choices[options.cursorUpdatesIndex].select("Disable");
|
|
833 options.choices[options.cursorUpdatesIndex].setEnabled(false);
|
|
834 options.setEncodings();
|
|
835 options.choices[options.eightBitColorsIndex].select("No");
|
|
836 options.choices[options.eightBitColorsIndex].setEnabled(false);
|
|
837 options.setColorFormat();
|
|
838 } else {
|
|
839 rfb.closeSession();
|
|
840 }
|
|
841
|
|
842 System.out.println("Recording the session in " + sessionFileName);
|
|
843 rfb.startSession(sessionFileName);
|
|
844 recordingActive = true;
|
|
845 }
|
|
846 }
|
|
847
|
|
848 //
|
|
849 // Stop session recording.
|
|
850 //
|
|
851
|
|
852 protected void stopRecording() throws IOException {
|
|
853 synchronized (recordingSync) {
|
|
854 if (recordingActive) {
|
|
855 // Restore options.
|
|
856 options.choices[options.cursorUpdatesIndex]
|
|
857 .select(cursorUpdatesDef);
|
|
858 options.choices[options.cursorUpdatesIndex].setEnabled(true);
|
|
859 options.setEncodings();
|
|
860 options.choices[options.eightBitColorsIndex]
|
|
861 .select(eightBitColorsDef);
|
|
862 options.choices[options.eightBitColorsIndex].setEnabled(true);
|
|
863 options.setColorFormat();
|
|
864
|
|
865 rfb.closeSession();
|
|
866 System.out.println("Session recording stopped.");
|
|
867 }
|
|
868 sessionFileName = null;
|
|
869 recordingActive = false;
|
|
870 }
|
|
871 }
|
|
872
|
|
873 /**
|
|
874 * readParameters() - read parameters from the html source or from the
|
|
875 * command line. On the command line, the arguments are just a sequence of
|
|
876 * param_name/param_value pairs where the names and values correspond to
|
|
877 * those expected in the html applet tag source.
|
|
878 */
|
|
879
|
|
880 void readParameters() {
|
|
881 /*
|
|
882 * host = readParameter("HOST", !inAnApplet);
|
|
883 *
|
|
884 * if (host == null) { host = getCodeBase().getHost(); if
|
|
885 * (host.equals("")) { fatalError("HOST parameter not specified"); } }
|
|
886 *
|
|
887 * port = readIntParameter("PORT", 5550);
|
|
888 */
|
|
889
|
|
890 // Read "ENCPASSWORD" or "PASSWORD" parameter if specified.
|
|
891 readPasswordParameters();
|
|
892
|
|
893 String str;
|
|
894 if (inAnApplet) {
|
|
895 str = readParameter("Open New Window", false);
|
|
896 if (str != null && str.equalsIgnoreCase("Yes"))
|
|
897 inSeparateFrame = true;
|
|
898 }
|
|
899
|
|
900 // "Show Controls" set to "No" disables button panel.
|
|
901 showControls = true;
|
|
902 str = readParameter("Show Controls", false);
|
|
903 if (str != null && str.equalsIgnoreCase("No"))
|
|
904 showControls = false;
|
|
905
|
|
906 // "Offer Relogin" set to "No" disables "Login again" and "Close
|
|
907 // window" buttons under error messages in applet mode.
|
|
908 offerRelogin = true;
|
|
909 str = readParameter("Offer Relogin", false);
|
|
910 if (str != null && str.equalsIgnoreCase("No"))
|
|
911 offerRelogin = false;
|
|
912
|
|
913 // Do we continue showing desktop on remote disconnect?
|
|
914 showOfflineDesktop = false;
|
|
915 str = readParameter("Show Offline Desktop", false);
|
|
916 if (str != null && str.equalsIgnoreCase("Yes"))
|
|
917 showOfflineDesktop = true;
|
|
918
|
|
919 // Fine tuning options.
|
|
920 deferScreenUpdates = readIntParameter("Defer screen updates", 20);
|
|
921 deferCursorUpdates = readIntParameter("Defer cursor updates", 10);
|
|
922 deferUpdateRequests = readIntParameter("Defer update requests", 0);
|
|
923
|
|
924 // Debugging options.
|
|
925 debugStatsExcludeUpdates = readIntParameter("DEBUG_XU", 0);
|
|
926 debugStatsMeasureUpdates = readIntParameter("DEBUG_CU", 0);
|
|
927
|
|
928 // SocketFactory.
|
|
929 socketFactory = readParameter("SocketFactory", false);
|
|
930 }
|
|
931
|
|
932 //
|
|
933 // Read password parameters. If an "ENCPASSWORD" parameter is set,
|
|
934 // then decrypt the password into the passwordParam string. Otherwise,
|
|
935 // try to read the "PASSWORD" parameter directly to passwordParam.
|
|
936 //
|
|
937
|
|
938 private void readPasswordParameters() {
|
|
939 String encPasswordParam = readParameter("ENCPASSWORD", false);
|
|
940 if (encPasswordParam == null) {
|
|
941 passwordParam = readParameter("PASSWORD", false);
|
|
942
|
|
943 } else {
|
|
944 // ENCPASSWORD is hexascii-encoded. Decode.
|
|
945 byte[] pw = { 0, 0, 0, 0, 0, 0, 0, 0 };
|
|
946 int len = encPasswordParam.length() / 2;
|
|
947 if (len > 8)
|
|
948 len = 8;
|
|
949 for (int i = 0; i < len; i++) {
|
|
950 String hex = encPasswordParam.substring(i * 2, i * 2 + 2);
|
|
951 Integer x = new Integer(Integer.parseInt(hex, 16));
|
|
952 pw[i] = x.byteValue();
|
|
953 }
|
|
954 // Decrypt the password.
|
|
955 byte[] key = { 23, 82, 107, 6, 35, 78, 88, 7 };
|
|
956 DesCipher des = new DesCipher(key);
|
|
957 des.decrypt(pw, 0, pw, 0);
|
|
958 passwordParam = new String(pw);
|
|
959
|
|
960 }
|
|
961 }
|
|
962
|
|
963 public String readParameter(String name, boolean required) {
|
|
964 if (inAnApplet) {
|
|
965 String s = getParameter(name);
|
|
966 if ((s == null) && required) {
|
|
967 fatalError(name + " parameter not specified");
|
|
968 }
|
|
969 return s;
|
|
970 }
|
|
971 /*
|
|
972 * for (int i = 0; i < mainArgs.length; i += 2) { if
|
|
973 * (mainArgs[i].equalsIgnoreCase(name)) { try { return mainArgs[i + 1];
|
|
974 * } catch (Exception e) { if (required) { fatalError(name +
|
|
975 * " parameter not specified"); } return null; } } }
|
|
976 */
|
|
977 if (required) {
|
|
978 fatalError(name + " parameter not specified");
|
|
979 }
|
|
980 return null;
|
|
981 }
|
|
982
|
|
983 int readIntParameter(String name, int defaultValue) {
|
|
984 String str = readParameter(name, false);
|
|
985 int result = defaultValue;
|
|
986 if (str != null) {
|
|
987 try {
|
|
988 result = Integer.parseInt(str);
|
|
989 } catch (NumberFormatException e) {
|
|
990 }
|
|
991 }
|
|
992 return result;
|
|
993 }
|
|
994
|
|
995 //
|
|
996 // moveFocusToDesktop() - move keyboard focus either to VncCanvas.
|
|
997 //
|
|
998
|
|
999 void moveFocusToDesktop() {
|
|
1000 if (vncContainer != null) {
|
|
1001 if (vc != null && vncContainer.isAncestorOf(vc))
|
|
1002 vc.requestFocus();
|
|
1003 }
|
|
1004 }
|
|
1005
|
|
1006 //
|
|
1007 // disconnect() - close connection to server.
|
|
1008 //
|
|
1009
|
|
1010 synchronized public void disconnect() {
|
|
1011 System.out.println("Disconnecting");
|
|
1012
|
|
1013 if (vc != null) {
|
|
1014 double sec = (System.currentTimeMillis() - vc.statStartTime) / 1000.0;
|
|
1015 double rate = Math.round(vc.statNumUpdates / sec * 100) / 100.0;
|
|
1016 int nRealRects = vc.statNumPixelRects;
|
|
1017 int nPseudoRects = vc.statNumTotalRects - vc.statNumPixelRects;
|
|
1018 System.out.println("Updates received: " + vc.statNumUpdates + " ("
|
|
1019 + nRealRects + " rectangles + " + nPseudoRects
|
|
1020 + " pseudo), " + rate + " updates/sec");
|
|
1021 int numRectsOther = nRealRects - vc.statNumRectsTight
|
|
1022 - vc.statNumRectsZRLE - vc.statNumRectsHextile
|
|
1023 - vc.statNumRectsRaw - vc.statNumRectsCopy;
|
|
1024 System.out.println("Rectangles:" + " Tight=" + vc.statNumRectsTight
|
|
1025 + "(JPEG=" + vc.statNumRectsTightJPEG + ") ZRLE="
|
|
1026 + vc.statNumRectsZRLE + " Hextile="
|
|
1027 + vc.statNumRectsHextile + " Raw=" + vc.statNumRectsRaw
|
|
1028 + " CopyRect=" + vc.statNumRectsCopy + " other="
|
|
1029 + numRectsOther);
|
|
1030
|
|
1031 int raw = vc.statNumBytesDecoded;
|
|
1032 int compressed = vc.statNumBytesEncoded;
|
|
1033 if (compressed > 0) {
|
|
1034 double ratio = Math.round((double) raw / compressed * 1000) / 1000.0;
|
|
1035 System.out.println("Pixel data: " + vc.statNumBytesDecoded
|
|
1036 + " bytes, " + vc.statNumBytesEncoded
|
|
1037 + " compressed, ratio " + ratio);
|
|
1038 }
|
|
1039 }
|
|
1040
|
|
1041 if (rfb != null && !rfb.closed())
|
|
1042 rfb.close();
|
|
1043 options.dispose();
|
|
1044 clipboard.dispose();
|
|
1045 if (rec != null)
|
|
1046 rec.dispose();
|
|
1047
|
|
1048 if (inAnApplet) {
|
|
1049 showMessage("Disconnected");
|
|
1050 } else {
|
|
1051 System.exit(0);
|
|
1052 }
|
|
1053 }
|
|
1054
|
|
1055 //
|
|
1056 // fatalError() - print out a fatal error message.
|
|
1057 // FIXME: Do we really need two versions of the fatalError() method?
|
|
1058 //
|
|
1059
|
|
1060 synchronized public void fatalError(String str) {
|
|
1061 System.out.println(str);
|
|
1062
|
|
1063 if (inAnApplet) {
|
|
1064 // vncContainer null, applet not inited,
|
|
1065 // can not present the error to the user.
|
|
1066 Thread.currentThread().stop();
|
|
1067 } else {
|
|
1068 System.exit(1);
|
|
1069 }
|
|
1070 }
|
|
1071
|
|
1072 synchronized public void fatalError(String str, Exception e) {
|
|
1073
|
|
1074 if (rfb != null && rfb.closed()) {
|
|
1075 // Not necessary to show error message if the error was caused
|
|
1076 // by I/O problems after the rfb.close() method call.
|
|
1077 System.out.println("RFB thread finished");
|
|
1078 return;
|
|
1079 }
|
|
1080
|
|
1081 System.out.println(str);
|
|
1082 e.printStackTrace();
|
|
1083
|
|
1084 if (rfb != null)
|
|
1085 rfb.close();
|
|
1086
|
|
1087 if (inAnApplet) {
|
|
1088 showMessage(str);
|
|
1089 } else {
|
|
1090 System.exit(1);
|
|
1091 }
|
|
1092 }
|
|
1093
|
|
1094 //
|
|
1095 // Show message text and optionally "Relogin" and "Close" buttons.
|
|
1096 //
|
|
1097
|
|
1098 void showMessage(String msg) {
|
|
1099 vncContainer.removeAll();
|
|
1100
|
|
1101 Label errLabel = new Label(msg, Label.CENTER);
|
|
1102 errLabel.setFont(new Font("Helvetica", Font.PLAIN, 12));
|
|
1103
|
|
1104 if (offerRelogin) {
|
|
1105
|
|
1106 Panel gridPanel = new Panel(new GridLayout(0, 1));
|
|
1107 Panel outerPanel = new Panel(new FlowLayout(FlowLayout.LEFT));
|
|
1108 outerPanel.add(gridPanel);
|
|
1109 vncContainer.setLayout(new FlowLayout(FlowLayout.LEFT, 30, 16));
|
|
1110 vncContainer.add(outerPanel);
|
|
1111 Panel textPanel = new Panel(new FlowLayout(FlowLayout.CENTER));
|
|
1112 textPanel.add(errLabel);
|
|
1113 gridPanel.add(textPanel);
|
|
1114 gridPanel.add(new ReloginPanel(this));
|
|
1115
|
|
1116 } else {
|
|
1117
|
|
1118 vncContainer.setLayout(new FlowLayout(FlowLayout.LEFT, 30, 30));
|
|
1119 vncContainer.add(errLabel);
|
|
1120
|
|
1121 }
|
|
1122
|
|
1123 if (inSeparateFrame) {
|
|
1124 vncFrame.pack();
|
|
1125 } else {
|
|
1126 validate();
|
|
1127 }
|
|
1128 }
|
|
1129
|
|
1130 //
|
|
1131 // Stop the applet.
|
|
1132 // Main applet thread will terminate on first exception
|
|
1133 // after seeing that rfbThread has been set to null.
|
|
1134 //
|
|
1135
|
|
1136 public void stop() {
|
|
1137 System.out.println("Stopping applet");
|
|
1138 rfbThread = null;
|
|
1139 }
|
|
1140
|
|
1141 //
|
|
1142 // This method is called before the applet is destroyed.
|
|
1143 //
|
|
1144
|
|
1145 public void destroy() {
|
|
1146 System.out.println("Destroying applet");
|
|
1147
|
|
1148 vncContainer.removeAll();
|
|
1149 options.dispose();
|
|
1150 clipboard.dispose();
|
|
1151 if (rec != null)
|
|
1152 rec.dispose();
|
|
1153 if (rfb != null && !rfb.closed())
|
|
1154 rfb.close();
|
|
1155 if (inSeparateFrame)
|
|
1156 vncFrame.dispose();
|
|
1157 }
|
|
1158
|
|
1159 //
|
|
1160 // Start/stop receiving mouse events.
|
|
1161 //
|
|
1162
|
|
1163 public void enableInput(boolean enable) {
|
|
1164 vc.enableInput(enable);
|
|
1165 }
|
|
1166
|
|
1167 //
|
|
1168 // Close application properly on window close event.
|
|
1169 //
|
|
1170
|
|
1171 public void windowClosing(WindowEvent evt) {
|
|
1172 System.out.println("Closing window");
|
|
1173 if (rfb != null)
|
|
1174 disconnect();
|
|
1175
|
|
1176 vncContainer.hide();
|
|
1177
|
|
1178 if (!inAnApplet) {
|
|
1179 System.exit(0);
|
|
1180 }
|
|
1181 }
|
|
1182
|
|
1183 //
|
|
1184 // Ignore window events we're not interested in.
|
|
1185 //
|
|
1186
|
|
1187 public void windowActivated(WindowEvent evt) {
|
|
1188 }
|
|
1189
|
|
1190 public void windowDeactivated(WindowEvent evt) {
|
|
1191 }
|
|
1192
|
|
1193 public void windowOpened(WindowEvent evt) {
|
|
1194 }
|
|
1195
|
|
1196 public void windowClosed(WindowEvent evt) {
|
|
1197 }
|
|
1198
|
|
1199 public void windowIconified(WindowEvent evt) {
|
|
1200 }
|
|
1201
|
|
1202 public void windowDeiconified(WindowEvent evt) {
|
|
1203 }
|
|
1204
|
|
1205 public void getParentName() {
|
|
1206 if (echoValue == null) {
|
|
1207
|
|
1208 if (clientSocket == null) {
|
|
1209
|
|
1210 // echo = new EchoClient(pHost, this);
|
|
1211 echoValue = new EchoClient(pHost, this, echoPort);
|
|
1212 echoValue.openport();
|
|
1213
|
|
1214 echoValue = echoValue.requestHostName("1");
|
|
1215 } else {
|
|
1216 echoValue = new EchoClient();
|
|
1217 echoValue = echoValue.Interruption(clientSocket);
|
|
1218 }
|
|
1219 }
|
|
1220 // proxyからの返信で接続先を決定する
|
|
1221 host = echoValue.responseLine;
|
|
1222 parent = echoValue.parent;
|
|
1223 if (echoValue.treenum != null) {
|
|
1224 treenum = echoValue.treenum;
|
|
1225 } else {
|
|
1226 treenum = echoValue.treenum;
|
|
1227 }
|
|
1228 if (echoValue.leaderflag != null) {
|
|
1229 leaderflag = echoValue.leaderflag;
|
|
1230 } else {
|
|
1231 leaderflag = echoValue.leaderflag;
|
|
1232 }
|
|
1233 System.out.println("Parent =" + parent);
|
|
1234 System.out.println("mynumber =" + treenum);
|
|
1235 System.out.println("connect host =" + host);
|
|
1236 System.out.println("leaderflag(boolean) = " + leaderflag);
|
|
1237
|
|
1238 }
|
|
1239
|
|
1240 public void setEchoValue(EchoClient value) {
|
|
1241 this.echoValue = value;
|
|
1242 }
|
|
1243
|
|
1244 int castByteInt(byte[] b) {
|
|
1245 ByteBuffer bb = ByteBuffer.wrap(b);
|
|
1246 int value = bb.getInt();
|
|
1247 return value;
|
|
1248 }
|
|
1249
|
|
1250 public void setClientSocket(Socket sock) {
|
|
1251 clientSocket = sock;
|
|
1252 }
|
|
1253
|
|
1254 public void close() {
|
|
1255 rfb.close();
|
|
1256 vncFrame.setVisible(false);
|
|
1257 vncFrame.dispose();
|
|
1258 }
|
|
1259
|
|
1260 public Image getScreenImage() {
|
|
1261 return vc.rawPixelsImage;
|
|
1262 }
|
|
1263
|
|
1264 public void writeScreenData(byte[] b, String imageFormat) {
|
|
1265 try {
|
|
1266 vc.drawBufferedImage(b);
|
|
1267 } catch (IOException e) {
|
|
1268 e.printStackTrace();
|
|
1269 }
|
|
1270 }
|
|
1271
|
|
1272 private String getNamePort() {
|
|
1273 ConfFileReader cfr = new ConfFileReader();
|
|
1274 cfr.fileRead();
|
|
1275 for (int i = 0; i < cfr.getName().size(); i++) {
|
|
1276 if (serverConfirm(cfr.getName().get(i), cfr.getPort().get(i)))
|
|
1277 return cfr.getName().get(i) + ":" + cfr.getPort().get(i);
|
|
1278 }
|
|
1279 return null;
|
|
1280 }
|
|
1281
|
|
1282 private boolean serverConfirm(String name, int port) {
|
|
1283 try {
|
|
1284 new Socket(name, port);
|
|
1285 return true;
|
|
1286 } catch (IOException e) {
|
|
1287 return false;
|
|
1288 }
|
|
1289 }
|
|
1290
|
|
1291 }
|