changeset 143:4547543ca73c

findRootReply
author oc
date Thu, 12 Jun 2014 19:21:38 +0900
parents d2af9edb1803
children 1e004d9c599d
files src/main/java/jp/ac/u_ryukyu/treevnc/CreateConnectionParam.java src/main/java/jp/ac/u_ryukyu/treevnc/MyRfbProto.java src/main/java/jp/ac/u_ryukyu/treevnc/TreeVncCommand.java src/main/java/jp/ac/u_ryukyu/treevnc/client/MyRfbProtoClient.java src/main/java/jp/ac/u_ryukyu/treevnc/client/TreeVncProtocol.java src/main/java/jp/ac/u_ryukyu/treevnc/client/TreeVncRootSelectionPanel.java src/main/java/jp/ac/u_ryukyu/treevnc/server/VncProxyService.java src/viewer_swing/java/com/glavsoft/viewer/Viewer.java
diffstat 8 files changed, 43 insertions(+), 124 deletions(-) [+]
line wrap: on
line diff
--- a/src/main/java/jp/ac/u_ryukyu/treevnc/CreateConnectionParam.java	Thu Jun 12 18:04:22 2014 +0900
+++ b/src/main/java/jp/ac/u_ryukyu/treevnc/CreateConnectionParam.java	Thu Jun 12 19:21:38 2014 +0900
@@ -18,6 +18,7 @@
 	}
 
 	public synchronized void findTreeVncRoot() throws InterruptedException {
+		rfb.createRootSelectionPanel();
 		FindRoot getBcast = new FindRoot(rfb.acceptPort,this);
 		getBcast.findRoot();
 		// wait for RootSelection
--- a/src/main/java/jp/ac/u_ryukyu/treevnc/MyRfbProto.java	Thu Jun 12 18:04:22 2014 +0900
+++ b/src/main/java/jp/ac/u_ryukyu/treevnc/MyRfbProto.java	Thu Jun 12 19:21:38 2014 +0900
@@ -54,11 +54,12 @@
 
 	public MyRfbProto() {
 		rThread = new RequestScreenThread(this);
+	    treeVncCommand = new TreeVncCommand(null,this,null);
 	}
 	
 	public void setVncProxy(VncProxyService viewer) {
 	    this.viewer = viewer;
-	    treeVncCommand = new TreeVncCommand(viewer,this,treeProtocol);
+	    treeVncCommand.setViewer(viewer);
 	}
 
 	abstract public boolean isRoot() ;
@@ -426,6 +427,7 @@
 
 	public void setEcho(TreeVncProtocol _echo) {
 		treeProtocol = _echo;
+		treeVncCommand.setVncProtocol(_echo);
 	}
 	
 	public void setViewer(ViewerImpl v) {
@@ -702,5 +704,13 @@
         // here.
     }
 
+	public void addHostToSelectionPanel(int port, String hostname) {
+		
+	}
+
+	public void createRootSelectionPanel() {
+		
+	}
+
 
 }
--- a/src/main/java/jp/ac/u_ryukyu/treevnc/TreeVncCommand.java	Thu Jun 12 18:04:22 2014 +0900
+++ b/src/main/java/jp/ac/u_ryukyu/treevnc/TreeVncCommand.java	Thu Jun 12 19:21:38 2014 +0900
@@ -9,6 +9,7 @@
 import com.glavsoft.rfb.protocol.ProtocolContext;
 import com.glavsoft.transport.Reader;
 import com.glavsoft.transport.Writer;
+import com.glavsoft.viewer.ViewerImpl;
 
 import jp.ac.u_ryukyu.treevnc.client.TreeVncProtocol;
 import jp.ac.u_ryukyu.treevnc.server.VncProxyService;
@@ -39,8 +40,8 @@
         int length = buf.getInt();
         int port = buf.getInt();
         String hostname = null;
-        if (length>12) {
-             byte namebuf[] = new byte[length-12];
+        if (length>4) {
+             byte namebuf[] = new byte[length-4];
              try {
                 is.readBytes(namebuf);
             } catch (TransportException e) {
@@ -109,7 +110,7 @@
      * @param hostname
      */
     void handleFindRootReply(int port, String hostname) {
-    	viewer.addHostToSelectionPanel(port, hostname);
+    	rfb.addHostToSelectionPanel(port, hostname);
     }
     
     /**
@@ -131,4 +132,12 @@
         treeProtocol.notfoundParent(hostname, port);
     }
 
+	public void setVncProtocol(TreeVncProtocol _echo) {
+		this.treeProtocol = _echo;
+	}
+
+	public void setViewer(VncProxyService v) {
+		this.viewer = v;
+	}
+
 }
\ No newline at end of file
--- a/src/main/java/jp/ac/u_ryukyu/treevnc/client/MyRfbProtoClient.java	Thu Jun 12 18:04:22 2014 +0900
+++ b/src/main/java/jp/ac/u_ryukyu/treevnc/client/MyRfbProtoClient.java	Thu Jun 12 19:21:38 2014 +0900
@@ -16,6 +16,7 @@
 	int serverMajor, serverMinor;
 	int clientMajor, clientMinor;
 	private boolean normalTermination;
+	private TreeVncRootSelectionPanel rootSelectionPanel;
 
 
 	public MyRfbProtoClient() {
@@ -55,6 +56,21 @@
 		return normalTermination;
 	}
 	
+	
+	public void addHostToSelectionPanel(int port, String hostname) {
+		if (rootSelectionPanel != null) {
+			rootSelectionPanel.checkBox(Integer.toString(port) + ":" + hostname);
+			rootSelectionPanel.setButton();
+			rootSelectionPanel.visible();			
+		}
+	}
+	
+	@Override
+	public void createRootSelectionPanel() {
+		rootSelectionPanel = new TreeVncRootSelectionPanel();
+	}
+	
+	
 	/* 
 	 * measure client delay time using tree connection. It should be summed up in upward tree communication 
 	 */
--- a/src/main/java/jp/ac/u_ryukyu/treevnc/client/TreeVncProtocol.java	Thu Jun 12 18:04:22 2014 +0900
+++ b/src/main/java/jp/ac/u_ryukyu/treevnc/client/TreeVncProtocol.java	Thu Jun 12 19:21:38 2014 +0900
@@ -61,11 +61,9 @@
 	    ByteBuffer buf = ByteBuffer.allocate(4+4+4+4+hostname.length());
 	    buf.order(ByteOrder.BIG_ENDIAN);
 	    buf.put((byte) command);
-
+	    buf.put((byte) leaderFlag);
 	    buf.put((byte) 0);
 	    buf.put((byte) 0);
-	    buf.put((byte) 0);
-	    buf.putInt(leaderFlag);
 	    buf.putInt(4+hostname.length()); // length
 	    buf.putInt(port);
 	    buf.put(hostname.getBytes(), 0, hostname.length());
@@ -103,31 +101,6 @@
 
 
 	/**
-	 * @param args
-	 *            select connect port
-	 * @return
-	 */
-	public TreeVncProtocol requestHostName(String args) {
-		
-		if (echoSocket != null && os != null && is != null) {
-			try {
-				InetAddress addr = echoSocket.getLocalAddress();
-				myAddress = addr.getHostAddress();
-				os.writeBytes(myAddress + "\n");
-				os.writeBytes(args + "\n");
-				getProxyData(is, echoSocket);
-
-				streamClose();
-			} catch (UnknownHostException e) {
-				System.err.println("Trying to connect to unknown host: " + e);
-			} catch (IOException e) {
-				System.err.println("IOException: " + e);
-			}
-		}
-		return this;
-	}
-
-	/**
 	 * Call at lost host
 	 * @throws IOException 
 	 * @throws NumberFormatException 
@@ -157,36 +130,6 @@
 
     }
 
-    public TreeVncProtocol Interruption(Socket _clientSocket) {
-		clientSocket = _clientSocket;
-		try {
-			BufferedReader lostis = new BufferedReader(new InputStreamReader(
-					clientSocket.getInputStream()));
-			getProxyData(lostis, clientSocket);
-			clientSocket.close();
-		} catch (IOException e) {
-			System.out.println(e);
-		}
-		return this;
-	}
-
-	void getProxyData(BufferedReader is, Socket soc) throws IOException {
-		if ((parentAddress = is.readLine()) != null) {
-            System.out.println("Server received: " + parentAddress);
-		}
-		if ((parentNum = is.readLine()) != null) {
-			System.out.println("parent: " + parentNum);
-		}
-		if ((treeNum = is.readLine()) != null) {
-			System.out.println("treenum: " + treeNum);
-		}
-//		if ((leaderFlag = is.readLine()) != null) {
-//			System.out.println("leaderflag: " + leaderFlag);
-//		}
-		InetAddress parent = soc.getInetAddress();
-		parentAddress = parent.getHostName();
-        System.out.println("Actual Server: " + parentAddress);
-	}
 	
 	void streamClose() throws IOException {
 		os.close();
@@ -194,42 +137,6 @@
 		echoSocket.close();
 	}
 
-	void sendDataProxy() {
-		if ("1".equals(leaderFlag)) {
-			sendDataProxy("1", parentNum, treeNum);
-			System.out.println("---------------------------------------------");
-		} else {
-			// sendDataProxy("3", parentNum, treeNum);
-			// System.out.println("---------------------------------------------");
-		}
-	}
-
-	void sendDataProxy(String type, String num, String treenum) {
-		try {
-			if (treenum != null) {
-				os.writeBytes(type + "\n");
-				os.writeBytes(num + "\n");
-				os.writeBytes(treenum + "\n");
-			} else {
-				os.writeBytes(type + "\n");
-				os.writeBytes(num + "\n");
-			}
-		} catch (UnknownHostException e) {
-			System.err.println("Trying to connect to unknown host: " + e);
-		} catch (IOException e) {
-			System.err.println("IOException: " + e);
-		}
-	}
-
-	public void getParentName() {
-		if (clientSocket == null) {
-			openport();
-			requestHostName("1"); // 1 is normal connection type.
-		} else {
-			Interruption(clientSocket);
-		}
-	}
-
 	public void setViewer(ViewerImpl v) {
 		client = v;
 	}
--- a/src/main/java/jp/ac/u_ryukyu/treevnc/client/TreeVncRootSelectionPanel.java	Thu Jun 12 18:04:22 2014 +0900
+++ b/src/main/java/jp/ac/u_ryukyu/treevnc/client/TreeVncRootSelectionPanel.java	Thu Jun 12 19:21:38 2014 +0900
@@ -147,14 +147,8 @@
 
 	private void setStatus(String str) {
 		String[] temp = str.split(":");
-		if (temp.length == 2) {
-			hostAddress = temp[0];
-			port = temp[1];
-		} else {
-			port = temp[0];
-			System.out.println("root=" + str);
-			hostAddress = temp[1];
-		}
+		port = temp[0];
+		hostAddress = temp[1];
 	}
 
 	String splitString(String str) {
--- a/src/main/java/jp/ac/u_ryukyu/treevnc/server/VncProxyService.java	Thu Jun 12 18:04:22 2014 +0900
+++ b/src/main/java/jp/ac/u_ryukyu/treevnc/server/VncProxyService.java	Thu Jun 12 19:21:38 2014 +0900
@@ -7,9 +7,6 @@
 import java.util.logging.Logger;
 
 import jp.ac.u_ryukyu.treevnc.AcceptThread;
-import jp.ac.u_ryukyu.treevnc.client.TreeVncProtocol;
-import jp.ac.u_ryukyu.treevnc.client.TreeVncRootSelectionPanel;
-
 import com.glavsoft.core.SettingsChangedEvent;
 import com.glavsoft.rfb.IChangeSettingsListener;
 import com.glavsoft.rfb.IRfbSessionListener;
@@ -195,18 +192,6 @@
 		return clients.getList();
 	}
 
-	public void addHostToSelectionPanel(int port, String hostname) {
-		if (rootSelectionPanel != null) {
-			rootSelectionPanel.checkBox(Integer.toString(port) + ":" + hostname);
-			rootSelectionPanel.setButton();
-			rootSelectionPanel.visible();			
-		}
-	}
-	
-	public void createRootSelectionPanel() {
-		rootSelectionPanel = new TreeVncRootSelectionPanel();
-	}
-
     public void replyCreateTree(String hostname, int port) {
         clients.replyCreateTree(hostname,port);
     }
--- a/src/viewer_swing/java/com/glavsoft/viewer/Viewer.java	Thu Jun 12 18:04:22 2014 +0900
+++ b/src/viewer_swing/java/com/glavsoft/viewer/Viewer.java	Thu Jun 12 19:21:38 2014 +0900
@@ -48,7 +48,6 @@
 import jp.ac.u_ryukyu.treevnc.CreateConnectionParam;
 import jp.ac.u_ryukyu.treevnc.MyRfbProto;
 import jp.ac.u_ryukyu.treevnc.client.MyRfbProtoClient;
-import jp.ac.u_ryukyu.treevnc.client.TreeVncRootSelectionPanel;
 
 @SuppressWarnings("serial")
 public class Viewer extends JApplet implements Runnable, WindowListener , ViewerImpl{
@@ -68,8 +67,6 @@
     boolean isTreeVNC = false;
     protected MyRfbProto myRfb;
 	private boolean noConnection;
-	public TreeVncRootSelectionPanel rootSelectionPanel = null;
-
 
     public static void main(String[] args) {
 		Parser parser = new Parser();