changeset 27:41b2e2ebcff2

modify AcceptClient.java
author one
date Sat, 28 Jan 2012 03:26:02 +0900
parents cbbdabc7645f
children a477a210a39a
files src/treeVnc/AcceptClient.java src/treeVnc/BroadCastProxy.java src/treeVnc/CreateThread.java src/treeVnc/CuiMyVncClient.java src/treeVnc/EchoClient.java src/treeVnc/GetBroadCastClient.java src/treeVnc/MyVncClient.java src/treeVnc/TextBoxClient.java src/treeVnc/TreeVnc.java src/treeVnc/VncProxyService.java
diffstat 10 files changed, 272 insertions(+), 245 deletions(-) [+]
line wrap: on
line diff
--- a/src/treeVnc/AcceptClient.java	Mon Jan 23 20:49:46 2012 +0900
+++ b/src/treeVnc/AcceptClient.java	Sat Jan 28 03:26:02 2012 +0900
@@ -7,18 +7,18 @@
 import java.util.*;
 
 public class AcceptClient {
-	int counter = 0, parentnum = 0/* 落ちたときの親の番号をカウントするためのもの */;
-	LinkedList<String> ls = new LinkedList<String>();
-	boolean addrRegistor = true;
-	int passNumber=0,numberZone;
+	private int counter = 0, parentnum = 0 /* 落ちたときの親の番号をカウントするためのもの */;
+	private LinkedList<String> ls = new LinkedList<String>();
+	private boolean addrRegistor = true;
+	private int passNumber=0,numberZone;
 	boolean runflag = false;
 	//private String name;
-	int passCheck = 0;
-	int treebranch = 2;// treeの子ノードの数 
-	String newparent,request,myAddress;
-	String leaderflag = "0", sendleaderflag = "0";
-	int intv_time = 100;
-	
+	private int passCheck = 0;
+	private int treebranch = 2; // treeの子ノードの数 
+	private String newparent,request,myAddress;
+	private String leaderflag = "0", sendleaderflag = "0";
+	private int intv_time = 100;
+	//private volatile boolean flag = false;
 
 
 	public AcceptClient(String name) {
@@ -26,9 +26,11 @@
 	}
 
 
+	/*
 	public AcceptClient() {
 		new CreateThread(this);
 	}
+	*/
 
 	// public synchronized void transferParentAddrerss(BufferedReader
 	// is,PrintStream os) {
@@ -158,22 +160,30 @@
 		leaderflag = decisionLeader(Integer.parseInt(port),treebranch);
 	}
 	
-	private synchronized void replyLeaderNode(PrintStream os,BufferedReader is,String port) throws IOException, InterruptedException {
+	private void replyLeaderNode(PrintStream os,BufferedReader is,String port) throws IOException, InterruptedException {
 		String checkRepetition = is.readLine();
+		String tempLastNode = null;
 		os.println(ls.getLast());
 		replyNodeInformation(port);
 		counter--;
 		passCheck = 1;
-		reportLastNode(ls.getLast(), newparent,port, String.valueOf(parentnum),
-				sendleaderflag);
+		System.out.println("接続要求"+checkRepetition);
+		if(!((ls.size()-1)==Integer.parseInt(checkRepetition))) {
+			checkWait(Integer.parseInt(checkRepetition));
+			reportLastNode(ls.getLast(), newparent,port, String.valueOf(parentnum),sendleaderflag);
+		} else {
+			tempLastNode = ls.getLast();
+		}
+		System.out.println("接続します"+checkRepetition);
 		listupdate(port);
-		checkWait(Integer.parseInt(checkRepetition));
+		if(!(ls.size()==Integer.parseInt(checkRepetition)))
+			checkWait(Integer.parseInt(checkRepetition));
+		else
+			reportLastNode(tempLastNode, newparent,port, String.valueOf(parentnum),sendleaderflag);
 		displyLinkedList(ls);
 		os.println(port);
 		runflag = true;
-		leaderflag = decisionLeader(
-				Integer.parseInt(checkRepetition),
-				treebranch);
+		leaderflag = decisionLeader(Integer.parseInt(checkRepetition),treebranch);
 		if (Integer.parseInt(checkRepetition) == counter + 1) {
 			checkRepetition = "stop";
 		} else {
@@ -187,18 +197,12 @@
 	
 	private void replyNormalChildren(PrintStream os,BufferedReader is,String port) throws IOException, InterruptedException {
 		String checkRepetition = is.readLine();
-		if (Integer.parseInt(checkRepetition)==ls.size()-2)
+		if (Integer.parseInt(checkRepetition)==ls.size()-1)
 			return;
+		System.out.println("接続要求"+checkRepetition);
 		checkWait(Integer.parseInt(checkRepetition));
-		/*
-		if (Integer.parseInt(checkRepetition) >= ls.size()) {
-			if ( ls.get(Integer.parseInt(checkRepetition)) == ls.get(1))
-				return;
-		} else {
-			if(ls.get(Integer.parseInt(checkRepetition)) == ls.getLast())
-				return;
-		}
-		*/
+		System.out.println("接続します"+checkRepetition);
+		checkWait(Integer.parseInt(checkRepetition));
 		os.println(ls.get(Integer.parseInt(port)));
 		os.println(port);
 		if(ls.size()-1+passCheck == Integer.parseInt(checkRepetition))
@@ -279,26 +283,27 @@
 
 	}
 	
-	synchronized void checkWait(int treenum) throws InterruptedException {
-		while (true) {
+	synchronized void checkWait(int treeNum) throws InterruptedException {
 			if (passNumber == 0) {
 				passNumber++;
-				numberZone = ( (treenum-1) / treebranch);
-				wait();
-				break;
-			} else if (numberZone == ( (treenum-1) / treebranch)) {
-				if (++passNumber == treebranch) {
+				numberZone = ( (treeNum-1) / treebranch);
+				System.out.println(treeNum+"waitしまーす");
+				wait(300);
+				notifyAll();
+			} else if (numberZone == ( (treeNum-1) / treebranch)) {
+			if (++passNumber == treebranch) {
+					System.out.println(treeNum+"notifyしまーす");
+					passNumber = 0;
 					notifyAll();
-					break; 
 				} else {
 					passNumber++;
-					wait();
+					System.out.println(treeNum+"waityobiしまーす");
+					wait(300);
 				}
 			} else {
 				wait();
-				continue;
+				checkWait(treeNum);
 			}
-		}
 	}
-	
+
 }
\ No newline at end of file
--- a/src/treeVnc/BroadCastProxy.java	Mon Jan 23 20:49:46 2012 +0900
+++ b/src/treeVnc/BroadCastProxy.java	Sat Jan 28 03:26:02 2012 +0900
@@ -1,34 +1,37 @@
 package treeVnc;
 
-
 import java.io.IOException;
 import java.io.PrintStream;
 import java.net.Socket;
 
-
 public class BroadCastProxy {
 	private String str;
 	private Socket socket = null;
 	private PrintStream os = null;
 	private int port = 8182;
-	
+
 	public BroadCastProxy(String _str) {
 		str = _str;
 	}
 
-	void createSocket(String addr) throws IOException {
-		try {
-			Thread.sleep(1000);
-		} catch (InterruptedException e) {
-			e.printStackTrace();
+	void createSocket(String addr) {	
+		while (true) {
+			try {
+				Thread.sleep(1000);
+				socket = new Socket(addr, port);
+				os = new PrintStream(socket.getOutputStream());
+				sendData();
+				os.close();
+				socket.close();
+				break;
+			} catch (IOException e) {
+				System.out.println("Connection faild");
+				continue;
+			} catch (InterruptedException e) {
+				e.printStackTrace();
+			}
 		}
-		socket = new Socket(addr,port);
-		os = new PrintStream(socket.getOutputStream());
-		sendData();
-		os.close();
-		socket.close();
 	}
-	
 
 	void sendData() {
 		os.println(str);
--- a/src/treeVnc/CreateThread.java	Mon Jan 23 20:49:46 2012 +0900
+++ b/src/treeVnc/CreateThread.java	Sat Jan 28 03:26:02 2012 +0900
@@ -18,16 +18,19 @@
 		port = 9999;
 	}
 
+	
 	public CreateThread(int port,AcceptClient _acc) {
 		acceptClient = _acc;
 		this.port = port; 
 	}
+	
 
 	void newEchoClient(final BufferedReader is,final PrintStream os) {
 		Runnable echoSender = new Runnable() {
 			public void run() {
 		//		AcceptClient acceptClient = new AcceptClient();
 				// acceptClient new
+				System.out.println("Threadつくります");
 				acceptClient.transferParentAddrerss(is,os);
 			}
 		};
@@ -66,6 +69,7 @@
 				BufferedReader is = new BufferedReader(new InputStreamReader(
 						clientSocket.getInputStream()));
 				PrintStream os = new PrintStream(clientSocket.getOutputStream());
+				System.out.println("accしたよ");
 				newEchoClient(is,os);
 //				acceptClient.transferParentAddrerss(is, os);
 			} catch (IOException e) {
--- a/src/treeVnc/CuiMyVncClient.java	Mon Jan 23 20:49:46 2012 +0900
+++ b/src/treeVnc/CuiMyVncClient.java	Sat Jan 28 03:26:02 2012 +0900
@@ -207,7 +207,7 @@
 
 				echoValue.openport();
 				// runflag = echo.losthost();
-				if (echoValue.losthost()) {
+				if (echoValue.lostHost()) {
 					break;
 				}
 				counter++;
@@ -235,7 +235,7 @@
 					echoValue = new EchoClient(echoValue, this);
 					echoValue.openport();
 					// runflag = echo.losthost();
-					if (echoValue.losthost()) {
+					if (echoValue.lostHost()) {
 						break;
 					}
 				}
--- a/src/treeVnc/EchoClient.java	Mon Jan 23 20:49:46 2012 +0900
+++ b/src/treeVnc/EchoClient.java	Sat Jan 28 03:26:02 2012 +0900
@@ -5,8 +5,6 @@
 
 //import myVncProxy.MulticastQueue.Client;
 
-
-
 public class EchoClient {
 	private String name;
 	private BufferedReader is = null;
@@ -15,48 +13,46 @@
 	private boolean runflag = false;
 	private WaitReply waitReply;
 	private Socket clientSocket = null;
-//	MyVncClient client;
+	// MyVncClient client;
 	private InterfaceForViewer client;
 	private int echoPort = 9999;
-	//private IpV6 ipV6;
-	//private MyVncClient checkMove;
-	//private VncViewer vncV;
+	// private IpV6 ipV6;
+	// private MyVncClient checkMove;
+	// private VncViewer vncV;
 	String responseLine;
 	String parent;// 親の番号
 	String treenum;// 自分の番号
 	String leaderflag;// リーダフラグ
-	//boolean passflag;
-	
+
+	// boolean passflag;
 
 	// WaitReplyに自分自身を渡している
 	public EchoClient() {
 	}
 
-	
 	public EchoClient(EchoClient echo) {
 		this.name = echo.name;
-		this.leaderflag= echo.leaderflag;
+		this.leaderflag = echo.leaderflag;
 		this.parent = echo.parent;
 		this.treenum = echo.treenum;
 		this.client = echo.client;
 		this.waitReply = echo.waitReply;
-		//checkMove = (MyVncClient)echo.client;
+		// checkMove = (MyVncClient)echo.client;
 	}
+
 	// VncViewerから引数をもらってきてproxy役を認識する
-	public EchoClient(String name,MyVncClient client) {
+	public EchoClient(String name, MyVncClient client) {
 		this.client = client;
 		this.name = name;
 	}
 
-	public EchoClient(String name,MyVncClient client, int echoPort) {
+	public EchoClient(String name, MyVncClient client, int echoPort) {
 		this.client = client;
 		this.name = name;
 		this.echoPort = echoPort;
 	}
-	
-	
-	
-	public EchoClient(EchoClient echo,MyVncClient client) {
+
+	public EchoClient(EchoClient echo, MyVncClient client) {
 		this.client = client;
 		this.name = echo.name;
 		leaderflag = echo.leaderflag;
@@ -65,18 +61,18 @@
 		waitReply = echo.waitReply;
 	}
 
-	public EchoClient(String name,CuiMyVncClient client) {
+	public EchoClient(String name, CuiMyVncClient client) {
 		this.client = client;
 		this.name = name;
 	}
-	
-	public EchoClient(String name,CuiMyVncClient client, int echoPort) {
+
+	public EchoClient(String name, CuiMyVncClient client, int echoPort) {
 		this.client = client;
 		this.name = name;
 		this.echoPort = echoPort;
 	}
 
-	public EchoClient(EchoClient echo,CuiMyVncClient client) {
+	public EchoClient(EchoClient echo, CuiMyVncClient client) {
 		this.client = client;
 		this.name = echo.name;
 		leaderflag = echo.leaderflag;
@@ -93,29 +89,31 @@
 				echoSocket = new Socket("133.13.48.18", echoPort);
 			}
 			os = new DataOutputStream(echoSocket.getOutputStream());
-			is = new BufferedReader(new InputStreamReader(echoSocket.getInputStream()));
+			is = new BufferedReader(new InputStreamReader(
+					echoSocket.getInputStream()));
 		} catch (UnknownHostException e) {
 			System.err.println("Don't know about host: localhost");
 		} catch (IOException e) {
 			System.out.println(name + " Connection Faild");
 			System.exit(0);
 		}
+
 	}
 
 	/**
 	 * @param args
-	 *            select connect port 
+	 *            select connect port
 	 * @return
 	 */
 	EchoClient requestHostName(String args) {
 		// サーバーにメッセージを送る
 		if (echoSocket != null && os != null && is != null) {
 			try {
-				
+
 				InetAddress addr = InetAddress.getLocalHost();
 				String add = new String(addr.getHostAddress());
-				//add = getIpV6();
-				
+				// add = getIpV6();
+
 				os.writeBytes(add + "\n");
 				os.writeBytes(args + "\n");
 				getProxyData(is);
@@ -126,44 +124,42 @@
 			} catch (IOException e) {
 				System.err.println("IOException: " + e);
 			}
-			waitReply = new WaitReply(treenum,client);
+			waitReply = new WaitReply(treenum, client);
 			waitReply.start();
 		}
 		return this;
 	}
 
-	
 	/**
-	 * Call at lost host 
+	 * Call at lost host
 	 */
-	boolean losthost() {
+	boolean lostHost() {
 		if (echoSocket != null && os != null && is != null) {
 			try {
-				if(runflag){
+				if (runflag) {
 					return true;
 				}
 				sendDataProxy();
-				String checkRepetition = getProxyData2(is);				
-				if(checkRepetition.equals("stop")){
+				String checkRepetition = getProxyData2(is);
+				if (checkRepetition.equals("stop")) {
 					return true;
-				}				
-				//if(!(checkRepetition.equals("skip")) || "1".equals(leaderflag)) {
-				if(!(waitReply.checkPath())) {
+				}
+				// if(!(checkRepetition.equals("skip")) ||
+				// "1".equals(leaderflag)) {
+				if (!(waitReply.checkPath())) {
 					Thread.sleep(1000);
 					reConnectionMain(echoSocket);
 					streamClose();
-				}				
-				//Thread.sleep(1000);
+				}
+				// Thread.sleep(1000);
 				/*
-				if(!(checkMove.vncFrame.isShowing())&&"skip".equals(checkRepetition)) {
-					openport();
-					notfoundParent();					
-				}				
-				*/
+				 * if(!(checkMove.vncFrame.isShowing())&&"skip".equals(
+				 * checkRepetition)) { openport(); notfoundParent(); }
+				 */
 			} catch (UnknownHostException e) {
 				System.err.println("Trying to connect to unknown host: " + e);
-			} catch (IOException e) {				
-				return false;			
+			} catch (IOException e) {
+				return false;
 			} catch (InterruptedException e) {
 				e.printStackTrace();
 
@@ -175,12 +171,12 @@
 		}
 		return true;
 	}
-	
+
 	boolean notfoundParent() {
 		if (echoSocket != null && os != null && is != null) {
 			runflag = true;
 			try {
-				sendDataProxy("2", parent,null);
+				sendDataProxy("2", parent, null);
 				getProxyData(is);
 				reConnectionMain(echoSocket);
 				streamClose();
@@ -193,22 +189,21 @@
 		return true;
 	}
 
-	
 	EchoClient Interruption(Socket _clientSocket) {
 		clientSocket = _clientSocket;
-		BufferedReader lostis = null;//あとで修正する
-
+		BufferedReader lostis = null;// あとで修正する
 
 		try {
-			lostis = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
-				getProxyData(lostis);
-				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 getProxyData(BufferedReader is) throws IOException {
 		if ((responseLine = is.readLine()) != null) {
 			System.out.println("Server: " + responseLine);
@@ -223,9 +218,10 @@
 			System.out.println("leaderflag: " + leaderflag);
 		}
 	}
-	
+
 	String getProxyData2(BufferedReader is) throws IOException {
 		String checkRepetition;
+		System.out.println("-------------------re----------------------------");
 		if ((responseLine = is.readLine()) != null) {
 			System.out.println("Server: " + responseLine);
 		}
@@ -237,7 +233,7 @@
 		}
 		return checkRepetition;
 	}
-	
+
 	void reConnectionMain(Socket echoSocket) {
 		client.close();
 		client.setClientSocket(echoSocket);
@@ -247,24 +243,26 @@
 		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);
+			sendDataProxy("1", parent, treenum);
+			System.out.println("---------------------------------------------");
 		} else {
-			sendDataProxy("3",parent,treenum);
+			sendDataProxy("3", parent, treenum);
+			System.out.println("---------------------------------------------");
 		}
 	}
-	
-	void sendDataProxy(String type,String num,String treenum) {
+
+	void sendDataProxy(String type, String num, String treenum) {
 		try {
-			if(treenum!=null) {
+			if (treenum != null) {
 				os.writeBytes(type + "\n");
 				os.writeBytes(num + "\n");
 				os.writeBytes(treenum + "\n");
@@ -280,10 +278,7 @@
 		}
 	}
 	/*
-	String getIpV6() {
-		ipV6 = new IpV6();
-		ipV6.getInterface();
-		return ipV6.getV6();
-	}
-	*/
+	 * String getIpV6() { ipV6 = new IpV6(); ipV6.getInterface(); return
+	 * ipV6.getV6(); }
+	 */
 }
\ No newline at end of file
--- a/src/treeVnc/GetBroadCastClient.java	Mon Jan 23 20:49:46 2012 +0900
+++ b/src/treeVnc/GetBroadCastClient.java	Sat Jan 28 03:26:02 2012 +0900
@@ -64,7 +64,7 @@
 		System.out.println(recover);
 		return recover;
 	}
-	*/
+*/
 	
 	public void run() {
 		getData();
--- a/src/treeVnc/MyVncClient.java	Mon Jan 23 20:49:46 2012 +0900
+++ b/src/treeVnc/MyVncClient.java	Sat Jan 28 03:26:02 2012 +0900
@@ -20,10 +20,10 @@
 	private Socket clientSocket = null;
 	private String parent, treenum;
 	private String leaderflag;
-	//private boolean runflag = false;
+	// private boolean runflag = false;
 	private boolean first = true;
 
-	private EchoClient echoValue;		
+	private EchoClient echoValue;
 	private int echoPort;
 	private String pHost;
 	private TextBoxClient getHost;
@@ -49,61 +49,69 @@
 		System.out.println(mainArgs.length);
 		inAnApplet = false;
 		inSeparateFrame = true;
-		
-//	if(mainArgs.length == 0) {
+		if (mainArgs.length != 0) {
+			if ("-c".equals(argv[0])) {
+				getHost = new TextBoxClient();
+				getHost.ipRegister();
+				pHost = getHost.getAddressOption();
+				port = Integer.parseInt(getHost.getPortOption());
+			} else {
+				bCast = new BroadCastClient("who");
+				bCast.createSocket();
+				bCast.sendData();
+				getBcast = new GetBroadCastClient();
+				if ("-reg".equals(argv[0]) && getNamePort() != null) {
+					getBcast.text.checkBox(getNamePort());
+					getBcast.text.setButton();
+					getBcast.text.visible();
+				} else {
+					runBcast = new Thread(getBcast);
+					runBcast.start();
+					getBcast.setStopFlag(true);
+				}
+				pHost = getBcast.text.getAddress();
+				port = Integer.parseInt(getBcast.text.getPort());
+				if (!("-reg".equals(argv[0])))
+					getBcast.socketClose();
+
+			}
+		} else {
 			bCast = new BroadCastClient("who");
 			bCast.createSocket();
 			bCast.sendData();
 			getBcast = new GetBroadCastClient();
-			if(getNamePort() != null)
-				getBcast.text.checkBox(getNamePort());
 			runBcast = new Thread(getBcast);
 			runBcast.start();
-//		}
-		
-		//getBcast.text.checkBox(getNamePort());
-		/*
-		try {
-			Thread.sleep(1000);
-		} catch (InterruptedException e) {
-			e.printStackTrace();
-		}
 			getBcast.setStopFlag(true);
 			pHost = getBcast.text.getAddress();
 			port = Integer.parseInt(getBcast.text.getPort());
-			getBcast.socketClose();
-			
-	*/
-			
-
-		if(mainArgs.length == 0)
-			getBcast.setStopFlag(true);
-		else {
-			getHost = new TextBoxClient();
-			getHost.ipRegister();
 		}
 
-		if (mainArgs.length > 0)
-			pHost = getHost.getAddressOption();	
-			//pHost = mainArgs[0];
-		else {
-			pHost = getBcast.text.getAddress();
-		}
-			
-			
-			//pHost = "cls080.ie.u-ryukyu.ac.jp";
-		if (mainArgs.length > 0)
-			port = Integer.parseInt(getHost.getPortOption());
-			//port = Integer.parseInt(mainArgs[1]);
-		else {
-			port = Integer.parseInt(getBcast.text.getPort());
-			getBcast.socketClose();
-//			port = 5999;
-		}
+		// getBcast.text.checkBox(getNamePort());
+		/*
+		 * try { Thread.sleep(1000); } catch (InterruptedException e) {
+		 * e.printStackTrace(); }
+		 */
 
+		/*
+		 * 
+		 * if(mainArgs.length == 0) getBcast.setStopFlag(true); else { getHost =
+		 * new TextBoxClient(); getHost.ipRegister(); }
+		 * 
+		 * if (mainArgs.length > 0) pHost = getHost.getAddressOption(); //pHost
+		 * = mainArgs[0]; else { pHost = getBcast.text.getAddress(); }
+		 * 
+		 * 
+		 * //pHost = "cls080.ie.u-ryukyu.ac.jp"; if (mainArgs.length > 0) port =
+		 * Integer.parseInt(getHost.getPortOption()); //port =
+		 * Integer.parseInt(mainArgs[1]); else { port =
+		 * Integer.parseInt(getBcast.text.getPort()); getBcast.socketClose(); //
+		 * port = 5999; }
+		 */
 		init();
 		start_threads();
 		start();
+
 	}
 
 	public void init() {
@@ -177,8 +185,8 @@
 			} else {
 				System.out.println("reConnectAndAuthenticate() ");
 				reConnectAndAuthenticate();
-				//accThread = new Thread(new AcceptThread(rfb, 5999));
-				//accThread.start();
+				// accThread = new Thread(new AcceptThread(rfb, 5999));
+				// accThread.start();
 			}
 
 			doProtocolInitialisation();
@@ -226,11 +234,11 @@
 				}
 
 				echoValue.openport();
-				
-				if (echoValue.losthost()) {
+
+				if (echoValue.lostHost()) {
 					break;
 				}
-				
+
 				counter++;
 			}
 		} catch (Exception e) {
@@ -239,7 +247,7 @@
 		}
 		gbc.weightx = 1.0;
 		gbc.weighty = 1.0;
-		
+
 		if (inSeparateFrame) {
 			// Create a panel which itself is resizeable and can hold
 			// non-resizeable VncCanvas component at the top left corner.
@@ -291,7 +299,7 @@
 					echoValue = new EchoClient(echoValue);
 					echoValue.openport();
 					// runflag = echo.losthost();
-					if (echoValue.losthost()) {
+					if (echoValue.lostHost()) {
 						break;
 					}
 
@@ -416,8 +424,8 @@
 
 		if (rfb.serverMinor == 855) {
 			/*
-			 * if connect to proxy, userEchoPortFlag is true. 
-			 * if connect to client, userEchoPortFlag is false.
+			 * if connect to proxy, userEchoPortFlag is true. if connect to
+			 * client, userEchoPortFlag is false.
 			 */
 			boolean useEchoPortFlag = rfb.readProxyFlag();
 			if (useEchoPortFlag) {
@@ -425,7 +433,6 @@
 				b = rfb.readEchoPort();
 				echoPort = castByteInt(b);
 
-
 				InetAddress addr = InetAddress.getByName(pHost);
 				String h = new String(addr.getHostAddress());
 
@@ -434,7 +441,7 @@
 					rfb.changeParent(host, port);
 					rfb.readVersionMsg();
 					rfb.writeVersionMsg();
-					boolean flag = rfb.readProxyFlag();					
+					boolean flag = rfb.readProxyFlag();
 				}
 			}
 		}
@@ -1242,34 +1249,32 @@
 	public Image getScreenImage() {
 		return vc.rawPixelsImage;
 	}
-	
+
 	public void writeScreenData(byte[] b, String imageFormat) {
-		try{
+		try {
 			vc.drawBufferedImage(b);
-		}catch(IOException e){
+		} catch (IOException e) {
 			e.printStackTrace();
 		}
 	}
-	
+
 	private String getNamePort() {
-		ConfFileReader crf = new ConfFileReader();
-		crf.fileRead();
-		for(int i=0 ; i < crf.getName().size() ; i++) {
-			if(serverConfirm(crf.getName().get(i),crf.getPort().get(i)))
-				return crf.getName().get(i)+":"+crf.getPort().get(i);
+		ConfFileReader cfr = new ConfFileReader();
+		cfr.fileRead();
+		for (int i = 0; i < cfr.getName().size(); i++) {
+			if (serverConfirm(cfr.getName().get(i), cfr.getPort().get(i)))
+				return cfr.getName().get(i) + ":" + cfr.getPort().get(i);
 		}
 		return null;
 	}
-	
-	
-	private boolean serverConfirm(String name,int port) {
-        try{
-        	new Socket(name,port);
-            return true;
-        }
-        catch (IOException e){
-            return false;
-        }
+
+	private boolean serverConfirm(String name, int port) {
+		try {
+			new Socket(name, port);
+			return true;
+		} catch (IOException e) {
+			return false;
+		}
 	}
 
 }
--- a/src/treeVnc/TextBoxClient.java	Mon Jan 23 20:49:46 2012 +0900
+++ b/src/treeVnc/TextBoxClient.java	Sat Jan 28 03:26:02 2012 +0900
@@ -5,7 +5,8 @@
 import java.awt.event.*;
 import java.util.ArrayList;
 
-public class TextBoxClient extends JFrame implements ActionListener, ItemListener {
+public class TextBoxClient extends JFrame implements ActionListener,
+		ItemListener {
 
 	/**
 	 * 
@@ -21,27 +22,25 @@
 	private boolean flag;
 	private ArrayList<String> temp = new ArrayList<String>();
 	private int counter = 0;
-	//private JCheckBox[] check = new JCheckBox[20];
+	// private JCheckBox[] check = new JCheckBox[20];
 	private Checkbox[] check = new Checkbox[20];
 	private boolean firstFlag = true;
 	private String hostAddress;
 	private String port;
 	private CheckboxGroup ch = new CheckboxGroup();
-	
+
 	public TextBoxClient() {
 		setTitle("Informatin Connection Address");
 		setResizable(false);
 		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
 	}
 
-	
 	public void ipRegister() {
 		setSize();
 		setText();
 		visible();
 	}
 
-
 	private void setSize() {
 		Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
 		width = (d.getWidth() / 2);
@@ -74,12 +73,12 @@
 	}
 
 	void checkBox(String str) {
-		//CheckboxGroup ch = new CheckboxGroup();
+		// CheckboxGroup ch = new CheckboxGroup();
 		if (counter == 0)
-			check[counter] = new Checkbox(str,true,ch);
+			check[counter] = new Checkbox(str, true, ch);
 		else
-			check[counter] = new Checkbox(str,false,ch);
-		//check[counter].setBackground(new Color(0, 153, 255));
+			check[counter] = new Checkbox(str, false, ch);
+		// check[counter].setBackground(new Color(0, 153, 255));
 		check[counter].addItemListener(this);
 		panel.add(check[counter]);
 		panel.setLayout(new GridLayout(counter + 2, 0));
@@ -89,22 +88,22 @@
 
 	void setButton() {
 		panel.add(button);
-		//panel.setBackground(Color.blue);
+		// panel.setBackground(Color.blue);
 		button.addActionListener(this);
 		Container contentPane = getContentPane();
 		contentPane.add(panel, BorderLayout.CENTER);
 	}
 
-
 	private void reportWindow() {
 		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
 		Container pane = getContentPane();
-		JLabel label = new JLabel("Not found Proxy. If you use Client-mode you must set-up Proxy");
-		label.setPreferredSize(new Dimension(580,50));
+		JLabel label = new JLabel(
+				"Not found Proxy. If you use Client-mode you must set-up Proxy");
+		label.setPreferredSize(new Dimension(580, 50));
 		label.setFont(new Font("Arial", Font.PLAIN, 20));
 		pane.add(label);
 	}
-	
+
 	public String getAddressOption() {
 		while (!(flag)) {
 			try {
@@ -113,13 +112,13 @@
 				e.printStackTrace();
 			}
 		}
-			return t1.getText();
+		return t1.getText();
 	}
 
 	public String getAddress() {
 		int i = 0;
 		while (!(flag)) {
-			if (i >= 20) {
+			if (i >= 50) {
 				reportWindow();
 				visible();
 				break;
@@ -134,11 +133,11 @@
 		return hostAddress;
 		// return t1.getText();
 	}
-	
+
 	public String getPortOption() {
 		return t2.getText();
 	}
-	
+
 	public String getPort() {
 		return port;
 		// return t2.getText();
@@ -149,23 +148,27 @@
 		for (int t = 0; t < counter; t++) {
 			if (check[t].getState()) {
 				System.out.println(check[t].getLabel());
-	//			if(int t =0)
-					setStatus(check[t].getLabel());
-				//else
-					//setStatus()
+				// if(int t =0)
+				setStatus(check[t].getLabel());
+				unVisible();
+				// else
+				// setStatus()
 			}
 		}
 	}
-	
 
 	private void setStatus(String str) {
 		String[] temp = str.split(":");
-		port = temp[0];
-		System.out.println("port=" + port);
-		hostAddress = temp[3];
+		if (temp.length == 2) {
+			hostAddress = temp[0];
+			port = temp[1];
+		} else {
+			port = temp[0];
+			System.out.println("port=" + port);
+			hostAddress = temp[3];
+		}
 	}
-	
-	
+
 	String splitString(String str) {
 		String[] split = str.split("\\*");
 		String comper;
@@ -176,13 +179,15 @@
 		if (firstFlag) {
 			temp.add(comper);
 			firstFlag = false;
-			return "port:" + split[0] + ":host:" + split[1] + ":proxy:"	+ split[3];
+			return "port:" + split[0] + ":host:" + split[1] + ":proxy:"
+					+ split[3];
 		}
 		for (int t = 0; t < temp.size(); t++) {
 			if (!(comper.equals(temp.get(t)))) {
 				if (t == temp.size() - 1) {
 					temp.add(comper);
-					return "port:" + split[0] + ":host:" + split[1] + ":proxy:" + split[3];
+					return "port:" + split[0] + ":host:" + split[1] + ":proxy:"
+							+ split[3];
 				}
 			} else {
 				break;
--- a/src/treeVnc/TreeVnc.java	Mon Jan 23 20:49:46 2012 +0900
+++ b/src/treeVnc/TreeVnc.java	Sat Jan 28 03:26:02 2012 +0900
@@ -1,8 +1,9 @@
 package treeVnc;
+
 /*
-import myVncClient.MyVncClient;
-import myVncProxy.VncProxyService;
-*/
+ import myVncClient.MyVncClient;
+ import myVncProxy.VncProxyService;
+ */
 
 public class TreeVnc {
 	public static void main(String[] argv) {
@@ -13,25 +14,33 @@
 		 * (InterruptedException e) { e.printStackTrace(); } }
 		 * System.out.println("test");
 		 */
-		if (argv.length == 0 || "-c".equals(argv[0])) {
+
+		if (argv.length == 0) {
 			System.out.println("client");
 			MyVncClient client = new MyVncClient();
 			client.treeVncClient(argv);
-		} else if(argv.length == 1) {
+		} else if (argv.length == 1) {
 			if ("-p".equals(argv[0])) {
 				System.out.println("proxy");
-				String[] temp = new String[0];
+//				String[] temp = new String[0];
 				VncProxyService proxy = new VncProxyService();
-				proxy.treeVncProxy(temp);
+				proxy.treeVncProxy(argv);
+			} else if ("-reg".equals(argv[0])||"-c".equals(argv[0])) {
+				System.out.println("client");
+				MyVncClient client = new MyVncClient();
+				client.treeVncClient(argv);
 			} else {
-				System.out.println("usage : java -jar TreeVnc.jar (IpAddress) 5900");
+				System.out
+						.println("usage : java -jar TreeVnc.jar (IpAddress) 5900");
 			}
-		} else if(argv.length==2) {
+		} else if (argv.length == 2) {
 			System.out.println("proxy");
 			VncProxyService proxy = new VncProxyService();
 			proxy.treeVncProxy(argv);
-		} else{
-			System.out.println("usage : java -jar TreeVnc.jar (IpAddress) 5900");
+		} else {
+			System.out
+					.println("usage : java -jar TreeVnc.jar (IpAddress) 5900");
 		}
+
 	}
 }
--- a/src/treeVnc/VncProxyService.java	Mon Jan 23 20:49:46 2012 +0900
+++ b/src/treeVnc/VncProxyService.java	Sat Jan 28 03:26:02 2012 +0900
@@ -731,17 +731,18 @@
 	
 	void readParameters() {
 		if (!(changeFlag)) {
-			if (mainArgs.length == 0) {
-				getHost = new TextBoxProxy(this);
-				getHost.ipRegister();
-				host = getHost.getAddress();
+			if ("-p".equals(mainArgs[0])) {
+				//getHost = new TextBoxProxy(this);
+				//getHost.ipRegister();
+				//host = getHost.getAddress();
+				host = "localhost";		
 			} else {
 				host = mainArgs[0];
 			}
 
-			if (mainArgs.length < 2) {
-				port = Integer.parseInt(getHost.getPort());
-				// port = 5900;
+			if ("-p".equals(mainArgs[0])) {
+				///port = Integer.parseInt(getHost.getPort());
+				 port = 5900;
 			} else {
 				port = Integer.parseInt(mainArgs[1]);
 			}