changeset 52:1d382eedc2b1

update myVncClient
author one
date Mon, 25 Jul 2011 20:45:57 +0900
parents 5867cac7efb0
children 96efd303d081 f2f4b0398f04
files VncViewer.jar myVncClient.jar src/myVncClient/EchoClient.java src/myVncClient/MyRfbProto.java src/myVncClient/MyVncClient.java
diffstat 5 files changed, 51 insertions(+), 51 deletions(-) [+]
line wrap: on
line diff
Binary file VncViewer.jar has changed
Binary file myVncClient.jar has changed
--- a/src/myVncClient/EchoClient.java	Fri Jul 22 19:21:18 2011 +0900
+++ b/src/myVncClient/EchoClient.java	Mon Jul 25 20:45:57 2011 +0900
@@ -2,7 +2,7 @@
 
 import java.io.*;
 import java.net.*;
-import java.util.Random;
+
 
 public class EchoClient {
 	String name;
@@ -10,7 +10,7 @@
 	DataOutputStream os = null;
 	Socket echoSocket = null;
 	boolean runflag = false;
-	WaitReply waitReply;// = new WaitReply();
+	WaitReply waitReply;
 	String responseLine;
 	String parent;// 親の番号
 	String treenum;// 自分の番号
@@ -28,6 +28,13 @@
 	public EchoClient(String _name) {
 		name = _name;
 	}
+	
+	public EchoClient(EchoClient echo) {
+		name = echo.name;
+		leaderflag = echo.leaderflag;
+		parent = echo.parent;
+		treenum = echo.treenum;
+	}
 
 	// void hostn(String args){
 	void openport() {
@@ -54,20 +61,6 @@
 		}
 	}
 
-	/*
-	 * try { echoServer = new ServerSocket(9998); } catch (IOException e) {
-	 * System.out.println(e); }
-	 * 
-	 * try { //clientSocket = echoServer.accept(); lostis = new
-	 * BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
-	 * lostos = new PrintStream(clientSocket.getOutputStream()); while (true){
-	 * line = is.readLine(); } } catch (IOException e){ System.out.println(e); }
-	 */
-
-	/*
-	 * catch(InterruptedException e){ e.printStackTrace(); }
-	 */
-
 	/**
 	 * @param args
 	 *            select at first connection or other
@@ -142,7 +135,9 @@
 				}
 				if ((parent = is.readLine()) != null) {
 					System.out.println("parent: " + parent);
-				}/*
+				}
+								
+				/*
 				 * if ((value.treenum = is.readLine()) != null) {
 				 * System.out.println("treenum: " + value.treenum); }
 				 */
@@ -209,15 +204,14 @@
 		}
 	}
 
-	void Interruption(Socket _clientSocket) {
+	EchoClient Interruption(Socket _clientSocket) {
 		clientSocket = _clientSocket;
 		BufferedReader lostis = null;//あとで修正する
-		PrintStream lostos;//あとで修正する
+
 
 		try {
 			lostis = new BufferedReader(new InputStreamReader(
 					clientSocket.getInputStream()));
-			lostos = new PrintStream(clientSocket.getOutputStream());
 			// while (true){
 			// line = lostis.readLine();
 			// System.out.println(line);
@@ -251,8 +245,6 @@
 		} catch (IOException e) {
 			System.out.println(e);
 		}
-		return ;
+		return this;
 	}
-}
-
-
+}
\ No newline at end of file
--- a/src/myVncClient/MyRfbProto.java	Fri Jul 22 19:21:18 2011 +0900
+++ b/src/myVncClient/MyRfbProto.java	Mon Jul 25 20:45:57 2011 +0900
@@ -20,7 +20,7 @@
 import myVncClient.MulticastQueue.Client;
 
 import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
+//import java.util.concurrent.Executors;
 import java.io.OutputStream;
 
 class MyRfbProto extends RfbProto {
@@ -41,7 +41,7 @@
 	private byte initData[];
 	private LinkedList<Socket> cliListTmp;
 	private LinkedList<Socket> cliList;
-	private LinkedList<Thread> sendThreads;
+	//private LinkedList<Thread> sendThreads;
 	boolean createBimgFlag;
 
 	ExecutorService executor;
--- a/src/myVncClient/MyVncClient.java	Fri Jul 22 19:21:18 2011 +0900
+++ b/src/myVncClient/MyVncClient.java	Mon Jul 25 20:45:57 2011 +0900
@@ -47,7 +47,7 @@
 	//
 
 	public void init(EchoClient value) {
-
+		
 		// readParameters();
 		readParameters(value);
 
@@ -93,8 +93,7 @@
 		rfbThread.start();
 	}
 	
-	public void run() {
-
+	public void run() { 
 		gridbag = new GridBagLayout();
 		vncContainer.setLayout(gridbag);
 
@@ -127,14 +126,28 @@
 			Random rnd = new Random();
 			long ran = rnd.nextInt(5000) + 5000;
 			System.out.println(ran);
+			//親がいない場合の処理はここに書く!!!!
+			/**
+			 * this while reconnection  
+			 */
+			
 			while (true) {
+				/**
+				 * if my last node case reconnectoion stop    
+				 */
+				if(clientSocket != null) {
+					break;
+				}
 				try {
 					Thread.sleep(ran);
 				} catch (InterruptedException e1) {
 					// TODO Auto-generated catch block
 					e1.printStackTrace();
 				}
-				echo = new EchoClient();
+				if(clientSocket != null) {
+					break;
+				}
+				echo = new EchoClient(echo);
 				echo.openport();
 				echo.losthost();
 				if(echo.runflag==true){
@@ -203,29 +216,12 @@
 			//window を消してnullを突っ込んでGCで削除させる。
 			vncFrame.setVisible(false);
 			vncFrame = null;
+			//num4
 			// リーダーの子ノードがproxyに対して親が落ちたことを報告をする
 			if(leaderflag != null){
-				echo = new EchoClient();
-				echo.openport();
-				echo.losthost();
-			/*
-			if ("1".equals(echoClient.value.leaderflag)) {
-				echo = new echoClient();
+				echo = new EchoClient(echo);
 				echo.openport();
 				echo.losthost();
-			} else if ("0".equals(echoClient.value.leaderflag)) {
-				
-				try {
-					Thread.sleep(1000);
-				} catch (InterruptedException e1) {
-					// TODO Auto-generated catch block
-					e1.printStackTrace();
-				}
-
-				echo = new echoClient();
-				echo.openport();
-				echo.losthost();
-				*/
 			} else {
 
 				if (showOfflineDesktop) {
@@ -713,16 +709,28 @@
 				value = echo.hostn("1");
 			} else {
 				echo = new EchoClient();
-				echo.Interruption(clientSocket);
+				value = echo.Interruption(clientSocket);
 			}
 		}
 		// proxyからの返信で接続先を決定する
 		host = value.responseLine;
 		parent = value.parent;
-		treenum = value.treenum;
+		if(value.treenum != null) {
+			treenum = value.treenum;
+		} else {
+			treenum = echo.treenum;
+		}
+		if(value.leaderflag != null) {
+			leaderflag = value.leaderflag;
+		} else {
+			leaderflag = echo.leaderflag;
+		}
 		System.out.println("Parent =" + parent);
 		System.out.println("mynumber =" + treenum);
 		System.out.println("connect host =" + host);
+		System.out.println("leaderflag(boolean) = " + leaderflag);
+		
+		echo = value;
 
 		if (host == null) {
 			host = getCodeBase().getHost();