Mercurial > hg > Members > nobuyasu > tightVNCClient
comparison src/myVncClient/MyVncClient.java @ 79:c76e43a12796
modify MyVncClient
author | e085711 |
---|---|
date | Wed, 31 Aug 2011 13:34:32 +0900 |
parents | 42b08ecc4cb5 |
children | 3bfe8845684c |
comparison
equal
deleted
inserted
replaced
78:fe94e353d595 | 79:c76e43a12796 |
---|---|
21 String parent, treenum; | 21 String parent, treenum; |
22 private String leaderflag; | 22 private String leaderflag; |
23 boolean runflag = false; | 23 boolean runflag = false; |
24 boolean first = true; | 24 boolean first = true; |
25 | 25 |
26 EchoClient echo; | 26 EchoClient echoValue; |
27 int echoPort; | |
28 String pHost; | |
29 | |
27 // | 30 // |
28 // main() is called when run as a java program from the command line. | 31 // main() is called when run as a java program from the command line. |
29 // It simply runs the applet inside a newly-created frame. | 32 // It simply runs the applet inside a newly-created frame. |
30 // | 33 // |
31 | 34 |
32 public static void main(String[] argv) { | 35 public static void main(String[] argv) { |
33 MyVncClient v = new MyVncClient(); | 36 MyVncClient v = new MyVncClient(); |
34 v.echo = null; | 37 v.echoValue = null; |
35 v.runClient(argv); | 38 v.runClient(argv); |
36 } | 39 } |
37 | 40 |
38 private void runClient(String[] argv) { | 41 private void runClient(String[] argv) { |
39 mainArgs = argv; | 42 mainArgs = argv; |
40 inAnApplet = false; | 43 inAnApplet = false; |
41 inSeparateFrame = true; | 44 inSeparateFrame = true; |
42 | 45 |
43 if (mainArgs.length > 0) | 46 if (mainArgs.length > 0) |
44 host = mainArgs[0]; | 47 pHost = mainArgs[0]; |
45 else | 48 else |
46 host = "cls080.ie.u-ryukyu.ac.jp"; | 49 pHost = "cls080.ie.u-ryukyu.ac.jp"; |
47 if (mainArgs.length > 1) | 50 if (mainArgs.length > 1) |
48 port = Integer.parseInt(mainArgs[1]); | 51 port = Integer.parseInt(mainArgs[1]); |
49 else | 52 else |
50 port = 5999; | 53 port = 5999; |
51 | 54 |
162 while (true) { | 165 while (true) { |
163 /** | 166 /** |
164 * if my last node case reconnectoion stop | 167 * if my last node case reconnectoion stop |
165 */ | 168 */ |
166 | 169 |
167 echo = new EchoClient(echo, this); | 170 echoValue = new EchoClient(echoValue, this); |
168 try { | 171 try { |
169 Thread.sleep(ran); | 172 Thread.sleep(ran); |
170 } catch (InterruptedException e1) { | 173 } catch (InterruptedException e1) { |
171 e1.printStackTrace(); | 174 e1.printStackTrace(); |
172 } | 175 } |
173 | 176 |
174 if (counter >= 3) { | 177 if (counter >= 3) { |
175 echo.openport(); | 178 echoValue.openport(); |
176 echo.notfoundParent(); | 179 echoValue.notfoundParent(); |
177 } | 180 } |
178 | 181 |
179 echo.openport(); | 182 echoValue.openport(); |
180 // runflag = echo.losthost(); | 183 // runflag = echo.losthost(); |
181 if (echo.losthost()) { | 184 if (echoValue.losthost()) { |
182 break; | 185 break; |
183 } | 186 } |
184 counter++; | 187 counter++; |
185 } | 188 } |
186 | 189 |
244 vncFrame.dispose(); | 247 vncFrame.dispose(); |
245 // num4 | 248 // num4 |
246 // リーダーの子ノードがproxyに対して親が落ちたことを報告をする | 249 // リーダーの子ノードがproxyに対して親が落ちたことを報告をする |
247 if (leaderflag != null) { | 250 if (leaderflag != null) { |
248 while (true) { | 251 while (true) { |
249 echo = new EchoClient(echo, this); | 252 echoValue = new EchoClient(echoValue, this); |
250 echo.openport(); | 253 echoValue.openport(); |
251 // runflag = echo.losthost(); | 254 // runflag = echo.losthost(); |
252 if (echo.losthost()) { | 255 if (echoValue.losthost()) { |
253 break; | 256 break; |
254 } | 257 } |
255 } | 258 } |
256 } else { | 259 } else { |
257 | 260 |
358 validate(); | 361 validate(); |
359 } | 362 } |
360 | 363 |
361 showConnectionStatus("Connecting to " + host + ", port " + port + "..."); | 364 showConnectionStatus("Connecting to " + host + ", port " + port + "..."); |
362 | 365 |
363 rfb = new MyRfbProto(host, port, this); | 366 rfb = new MyRfbProto(pHost, port, this); |
364 showConnectionStatus("Connected to server"); | 367 showConnectionStatus("Connected to server"); |
365 | 368 |
366 rfb.readVersionMsg(); | 369 rfb.readVersionMsg(); |
367 showConnectionStatus("RFB server supports protocol version " | 370 showConnectionStatus("RFB server supports protocol version " |
368 + rfb.serverMajor + "." + rfb.serverMinor); | 371 + rfb.serverMajor + "." + rfb.serverMinor); |
369 | 372 |
370 rfb.writeVersionMsg(); | 373 rfb.writeVersionMsg(); |
371 showConnectionStatus("Using RFB protocol version " + rfb.clientMajor | 374 showConnectionStatus("Using RFB protocol version " + rfb.clientMajor |
372 + "." + rfb.clientMinor); | 375 + "." + rfb.clientMinor); |
373 | 376 |
377 | |
374 if(rfb.serverMinor == 998) { | 378 if(rfb.serverMinor == 998) { |
375 byte[] b = new byte[4]; | 379 byte[] b = new byte[4]; |
376 b = rfb.readEchoPort(); | 380 b = rfb.readEchoPort(); |
377 int echoPort = castByteInt(b); | 381 echoPort = castByteInt(b); |
378 | 382 |
379 InetAddress addr = InetAddress.getByName(host); | 383 InetAddress addr = InetAddress.getByName(pHost); |
380 String h = new String(addr.getHostAddress()); | 384 String h = new String(addr.getHostAddress()); |
381 | 385 |
382 getParentname(echo, echoPort); | 386 getParentName(); |
383 if(!(h.equals(host))) { | 387 if(!(h.equals(host))) { |
384 rfb.changeParent(host, port); | 388 rfb.changeParent(host, port); |
385 rfb.readVersionMsg(); | 389 rfb.readVersionMsg(); |
386 rfb.writeVersionMsg(); | 390 rfb.writeVersionMsg(); |
387 } | 391 } |
388 } | 392 } |
389 | 393 |
390 | 394 |
391 int secType = rfb.negotiateSecurity(); | 395 int secType = rfb.negotiateSecurity(); |
392 int authType; | 396 int authType; |
393 if (secType == RfbProto.SecTypeTight) { | 397 if (secType == RfbProto.SecTypeTight) { |
394 showConnectionStatus("Enabling TightVNC protocol extensions"); | 398 showConnectionStatus("Enabling TightVNC protocol extensions"); |
449 int echoPort = castByteInt(b); | 453 int echoPort = castByteInt(b); |
450 | 454 |
451 InetAddress addr = InetAddress.getByName(host); | 455 InetAddress addr = InetAddress.getByName(host); |
452 String h = new String(addr.getHostAddress()); | 456 String h = new String(addr.getHostAddress()); |
453 | 457 |
454 getParentname(echo, echoPort); | 458 getParentName(); |
455 if(!(h.equals(host))) { | 459 if(!(h.equals(host))) { |
456 rfb.changeParent(host, port); | 460 rfb.changeParent(host, port); |
457 rfb.readVersionMsg(); | 461 rfb.readVersionMsg(); |
458 rfb.writeVersionMsg(); | 462 rfb.writeVersionMsg(); |
459 } | 463 } |
1129 } | 1133 } |
1130 | 1134 |
1131 public void windowDeiconified(WindowEvent evt) { | 1135 public void windowDeiconified(WindowEvent evt) { |
1132 } | 1136 } |
1133 | 1137 |
1134 void getParentname(EchoClient value, int echoPort) { | 1138 public void getParentName() { |
1135 if (value == null) { | 1139 if (echoValue == null) { |
1136 | 1140 |
1137 if (clientSocket == null) { | 1141 if (clientSocket == null) { |
1138 String pHost; | 1142 |
1139 if (mainArgs.length > 0) | |
1140 pHost = mainArgs[0]; | |
1141 else | |
1142 pHost = "cls080.ie.u-ryukyu.ac.jp"; | |
1143 // echo = new EchoClient(pHost, this); | 1143 // echo = new EchoClient(pHost, this); |
1144 echo = new EchoClient(pHost, this, echoPort); | 1144 echoValue = new EchoClient(pHost, this, echoPort); |
1145 echo.openport(); | 1145 echoValue.openport(); |
1146 | 1146 |
1147 value = echo.hostn("1"); | 1147 echoValue = echoValue.hostn("1"); |
1148 } else { | 1148 } else { |
1149 echo = new EchoClient(); | 1149 echoValue = new EchoClient(); |
1150 value = echo.Interruption(clientSocket); | 1150 echoValue = echoValue.Interruption(clientSocket); |
1151 } | 1151 } |
1152 } | 1152 } |
1153 // proxyからの返信で接続先を決定する | 1153 // proxyからの返信で接続先を決定する |
1154 host = value.responseLine; | 1154 host = echoValue.responseLine; |
1155 parent = value.parent; | 1155 parent = echoValue.parent; |
1156 if (value.treenum != null) { | 1156 if (echoValue.treenum != null) { |
1157 treenum = value.treenum; | 1157 treenum = echoValue.treenum; |
1158 } else { | 1158 } else { |
1159 treenum = echo.treenum; | 1159 treenum = echoValue.treenum; |
1160 } | 1160 } |
1161 if (value.leaderflag != null) { | 1161 if (echoValue.leaderflag != null) { |
1162 leaderflag = value.leaderflag; | 1162 leaderflag = echoValue.leaderflag; |
1163 } else { | 1163 } else { |
1164 leaderflag = echo.leaderflag; | 1164 leaderflag = echoValue.leaderflag; |
1165 } | 1165 } |
1166 System.out.println("Parent =" + parent); | 1166 System.out.println("Parent =" + parent); |
1167 System.out.println("mynumber =" + treenum); | 1167 System.out.println("mynumber =" + treenum); |
1168 System.out.println("connect host =" + host); | 1168 System.out.println("connect host =" + host); |
1169 System.out.println("leaderflag(boolean) = " + leaderflag); | 1169 System.out.println("leaderflag(boolean) = " + leaderflag); |
1170 | 1170 |
1171 echo = value; | 1171 } |
1172 | 1172 |
1173 if (host == null) { | 1173 public void setEchoValue(EchoClient value) { |
1174 host = getCodeBase().getHost(); | 1174 this.echoValue = value; |
1175 if (host.equals("")) { | 1175 } |
1176 fatalError("HOST parameter not specified"); | |
1177 } | |
1178 } | |
1179 // port = 5999; | |
1180 | |
1181 } | |
1182 | |
1183 int castByteInt(byte[] b) { | 1176 int castByteInt(byte[] b) { |
1184 ByteBuffer bb = ByteBuffer.wrap(b); | 1177 ByteBuffer bb = ByteBuffer.wrap(b); |
1185 int value = bb.getInt(); | 1178 int value = bb.getInt(); |
1186 return value; | 1179 return value; |
1187 } | 1180 } |
1188 | 1181 |
1189 | |
1190 | |
1191 public static void main(Socket _clientSocket) { | |
1192 MyVncClient v = new MyVncClient(); | |
1193 // v.clientSocket = _clientSocket; | |
1194 // v.mainArgs = argv; | |
1195 v.inAnApplet = false; | |
1196 v.inSeparateFrame = true; | |
1197 | |
1198 v.echo = null; | |
1199 | |
1200 v.init(); | |
1201 v.start_threads(); | |
1202 v.start(); | |
1203 } | |
1204 | |
1205 public static void main(EchoClient value) { | |
1206 MyVncClient v = new MyVncClient(); | |
1207 v.inAnApplet = false; | |
1208 v.inSeparateFrame = true; | |
1209 | |
1210 v.echo = value; | |
1211 | |
1212 v.init(); | |
1213 v.start_threads(); | |
1214 v.start(); | |
1215 | |
1216 } | |
1217 | |
1218 public void setClientSocket(Socket sock) { | 1182 public void setClientSocket(Socket sock) { |
1219 clientSocket = sock; | 1183 clientSocket = sock; |
1220 } | 1184 } |
1185 | |
1221 public void close() { | 1186 public void close() { |
1222 rfb.close(); | 1187 rfb.close(); |
1223 vncFrame.setVisible(false); | 1188 vncFrame.setVisible(false); |
1224 vncFrame.dispose(); | 1189 vncFrame.dispose(); |
1225 } | 1190 } |