comparison src/myVncClient/MyVncClient.java @ 55:f2f4b0398f04

update EchoClient.java
author Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
date Thu, 28 Jul 2011 18:06:46 +0900
parents 1d382eedc2b1
children 9f8463fb1d4d
comparison
equal deleted inserted replaced
52:1d382eedc2b1 55:f2f4b0398f04
18 boolean inAnApplet = true; 18 boolean inAnApplet = true;
19 boolean inSeparateFrame = false; 19 boolean inSeparateFrame = false;
20 Socket clientSocket = null; 20 Socket clientSocket = null;
21 String parent, treenum; 21 String parent, treenum;
22 private String leaderflag; 22 private String leaderflag;
23 boolean runflag = false;
24
23 25
24 26
25 // 27 //
26 // main() is called when run as a java program from the command line. 28 // main() is called when run as a java program from the command line.
27 // It simply runs the applet inside a newly-created frame. 29 // It simply runs the applet inside a newly-created frame.
129 //親がいない場合の処理はここに書く!!!! 131 //親がいない場合の処理はここに書く!!!!
130 /** 132 /**
131 * this while reconnection 133 * this while reconnection
132 */ 134 */
133 135
136 int counter = 0;
137 //window を消してnullを突っ込んでGCで削除させる。
138 /*
139 vncFrame.setVisible(false);
140 vncFrame = null;
141 */
134 while (true) { 142 while (true) {
135 /** 143 /**
136 * if my last node case reconnectoion stop 144 * if my last node case reconnectoion stop
137 */ 145 */
138 if(clientSocket != null) { 146
147 echo = new EchoClient(echo,this);
148 try {
149 Thread.sleep(ran);
150 } catch (InterruptedException e1) {
151 e1.printStackTrace();
152 }
153
154 if(counter >= 3) {
155 echo.openport();
156 echo.notfoundParent();
157 }
158
159 echo.openport();
160 //runflag = echo.losthost();
161 if(echo.losthost()) {
139 break; 162 break;
140 } 163 }
141 try { 164 counter++;
142 Thread.sleep(ran);
143 } catch (InterruptedException e1) {
144 // TODO Auto-generated catch block
145 e1.printStackTrace();
146 }
147 if(clientSocket != null) {
148 break;
149 }
150 echo = new EchoClient(echo);
151 echo.openport();
152 echo.losthost();
153 if(echo.runflag==true){
154 echo.runflag=false;
155 break;
156 }
157 } 165 }
158 166
159 // System.exit(0); 167 // System.exit(0);
160 } catch (Exception e) { 168 } catch (Exception e) {
161 System.out.println(e); 169 System.out.println(e);
210 } catch (ConnectException e) { 218 } catch (ConnectException e) {
211 fatalError("Network error: could not connect to server: " + host 219 fatalError("Network error: could not connect to server: " + host
212 + ":" + port, e); 220 + ":" + port, e);
213 } catch (EOFException e) { 221 } catch (EOFException e) {
214 222
215 // insert
216 //window を消してnullを突っ込んでGCで削除させる。 223 //window を消してnullを突っ込んでGCで削除させる。
217 vncFrame.setVisible(false); 224 vncFrame.setVisible(false);
218 vncFrame = null; 225 vncFrame = null;
219 //num4 226 //num4
220 // リーダーの子ノードがproxyに対して親が落ちたことを報告をする 227 // リーダーの子ノードがproxyに対して親が落ちたことを報告をする
221 if(leaderflag != null){ 228 if(leaderflag != null) {
222 echo = new EchoClient(echo); 229 while(true) {
223 echo.openport(); 230 echo = new EchoClient(echo,this);
224 echo.losthost(); 231 echo.openport();
232 //runflag = echo.losthost();
233 if(echo.losthost()) {
234 break;
235 }
236 }
225 } else { 237 } else {
226 238
227 if (showOfflineDesktop) { 239 if (showOfflineDesktop) {
228 e.printStackTrace(); 240 e.printStackTrace();
229 System.out 241 System.out
269 281
270 // 282 //
271 // Create a VncCanvas instance. 283 // Create a VncCanvas instance.
272 // 284 //
273 285
286
274 void createCanvas(int maxWidth, int maxHeight) throws IOException { 287 void createCanvas(int maxWidth, int maxHeight) throws IOException {
275 // Determine if Java 2D API is available and use a special 288 // Determine if Java 2D API is available and use a special
276 // version of VncCanvas if it is present. 289 // version of VncCanvas if it is present.
277 vc = null; 290 vc = null;
278 try { 291 try {
701 714
702 if (clientSocket == null) { 715 if (clientSocket == null) {
703 String pHost; 716 String pHost;
704 if (mainArgs.length > 0) pHost = mainArgs[0]; 717 if (mainArgs.length > 0) pHost = mainArgs[0];
705 else pHost = "cls080.ie.u-ryukyu.ac.jp"; 718 else pHost = "cls080.ie.u-ryukyu.ac.jp";
706 echo = new EchoClient(pHost); 719 echo = new EchoClient(pHost,this);
707 echo.openport(); 720 echo.openport();
708 721
709 value = echo.hostn("1"); 722 value = echo.hostn("1");
710 } else { 723 } else {
711 echo = new EchoClient(); 724 echo = new EchoClient();
1062 public void windowDeiconified(WindowEvent evt) { 1075 public void windowDeiconified(WindowEvent evt) {
1063 } 1076 }
1064 1077
1065 public static void main(Socket _clientSocket) { 1078 public static void main(Socket _clientSocket) {
1066 MyVncClient v = new MyVncClient(); 1079 MyVncClient v = new MyVncClient();
1067 v.clientSocket = _clientSocket; 1080 //v.clientSocket = _clientSocket;
1068 // v.mainArgs = argv; 1081 // v.mainArgs = argv;
1069 v.inAnApplet = false; 1082 v.inAnApplet = false;
1070 v.inSeparateFrame = true; 1083 v.inSeparateFrame = true;
1071 1084
1072 v.init(null); 1085 v.init(null);