comparison src/main/java/jp/ac/u_ryukyu/treevnc/client/EchoClient.java @ 36:b7d4d0349f99

write part of reconnection and remove warning.
author one
date Tue, 18 Sep 2012 17:23:19 +0900
parents 1b81deb0abb3
children c2f0b6907448
comparison
equal deleted inserted replaced
35:1b81deb0abb3 36:b7d4d0349f99
1 package jp.ac.u_ryukyu.treevnc.client; 1 package jp.ac.u_ryukyu.treevnc.client;
2 2
3 import java.io.*; 3 import java.io.*;
4 import java.net.*; 4 import java.net.*;
5 5
6 import jp.ac.u_ryukyu.treevnc.*; 6 import com.glavsoft.viewer.Viewer;
7
8 7
9 public class EchoClient { 8 public class EchoClient {
10 private String name; 9 private String name;
11 private BufferedReader is = null; 10 private BufferedReader is = null;
12 private DataOutputStream os = null; 11 private DataOutputStream os = null;
13 private Socket echoSocket = null; 12 private Socket echoSocket = null;
14 private boolean runflag = false; 13 private boolean runflag = false;
15 private WaitReply waitReply; 14 private WaitReply waitReply;
16 private Socket clientSocket = null; 15 private Socket clientSocket = null;
17 private MyVncClient client; 16 Viewer client;
18 private int echoPort = 9999; 17 private int echoPort = 9999;
19 public String parentAddress; 18 public String parentAddress;
20 public String parentNum; 19 public String parentNum;
21 public String treeNum; 20 public String treeNum;
22 public String leaderFlag; 21 public String leaderFlag;
100 } catch (UnknownHostException e) { 99 } catch (UnknownHostException e) {
101 System.err.println("Trying to connect to unknown host: " + e); 100 System.err.println("Trying to connect to unknown host: " + e);
102 } catch (IOException e) { 101 } catch (IOException e) {
103 System.err.println("IOException: " + e); 102 System.err.println("IOException: " + e);
104 } 103 }
105 waitReply = new WaitReply(treeNum, client); 104 waitReply = new WaitReply(treeNum,this);
106 waitReply.start(); 105 waitReply.start();
107 } 106 }
108 return this; 107 return this;
109 } 108 }
110 109
140 } 139 }
141 } 140 }
142 return true; 141 return true;
143 } 142 }
144 143
145 boolean notfoundParent() { 144 public boolean notfoundParent() {
146 if (echoSocket != null && os != null && is != null) { 145 if (echoSocket != null && os != null && is != null) {
147 runflag = true; 146 runflag = true;
148 try { 147 try {
149 sendDataProxy("2", parentNum, null); 148 sendDataProxy("2", parentNum, null);
150 getProxyData(is); 149 getProxyData(is);
203 } 202 }
204 return checkRepetition; 203 return checkRepetition;
205 } 204 }
206 205
207 void reConnectionMain(Socket echoSocket) { 206 void reConnectionMain(Socket echoSocket) {
208 client.close(); 207 try {
209 client.setClientSocket(echoSocket); 208 client.close();
210 client.run(); 209 client.setSocket(createSocketForClient(echoSocket));
210 Thread.sleep(1000);
211 client.run();
212 } catch (IOException e) {
213 e.printStackTrace();
214 } catch (InterruptedException e) {
215 e.printStackTrace();
216 }
211 } 217 }
212 218
213 void streamClose() throws IOException { 219 void streamClose() throws IOException {
214 os.close(); 220 os.close();
215 is.close(); 221 is.close();
251 requestHostName("1"); 257 requestHostName("1");
252 } else { 258 } else {
253 Interruption(clientSocket); 259 Interruption(clientSocket);
254 } 260 }
255 } 261 }
262
263 public void setViewer(Viewer v) {
264 client = v;
265 }
266
267 public Socket createSocketForClient(Socket soc) throws IOException {
268 BufferedReader is = new BufferedReader(new InputStreamReader(
269 soc.getInputStream()));
270 if ((parentAddress = is.readLine()) != null) {
271 System.out.println("Server: " + parentAddress);
272 }
273 if ((parentNum = is.readLine()) != null) {
274 System.out.println("parent: " + parentNum);
275 }
276 if ((treeNum = is.readLine()) != null) {
277 System.out.println("treenum: " + treeNum);
278 }
279 if ((leaderFlag = is.readLine()) != null) {
280 System.out.println("leaderflag: " + leaderFlag);
281 }
282 return new Socket(parentAddress,5999);
283 }
256 } 284 }