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