changeset 148:0d9a824dd12f

update AcceptClient.java
author one
date Fri, 09 Sep 2011 23:12:37 +0900
parents 001f0b770f96
children f68f63c298d0 4ee9cfadd8dc
files src/myVncProxy/AcceptClient.java src/myVncProxy/MyRfbProto.java
diffstat 2 files changed, 29 insertions(+), 25 deletions(-) [+]
line wrap: on
line diff
--- a/src/myVncProxy/AcceptClient.java	Tue Aug 30 19:59:02 2011 +0900
+++ b/src/myVncProxy/AcceptClient.java	Fri Sep 09 23:12:37 2011 +0900
@@ -11,6 +11,7 @@
 	boolean runflag = false;
 	private String name;
 	boolean addrRegistor = true;
+	int passCheck = 0;
 
 	public AcceptClient(String _name) {
 		name = _name;
@@ -52,15 +53,14 @@
 							counter--;
 							runflag = true;
 
-							sendleaderflag = decisionLeader(
-									Integer.parseInt(port), treebranch);
+							sendleaderflag = decisionLeader(Integer.parseInt(port), treebranch);
 
 							Child report = new Child();
-
-							report.reportLastNode(ls.getLast(), newparent,
-									port, String.valueOf(parentnum),
-									sendleaderflag, counter);
-
+							
+							passCheck = 1;
+							report.reportLastNode(ls.getLast(), newparent,port, 
+									String.valueOf(parentnum),sendleaderflag, counter);
+							
 							listupdate(port);
 
 							int g = 0;
@@ -89,14 +89,11 @@
 							os.close();
 
 						} else if ("2".equals(line)) {
-							parentnum = (Integer.parseInt(port) - 1)
-									/ treebranch;
+							parentnum = (Integer.parseInt(port) - 1) / treebranch;
 							String newparent = ls.get(parentnum);
-
-							outputStream(os, newparent,
-									String.valueOf(parentnum),
-									String.valueOf(counter), leaderflag);
-
+							leaderflag = decisionLeader(Integer.parseInt(port),treebranch);
+							listupdate(port,newparent);
+							outputStream(os, newparent,String.valueOf(parentnum),port,leaderflag);
 							os.close();
 							is.close();
 						} else if ("3".equals(line)) {
@@ -109,7 +106,11 @@
 							if (checkRepetition.equals(ls.getLast())) {
 								checkRepetition = "stop";
 							} else {
-								checkRepetition = "go";
+								//checkRepetition = "go";
+								if(ls.size()-1+passCheck == Integer.parseInt(checkRepetition)) {
+									checkRepetition = "skip";
+								}
+								passCheck = 0;
 							}
 							os.println(checkRepetition);
 
@@ -133,17 +134,12 @@
 							}
 
 							if (counter >= treebranch + 1) {
-
 								leaderflag = decisionLeader(counter, treebranch);
 								parentnum = (counter - 1) / treebranch;
-
 								request = ls.get(parentnum);
 								System.out.println(parentnum);
-
-								outputStream(os, request,
-										String.valueOf(parentnum),
+								outputStream(os, request,String.valueOf(parentnum),
 										String.valueOf(counter), leaderflag);
-
 								checkParameter(parentnum, counter, leaderflag);
 							} else {
 								// treeの親ノードに接続する人に接続する人を教える
@@ -174,6 +170,12 @@
 		ls.add(Integer.parseInt(port), ls.getLast());
 		ls.removeLast();
 	}
+	
+	void listupdate(String port,String myaddr) {
+		ls.remove(Integer.parseInt(port));
+		ls.add(Integer.parseInt(port), myaddr);
+		ls.removeLast();
+	}
 
 	void outputStream(PrintStream os, String request, String parentnum,
 			String treenum, String leaderflag) {
@@ -201,12 +203,12 @@
 	}
 
 	String decisionLeader(int counter, int treebranch) {
-		if ((counter - 1) % treebranch == 1) { // children in most young treenum
-												// have leaderflag 1 other 0
+		if(counter == 1) 
+			return "1";
+		if ((counter - 1) % treebranch == 1)// children in most young treenum
 			return "0";
-		} else {
+		else
 			return "1";
-		}
 	}
 
 }
--- a/src/myVncProxy/MyRfbProto.java	Tue Aug 30 19:59:02 2011 +0900
+++ b/src/myVncProxy/MyRfbProto.java	Fri Sep 09 23:12:37 2011 +0900
@@ -599,6 +599,7 @@
 	 * ZRLEE compression is not context dependent, so no recompression is necessary.
 	 */
 	void readSendData(int dataLen) throws IOException, DataFormatException {
+		
 		LinkedList<ByteBuffer>bufs = new LinkedList<ByteBuffer>();
 		ByteBuffer header = ByteBuffer.allocate(16);
 		readFully(header.array(),0,16); 
@@ -645,6 +646,7 @@
 		// but it may generate too many large data. It is better to do it in each client.
 		// But we have do inflation for all input data, so we have to do it here.
 	}
+	
 
 	void newClient(AcceptThread acceptThread, final Socket newCli,
 			final OutputStream os, final InputStream is) throws IOException {