comparison src/main/java/jp/ac/u_ryukyu/treevnc/client/EchoClient.java @ 43:6687aa9dd55e

add flag for screen change in ReciverTask.java.
author one
date Tue, 06 Nov 2012 15:36:46 +0900
parents fe38611c4b2b
children d4663dfd91ae
comparison
equal deleted inserted replaced
42:fe38611c4b2b 43:6687aa9dd55e
22 22
23 public EchoClient(String name, int echoPort) { 23 public EchoClient(String name, int echoPort) {
24 this.echoPort = echoPort; 24 this.echoPort = echoPort;
25 this.name = name; 25 this.name = name;
26 } 26 }
27
28 27
29 public void openport() { 28 public void openport() {
30 try { 29 try {
31 //if(echoSocket==null) 30 // if(echoSocket==null)
32 echoSocket = new Socket(name, echoPort); 31 echoSocket = new Socket(name, echoPort);
33 echoSocket.setReuseAddress(true); 32 echoSocket.setReuseAddress(true);
34 os = new DataOutputStream(echoSocket.getOutputStream()); 33 os = new DataOutputStream(echoSocket.getOutputStream());
35 is = new BufferedReader(new InputStreamReader( 34 is = new BufferedReader(new InputStreamReader(
36 echoSocket.getInputStream())); 35 echoSocket.getInputStream()));
64 } catch (UnknownHostException e) { 63 } catch (UnknownHostException e) {
65 System.err.println("Trying to connect to unknown host: " + e); 64 System.err.println("Trying to connect to unknown host: " + e);
66 } catch (IOException e) { 65 } catch (IOException e) {
67 System.err.println("IOException: " + e); 66 System.err.println("IOException: " + e);
68 } 67 }
69 waitReply = new WaitReply(treeNum,this); 68 waitReply = new WaitReply(treeNum, this);
70 waitReply.start(); 69 waitReply.start();
71 } 70 }
72 return this; 71 return this;
73 } 72 }
74 73
167 } 166 }
168 return checkRepetition; 167 return checkRepetition;
169 } 168 }
170 169
171 void reConnectionMain(Socket echoSocket) { 170 void reConnectionMain(Socket echoSocket) {
172 try { 171 while (true) {
173 client.close(); 172 try {
174 client.setSocket(createSocketForClient(echoSocket)); 173 client.close();
175 client.run(); 174 client.setSocket(createSocketForClient(echoSocket));
176 } catch (IOException e) { 175 client.run();
177 e.printStackTrace(); 176 break;
177 } catch (IOException e) {
178 continue;
179 }
178 } 180 }
179 } 181 }
180 182
181 void streamClose() throws IOException { 183 void streamClose() throws IOException {
182 os.close(); 184 os.close();
209 System.err.println("Trying to connect to unknown host: " + e); 211 System.err.println("Trying to connect to unknown host: " + e);
210 } catch (IOException e) { 212 } catch (IOException e) {
211 System.err.println("IOException: " + e); 213 System.err.println("IOException: " + e);
212 } 214 }
213 } 215 }
214 216
215 public void getParentName() { 217 public void getParentName() {
216 if (clientSocket == null) { 218 if (clientSocket == null) {
217 // echo = new EchoClient(pHost, this); 219 // echo = new EchoClient(pHost, this);
218 openport(); 220 openport();
219 requestHostName("1"); // 1 is normal connection type. 221 requestHostName("1"); // 1 is normal connection type.
229 public Socket createSocketForClient(Socket soc) throws IOException { 231 public Socket createSocketForClient(Socket soc) throws IOException {
230 BufferedReader is = new BufferedReader(new InputStreamReader( 232 BufferedReader is = new BufferedReader(new InputStreamReader(
231 soc.getInputStream())); 233 soc.getInputStream()));
232 String tempParentAddress = is.readLine(); 234 String tempParentAddress = is.readLine();
233 parentNum = is.readLine(); 235 parentNum = is.readLine();
234 if("reconnection".equals(tempParentAddress)) { 236 if ("reconnection".equals(tempParentAddress)) {
235 System.out.println("-----------------into function \n" + parentNum); 237 System.out.println("-----------------into function \n" + parentNum);
236 return new Socket(parentAddress,Integer.parseInt(parentNum)); 238 return new Socket(parentAddress, Integer.parseInt(parentNum));
237 } 239 }
238 treeNum = is.readLine(); 240 treeNum = is.readLine();
239 leaderFlag = is.readLine(); 241 leaderFlag = is.readLine();
240 return new Socket(tempParentAddress,5999); 242 return new Socket(tempParentAddress, 5999);
241 } 243 }
242 } 244 }