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