Mercurial > hg > Members > nobuyasu > tightVNCClient
comparison src/myVncClient/CuiMyVncClient.java @ 69:1f05b73b15df
modify MyVncClient.java and CuiMyVNcClient.java
author | e085711 |
---|---|
date | Sun, 07 Aug 2011 04:22:07 +0900 |
parents | 5e7110277cf0 |
children | affdcbdc90ea |
comparison
equal
deleted
inserted
replaced
68:4e31d8494360 | 69:1f05b73b15df |
---|---|
7 import java.util.Random; | 7 import java.util.Random; |
8 | 8 |
9 import myVncClient.AcceptThread; | 9 import myVncClient.AcceptThread; |
10 import myVncClient.OptionsNoFrame; | 10 import myVncClient.OptionsNoFrame; |
11 | 11 |
12 public class CuiMyVncClient implements InterfaceForViewer, java.lang.Runnable { | 12 public class CuiMyVncClient implements InterfaceForViewer { |
13 | 13 |
14 public static void main(String[] argv) { | 14 public static void main(String[] argv) { |
15 CuiMyVncClient v = new CuiMyVncClient(); | 15 CuiMyVncClient v = new CuiMyVncClient(); |
16 v.runClient(argv, v); | 16 v.runClient(argv, v); |
17 | 17 |
73 boolean inSeparateFrame = false; | 73 boolean inSeparateFrame = false; |
74 Socket clientSocket = null; | 74 Socket clientSocket = null; |
75 String parent, treenum; | 75 String parent, treenum; |
76 private String leaderflag; | 76 private String leaderflag; |
77 boolean runflag = false; | 77 boolean runflag = false; |
78 boolean first = true; | |
78 | 79 |
79 EchoClient echo; | 80 EchoClient echo; |
80 | 81 |
81 void checkArgs(String[] argv) { | 82 void checkArgs(String[] argv) { |
82 if (argv.length > 3) { | 83 if (argv.length > 3) { |
93 // | 94 // |
94 // init() | 95 // init() |
95 // | 96 // |
96 | 97 |
97 public void init(EchoClient value) { | 98 public void init(EchoClient value) { |
98 | 99 Random rnd = new Random(); |
100 long ran = rnd.nextInt(5000); | |
101 try { | |
102 Thread.sleep(ran); | |
103 } catch (InterruptedException e1) { | |
104 e1.printStackTrace(); | |
105 } | |
99 // readParameters(); | 106 // readParameters(); |
100 | 107 |
101 readParameters(value); | 108 readParameters(value); |
102 | 109 |
103 options = new OptionsNoFrame(this); | 110 options = new OptionsNoFrame(this); |
131 } | 138 } |
132 | 139 |
133 public void run() { | 140 public void run() { |
134 | 141 |
135 try { | 142 try { |
136 connectAndAuthenticate(); | 143 if (first) { |
144 connectAndAuthenticate(); | |
145 first = false; | |
146 }else { | |
147 reConnectAndAuthenticate(); | |
148 } | |
137 accThread = new Thread(new AcceptThread(rfb, 5999)); | 149 accThread = new Thread(new AcceptThread(rfb, 5999)); |
138 accThread.start(); | 150 accThread.start(); |
139 doProtocolInitialisation(); | 151 doProtocolInitialisation(); |
140 | 152 |
141 vc = new CuiVncCanvas(this, 0, 0); | 153 vc = new CuiVncCanvas(this, 0, 0); |
151 /** | 163 /** |
152 * this while reconnection | 164 * this while reconnection |
153 */ | 165 */ |
154 | 166 |
155 int counter = 0; | 167 int counter = 0; |
156 // window を消してnullを突っ込んでGCで削除させる。 | 168 |
157 /* | 169 /* |
158 * vncFrame.setVisible(false); vncFrame = null; | 170 vncFrame.setVisible(false); |
159 */ | 171 vncFrame.dispose(); |
172 */ | |
160 while (true) { | 173 while (true) { |
161 /** | 174 /** |
162 * if my last node case reconnectoion stop | 175 * if my last node case reconnectoion stop |
163 */ | 176 */ |
164 | 177 |
175 } | 188 } |
176 | 189 |
177 echo.openport(); | 190 echo.openport(); |
178 // runflag = echo.losthost(); | 191 // runflag = echo.losthost(); |
179 if (echo.losthost()) { | 192 if (echo.losthost()) { |
180 break; | 193 return; |
181 } | 194 } |
182 counter++; | 195 counter++; |
183 } | 196 } |
184 | 197 |
185 // System.exit(0); | 198 // System.exit(0); |
186 } catch (Exception e) { | 199 }catch (Exception e) { |
187 System.out.println(e); | 200 System.out.println(e); |
188 System.exit(0); | 201 System.exit(0); |
189 } | 202 } |
190 | 203 try{ |
191 try { | 204 |
192 | |
193 processNormalProtocol();// main loop | 205 processNormalProtocol();// main loop |
194 | 206 |
195 } catch (NoRouteToHostException e) { | 207 } catch (NoRouteToHostException e) { |
196 fatalError("Network error: no route to server: " + host, e); | 208 fatalError("Network error: no route to server: " + host, e); |
197 } catch (UnknownHostException e) { | 209 } catch (UnknownHostException e) { |
314 default: | 326 default: |
315 throw new Exception("Unknown authentication scheme " + authType); | 327 throw new Exception("Unknown authentication scheme " + authType); |
316 } | 328 } |
317 } | 329 } |
318 | 330 |
331 | |
332 | |
333 void reConnectAndAuthenticate() throws Exception { | |
334 showConnectionStatus("Initializing..."); | |
335 | |
336 showConnectionStatus("Connecting to " + host + ", port " + port + "..."); | |
337 | |
338 rfb.changeParent(host, port); | |
339 | |
340 showConnectionStatus("Connected to server"); | |
341 | |
342 rfb.readVersionMsg(); | |
343 showConnectionStatus("RFB server supports protocol version " | |
344 + rfb.serverMajor + "." + rfb.serverMinor); | |
345 | |
346 rfb.writeVersionMsg(); | |
347 showConnectionStatus("Using RFB protocol version " + rfb.clientMajor | |
348 + "." + rfb.clientMinor); | |
349 | |
350 int secType = rfb.negotiateSecurity(); | |
351 int authType; | |
352 if (secType == RfbProto.SecTypeTight) { | |
353 showConnectionStatus("Enabling TightVNC protocol extensions"); | |
354 rfb.setupTunneling(); | |
355 authType = rfb.negotiateAuthenticationTight(); | |
356 } else { | |
357 authType = secType; | |
358 } | |
359 | |
360 switch (authType) { | |
361 case RfbProto.AuthNone: | |
362 showConnectionStatus("No authentication needed"); | |
363 rfb.authenticateNone(); | |
364 break; | |
365 case RfbProto.AuthVNC: | |
366 showConnectionStatus("Performing standard VNC authentication"); | |
367 if (passwordParam != null) { | |
368 rfb.authenticateVNC(passwordParam); | |
369 } else { | |
370 String pw = askPassword(); | |
371 rfb.authenticateVNC(pw); | |
372 } | |
373 break; | |
374 default: | |
375 throw new Exception("Unknown authentication scheme " + authType); | |
376 } | |
377 } | |
378 | |
319 // | 379 // |
320 // Show a message describing the connection status. | 380 // Show a message describing the connection status. |
321 // To hide the connection status label, use (msg == null). | 381 // To hide the connection status label, use (msg == null). |
322 // | 382 // |
323 | 383 |