changeset 330:9d1ed0099350

root send lost child, hide function lost parent
author oc
date Tue, 03 Feb 2015 02:54:08 +0900
parents 230038d5127d
children 42fcc9419498
files src/main/java/com/glavsoft/rfb/protocol/ReceiverTask.java src/main/java/jp/ac/u_ryukyu/treevnc/TreeRFBProto.java src/main/java/jp/ac/u_ryukyu/treevnc/TreeVncProtocol.java
diffstat 3 files changed, 38 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- a/src/main/java/com/glavsoft/rfb/protocol/ReceiverTask.java	Mon Feb 02 20:18:53 2015 +0900
+++ b/src/main/java/com/glavsoft/rfb/protocol/ReceiverTask.java	Tue Feb 03 02:54:08 2015 +0900
@@ -161,7 +161,7 @@
                     while(counter-- > 0) {
                         try {
                             if (rfb.isLeader()) {
-                                echo.lostParent(rfb.getMyAddress(),rfb.getAcceptPort());
+//                                echo.lostParent(rfb.getMyAddress(),rfb.getAcceptPort());
                             }
                             break;
                         } catch (Exception e1) {
--- a/src/main/java/jp/ac/u_ryukyu/treevnc/TreeRFBProto.java	Mon Feb 02 20:18:53 2015 +0900
+++ b/src/main/java/jp/ac/u_ryukyu/treevnc/TreeRFBProto.java	Tue Feb 03 02:54:08 2015 +0900
@@ -111,8 +111,10 @@
      * @throws IOException
      * @throws TransportException
      */
-    public void newClient(final Socket newCli,final Writer os, final Reader is) { 
-
+    public void newClient(final Socket newCli,final Writer os, final Reader is) {
+        if (clients >= 2) {
+            clients = 0;
+        }
         final int myId = clients;
         final MulticastQueue.Client<LinkedList<ByteBuffer>> c = multicastqueue.newClient();
         final AtomicInteger writerRunning = new AtomicInteger();
@@ -150,17 +152,34 @@
                             if (state != 1) {
                                 System.out.println("Client died " + myId);
                                 System.out.println("task stop");
+
+                                String rootHostName = null;
+                                int rootHostPort = 0;
+                                String myHostName = null;
+                                int myHostPort = 0;
+
                                 if (isTreeManager) {
-
+                                    try {
+                                        rootHostName = InetAddress.getLocalHost().getHostAddress();
+                                        rootHostPort = getAcceptPort();
+                                        myHostName = rootHostName;
+                                        myHostPort = rootHostPort;
+                                    } catch (UnknownHostException e) {
+                                        e.printStackTrace();
+                                    }
                                 } else {
-                                    TreeVncProtocol echo = new TreeVncProtocol(getConnectionParam().getHostName(), getConnectionParam().getPort());
-                                    if (myId == 0) {
-                                        clients = myId;
-                                        echo.lostLeftChild(getMyAddress(), getAcceptPort());
-                                    } else if (myId == 1) {
-                                        clients = myId;
-                                        echo.lostRightChild(getMyAddress(), getAcceptPort());
-                                    }
+                                    rootHostName = getConnectionParam().getHostName();
+                                    rootHostPort = getConnectionParam().getPort();
+                                    myHostName = getMyAddress();
+                                    myHostPort = getAcceptPort();
+                                }
+
+                                TreeVncProtocol echo = new TreeVncProtocol(rootHostName, rootHostPort);
+                                clients = myId;
+                                if (myId == 0) {
+                                    echo.lostLeftChild(myHostName, myHostPort);
+                                } else if (myId == 1) {
+                                    echo.lostRightChild(myHostName, myHostPort);
                                 }
                                 break;
                             }
--- a/src/main/java/jp/ac/u_ryukyu/treevnc/TreeVncProtocol.java	Mon Feb 02 20:18:53 2015 +0900
+++ b/src/main/java/jp/ac/u_ryukyu/treevnc/TreeVncProtocol.java	Tue Feb 03 02:54:08 2015 +0900
@@ -29,8 +29,7 @@
         echoSocket = new Socket(rootAddress, rootPort);
         // echoSocket.setReuseAddress(true);
         os = new DataOutputStream(echoSocket.getOutputStream());
-        is = new BufferedReader(new InputStreamReader(
-                echoSocket.getInputStream()));
+        is = new BufferedReader(new InputStreamReader(echoSocket.getInputStream()));
     }
 
     public void findRootReply(int port) throws IOException {
@@ -93,9 +92,12 @@
 
     void streamClose() {
         try {
-            os.close();
-            is.close();
-            echoSocket.close();
+            if (os != null)
+                os.close();
+            if (is != null)
+                is.close();
+            if (echoSocket != null)
+                echoSocket.close();
         } catch (IOException e) {
             e.printStackTrace();
             System.out.println("cannot close stream.");