# HG changeset patch # User Yu Taninari # Date 1319466694 -32400 # Node ID 961a5915834ff7fcc3776484ce55fe0611b2e374 # Parent 53236c2c12293f636edf272279cdfd1c65f38045 merge diff -r 53236c2c1229 -r 961a5915834f src/myVncClient/EchoClient.java --- a/src/myVncClient/EchoClient.java Wed Oct 12 02:15:44 2011 +0900 +++ b/src/myVncClient/EchoClient.java Mon Oct 24 23:31:34 2011 +0900 @@ -17,13 +17,14 @@ // MyVncClient client; private InterfaceForViewer client; private int echoPort = 9999; - MyVncClient checkMove; - VncViewer vncV; + private IpV6 ipV6; + private MyVncClient checkMove; + private VncViewer vncV; String responseLine; String parent;// 親の番号 String treenum;// 自分の番号 String leaderflag;// リーダフラグ - boolean passflag; + //boolean passflag; // WaitReplyに自分自身を渡している @@ -33,10 +34,11 @@ public EchoClient(EchoClient echo) { this.name = echo.name; - leaderflag= echo.leaderflag; - parent = echo.parent; - treenum = echo.treenum; - client = echo.client; + this.leaderflag= echo.leaderflag; + this.parent = echo.parent; + this.treenum = echo.treenum; + this.client = echo.client; + this.waitReply = echo.waitReply; checkMove = (MyVncClient)echo.client; } // VncViewerから引数をもらってきてproxy役を認識する @@ -83,12 +85,6 @@ // void hostn(String args){ void openport() { - //  ソケットや入出力用のストリームの宣言 - /* - Random rnd = new Random(); - long ran = rnd.nextInt(1000) + 1000; -*/ - // ポート9999番に接続 try { if (name != null) { echoSocket = new Socket(name, echoPort); @@ -100,7 +96,7 @@ } catch (UnknownHostException e) { System.err.println("Don't know about host: localhost"); } catch (IOException e) { - System.out.println(name + " への接続に失敗しました"); + System.out.println(name + " Connection Faild"); System.exit(0); } } @@ -114,42 +110,23 @@ // サーバーにメッセージを送る if (echoSocket != null && os != null && is != null) { try { - // ip情報を取得する + InetAddress addr = InetAddress.getLocalHost(); - // System.out.println(addr.getHostAddress()); String add = new String(addr.getHostAddress()); - - // メッセージを送ります + //add = getIpV6(); + os.writeBytes(add + "\n"); os.writeBytes(args + "\n"); + getProxyData(is); - if ((responseLine = is.readLine()) != null) { - System.out.println("Server: " + responseLine); - } - if ((parent = is.readLine()) != null) { - System.out.println("parent: " + parent); - } - if ((treenum = is.readLine()) != null) { - System.out.println("treenum: " + treenum); - } - if ((leaderflag = is.readLine()) != null) { - System.out.println("leaderflag: " + leaderflag); - } - - // 開いたソケットなどをクローズ - os.close(); - is.close(); - echoSocket.close(); + streamClose(); } catch (UnknownHostException e) { System.err.println("Trying to connect to unknown host: " + e); } catch (IOException e) { System.err.println("IOException: " + e); - } - waitReply = new WaitReply(treenum,client); waitReply.start(); - } return this; } @@ -159,95 +136,41 @@ * Call at lost host */ boolean losthost() { - String checkRepetition; if (echoSocket != null && os != null && is != null) { try { if(runflag){ return true; } - // echoSocketの情報を呼び出す - if ("1".equals(leaderflag)) { - senddataProxy("1",parent,treenum); - } else { - senddataProxy("3",parent,treenum); - } - - if ((responseLine = is.readLine()) != null) { - System.out.println("Server: " + responseLine); - } - if ((parent = is.readLine()) != null) { - System.out.println("parent: " + parent); - } - if ((checkRepetition = is.readLine()) != null) { - System.out.println("checkRepetition: " + checkRepetition); - } + sendDataProxy(); + String checkRepetition = getProxyData2(is); if(checkRepetition.equals("stop")){ return true; - } - - /** - * if ((value.treenum = is.readLine()) != null) { - * System.out.println("treenum: " + value.treenum); } - */ - - - if(!(checkRepetition.equals("skip")) || "1".equals(leaderflag)) { - - //Thread.sleep(1000); - client.init(); - client.setEchoValue(this); - client.getParentName(); - client.start_threads(); - client.start(); - // MyVncClient.main(this); - - // 開いたソケットなどをクローズ - os.close(); - is.close(); - echoSocket.close(); - //runflag = true; - } - - - Thread.sleep(1000); + } + //if(!(checkRepetition.equals("skip")) || "1".equals(leaderflag)) { + if(!(waitReply.checkPath())) { + Thread.sleep(1000); + reConnectionMain(); + streamClose(); + } + //Thread.sleep(1000); + /* if(!(checkMove.vncFrame.isShowing())&&"skip".equals(checkRepetition)) { - System.out.println("in"); openport(); notfoundParent(); - } - - + } + */ } catch (UnknownHostException e) { System.err.println("Trying to connect to unknown host: " + e); - } catch (IOException e) { - - return false; - - /* - while (true) { - - try { - Thread.sleep(1000); - System.out.println("once connection proxy"); - } catch (InterruptedException e1) { - e1.printStackTrace(); - } - - openport(); - losthost(); - System.out.println("faild in this area"); - System.err.println("IOException: " + e); - - if(runflag == true){ - break; - } - } - */ - } - catch (InterruptedException e) { + } catch (IOException e) { + return false; + } catch (InterruptedException e) { e.printStackTrace(); + + } catch (NullPointerException e) { + openport(); + System.out.println("notFoundParents"); + notfoundParent(); } - } return true; } @@ -256,28 +179,10 @@ if (echoSocket != null && os != null && is != null) { runflag = true; try { - senddataProxy("2", parent,null); - - if ((responseLine = is.readLine()) != null) { - System.out.println("Server: " + responseLine); - } - if ((parent = is.readLine()) != null) { - System.out.println("parent: " + parent); - } - if ((treenum = is.readLine()) != null) { - System.out.println("treenum: " + treenum); - } - if ((leaderflag = is.readLine()) != null) { - System.out.println("leaderflag: " + leaderflag); - } - client.init(); - client.setEchoValue(this); - client.getParentName(); - client.start_threads(); - client.start(); - os.close(); - is.close(); - echoSocket.close(); + sendDataProxy("2", parent,null); + getProxyData(is); + reConnectionMain(); + streamClose(); } catch (UnknownHostException e) { System.err.println("Trying to connect to unknown host: " + e); } catch (IOException e) { @@ -286,76 +191,75 @@ } return true; } -/* - void lostchild() { - // ßSystem.out.println(name); - if (echoSocket != null && os != null && is != null) { - try { - - // echoSocketなどの情報を呼び出す(追加) - - // 自分の番号を報告 - os.writeBytes("4\n"); - os.writeBytes(treenum + "\n"); - - os.close(); - is.close(); - echoSocket.close(); - - } catch (UnknownHostException e) { - System.err.println("Trying to connect to unknown host: " + e); - } catch (IOException e) { - System.err.println("IOException: " + e); - } - } - } -*/ + EchoClient Interruption(Socket _clientSocket) { clientSocket = _clientSocket; BufferedReader lostis = null;//あとで修正する try { - lostis = new BufferedReader(new InputStreamReader( - clientSocket.getInputStream())); - // while (true){ - // line = lostis.readLine(); - // System.out.println(line); - - try { - if ((responseLine = lostis.readLine()) != null) { - System.out.println("newServer: " + responseLine); - } - if ((parent = lostis.readLine()) != null) { - System.out.println("newtparent: " + parent); - } - if ((treenum = lostis.readLine()) != null) { - System.out.println("newtreenum: " + treenum); - } - if ((leaderflag = lostis.readLine()) != null) { - System.out.println("newreaderflag: " + leaderflag); - } - - } catch (UnknownHostException e) { - System.err.println("Trying to connect to unknown host: " + e); - } catch (IOException e) { - System.err.println("IOException: " + e); - } - - // } - } catch (IOException e) { - System.out.println(e); - } - try { - clientSocket.close();// WaitReplyのacceptを終了させる + lostis = new BufferedReader(new InputStreamReader(clientSocket.getInputStream())); + getProxyData(lostis); + clientSocket.close();// WaitReplyのacceptを終了させる } catch (IOException e) { System.out.println(e); } return this; } - void senddataProxy(String type,String num,String treenum) { + void getProxyData(BufferedReader is) throws IOException { + if ((responseLine = is.readLine()) != null) { + System.out.println("Server: " + responseLine); + } + if ((parent = is.readLine()) != null) { + System.out.println("parent: " + parent); + } + if ((treenum = is.readLine()) != null) { + System.out.println("treenum: " + treenum); + } + if ((leaderflag = is.readLine()) != null) { + System.out.println("leaderflag: " + leaderflag); + } + } + + String getProxyData2(BufferedReader is) throws IOException { + String checkRepetition; + if ((responseLine = is.readLine()) != null) { + System.out.println("Server: " + responseLine); + } + if ((parent = is.readLine()) != null) { + System.out.println("parent: " + parent); + } + if ((checkRepetition = is.readLine()) != null) { + System.out.println("checkRepetition: " + checkRepetition); + } + return checkRepetition; + } + + void reConnectionMain() { + client.init(); + client.setEchoValue(this); + client.getParentName(); + client.start_threads(); + client.start(); + } + + void streamClose() throws IOException { + os.close(); + is.close(); + echoSocket.close(); + } + + void sendDataProxy() { + if ("1".equals(leaderflag)) { + sendDataProxy("1",parent,treenum); + } else { + sendDataProxy("3",parent,treenum); + } + } + + void sendDataProxy(String type,String num,String treenum) { try { if(treenum!=null) { os.writeBytes(type + "\n"); @@ -372,4 +276,10 @@ System.err.println("IOException: " + e); } } + + String getIpV6() { + ipV6 = new IpV6(); + ipV6.getInterface(); + return ipV6.getV6(); + } } \ No newline at end of file diff -r 53236c2c1229 -r 961a5915834f src/myVncClient/VncCanvas.java --- a/src/myVncClient/VncCanvas.java Wed Oct 12 02:15:44 2011 +0900 +++ b/src/myVncClient/VncCanvas.java Mon Oct 24 23:31:34 2011 +0900 @@ -32,7 +32,7 @@ import javax.imageio.ImageIO; -import test.TestComet; +//import test.TestComet; // diff -r 53236c2c1229 -r 961a5915834f src/myVncClient/WaitReply.java --- a/src/myVncClient/WaitReply.java Wed Oct 12 02:15:44 2011 +0900 +++ b/src/myVncClient/WaitReply.java Mon Oct 24 23:31:34 2011 +0900 @@ -19,7 +19,11 @@ this.client = client; this.treenum = treenum; } - + + public boolean checkPath() { + return passflag; + } + public void run() { Socket clientSocket = null; ServerSocket echoServer = null; @@ -35,10 +39,10 @@ clientSocket = echoServer.accept(); if (clientSocket != null) { client.close(); + passflag = true; // client.clientSocket = clientSocket; client.setClientSocket(clientSocket); client.init(); - passflag = true; client.setEchoValue(null); client.getParentName(); client.start_threads(); @@ -57,4 +61,4 @@ */ } } -} +} \ No newline at end of file