changeset 12:12c3a73be47f

rename package
author one
date Tue, 21 Aug 2012 14:24:38 +0900
parents 57ae9fbb1245
children 406fa09ae645
files src/main/java/ac/ryukyu/treevnc/InterfaceForViewer.java src/main/java/ac/ryukyu/treevnc/MostRecentMultiCast.java src/main/java/ac/ryukyu/treevnc/MulticastQueue.java src/main/java/ac/ryukyu/treevnc/client/AcceptThread.java src/main/java/ac/ryukyu/treevnc/client/EchoClient.java src/main/java/ac/ryukyu/treevnc/client/GetDataClient.java src/main/java/ac/ryukyu/treevnc/client/GetHostClient.java src/main/java/ac/ryukyu/treevnc/client/MyRfbProtoClient.java src/main/java/ac/ryukyu/treevnc/client/MyVncClient.java src/main/java/ac/ryukyu/treevnc/client/TextBoxClient.java src/main/java/ac/ryukyu/treevnc/client/WaitReply.java src/main/java/ac/ryukyu/treevnc/server/AcceptClient.java src/main/java/ac/ryukyu/treevnc/server/AcceptThread.java src/main/java/ac/ryukyu/treevnc/server/BroadCastProxy.java src/main/java/ac/ryukyu/treevnc/server/CreateThread.java src/main/java/ac/ryukyu/treevnc/server/GetBroadCastProxy.java src/main/java/ac/ryukyu/treevnc/server/MyRfbProtoProxy.java src/main/java/ac/ryukyu/treevnc/server/RequestScreenThread.java src/main/java/ac/ryukyu/treevnc/server/TextBoxProxy.java src/main/java/ac/ryukyu/treevnc/server/VncProxyService.java src/main/java/jp/ac/u_ryukyu/treevnc/InterfaceForViewer.java src/main/java/jp/ac/u_ryukyu/treevnc/MostRecentMultiCast.java src/main/java/jp/ac/u_ryukyu/treevnc/MulticastQueue.java src/main/java/jp/ac/u_ryukyu/treevnc/client/AcceptThread.java src/main/java/jp/ac/u_ryukyu/treevnc/client/EchoClient.java src/main/java/jp/ac/u_ryukyu/treevnc/client/GetDataClient.java src/main/java/jp/ac/u_ryukyu/treevnc/client/GetHostClient.java src/main/java/jp/ac/u_ryukyu/treevnc/client/MyRfbProtoClient.java src/main/java/jp/ac/u_ryukyu/treevnc/client/MyVncClient.java src/main/java/jp/ac/u_ryukyu/treevnc/client/TextBoxClient.java src/main/java/jp/ac/u_ryukyu/treevnc/client/WaitReply.java src/main/java/jp/ac/u_ryukyu/treevnc/server/AcceptClient.java src/main/java/jp/ac/u_ryukyu/treevnc/server/AcceptThread.java src/main/java/jp/ac/u_ryukyu/treevnc/server/BroadCastProxy.java src/main/java/jp/ac/u_ryukyu/treevnc/server/CreateThread.java src/main/java/jp/ac/u_ryukyu/treevnc/server/GetBroadCastProxy.java src/main/java/jp/ac/u_ryukyu/treevnc/server/MyRfbProtoProxy.java src/main/java/jp/ac/u_ryukyu/treevnc/server/RequestScreenThread.java src/main/java/jp/ac/u_ryukyu/treevnc/server/TextBoxProxy.java src/main/java/jp/ac/u_ryukyu/treevnc/server/VncProxyService.java src/viewer_swing/java/com/glavsoft/viewer/ConnectionManager.java src/viewer_swing/java/com/glavsoft/viewer/ContainerManager.java src/viewer_swing/java/com/glavsoft/viewer/TreeConnectionManager.java
diffstat 43 files changed, 3199 insertions(+), 3190 deletions(-) [+]
line wrap: on
line diff
--- a/src/main/java/ac/ryukyu/treevnc/InterfaceForViewer.java	Tue Aug 21 14:02:05 2012 +0900
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,29 +0,0 @@
-package ac.ryukyu.treevnc;
-
-import java.awt.Image;
-import java.net.Socket;
-import ac.ryukyu.treevnc.client.*;
-
-public interface InterfaceForViewer extends java.lang.Runnable{
-
-	public void setEchoValue(EchoClient value);
-	public String readParameter(String name, boolean required);
-	
-	public void getParentName();
-	// synchronized
-	public void disconnect();
-	public void fatalError(String str);
-	public void fatalError(String str, Exception e);
-
-	
-	public void destroy();
-	
-	public void enableInput(boolean enable);
-	
-
-	public void setClientSocket(Socket sock);
-	public void close();
-	public Image getScreenImage();
-	public void writeScreenData(byte[] b, String imageFormat);
-	
-}
--- a/src/main/java/ac/ryukyu/treevnc/MostRecentMultiCast.java	Tue Aug 21 14:02:05 2012 +0900
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,27 +0,0 @@
-package ac.ryukyu.treevnc;
-
-import java.util.LinkedList;
-
-
-public class MostRecentMultiCast<T> extends MulticastQueue<T> {
-
-	LinkedList<Node<T>> alive;
-	int count = 0;
-	MostRecentMultiCast(int limit) {
-		count = limit;
-		this.alive = new LinkedList<Node<T>>();
-	}
-
-	@Override
-	public synchronized void put(T item)
-	{
-		Node<T> next = new Node<T>(item);
-		tail.set(next);
-		tail = next;
-		alive.addLast(next);
-		if (alive.size()>count) {
-			Node<T> old = alive.getFirst();
-			old.clear();
-		}
-	}
-}
--- a/src/main/java/ac/ryukyu/treevnc/MulticastQueue.java	Tue Aug 21 14:02:05 2012 +0900
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,87 +0,0 @@
-package ac.ryukyu.treevnc;
-
-import java.util.concurrent.CountDownLatch;
-
-public class MulticastQueue<T>
-{
-	
-	Node<T> tail;
-	
-	public MulticastQueue()
-	{
-		tail = new Node<T>(null);
-	}
-
-	public synchronized void put(T item)
-	{
-		Node<T> next = new Node<T>(item);
-		tail.set(next);
-		tail = next;
-	}
-	
-	public Client<T> newClient()
-	{
-		return new Client<T>(tail);
-	}
-	
-	public static class Client<T>
-	{
-		Node<T> node;
-		
-		Client(Node<T> tail)
-		{
-			node = tail;
-		}
-		
-		synchronized public T poll()
-		{
-			Node<T> next = null;
-			T item = null;
-			do {
-				try {
-					next = node.next();
-				}catch(InterruptedException _e){
-					continue;
-				}
-//				item = node.getItem();
-				item = next.getItem();				
-				node = next;
-			} while ( item == null);
-			return item;
-		}
-	}
-	
-	static class Node<T>
-	{
-		private T item;
-		private Node<T> next;
-		private CountDownLatch latch;
-		
-		public Node(T item)
-		{
-			this.item = item;
-			this.next = null;
-			latch = new CountDownLatch(1);
-		}
-		
-		synchronized public T getItem() {
-			return item;
-		}
-
-		public void set(Node<T> next)
-		{
-			this.next = next;
-			latch.countDown();
-		}
-		
-		public Node<T> next() throws InterruptedException
-		{
-			latch.await();
-			return next;
-		}
-
-		synchronized public void clear() {
-			item = null;
-		}
-	}
-}
--- a/src/main/java/ac/ryukyu/treevnc/client/AcceptThread.java	Tue Aug 21 14:02:05 2012 +0900
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,42 +0,0 @@
-package ac.ryukyu.treevnc.client;
-import java.net.Socket;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-
-public class AcceptThread implements Runnable {
-        MyRfbProtoClient rfb = null;
-        byte[] imageBytes;
-        int port;
-        
-        AcceptThread(MyRfbProtoClient _rfb) {
-                rfb = _rfb;
-        }
-
-
-        AcceptThread(MyRfbProtoClient _rfb, int p) {
-            rfb = _rfb;
-            port = p;
-        }
-       
-	public void changeRfb(MyRfbProtoClient _rfb) {
-		rfb = _rfb;
-	}
-
-	public void run() {
-		rfb.selectPort(port);
-
-		while (true) {
-			try {
-				Socket newCli = rfb.accept();
-
-				OutputStream os = newCli.getOutputStream();
-				InputStream is = newCli.getInputStream();
-				rfb.newClient(this, newCli, os, is);
-			} catch (IOException e) {
-				e.printStackTrace();
-				System.out.println(e);
-			}
-		}
-	}
-}
--- a/src/main/java/ac/ryukyu/treevnc/client/EchoClient.java	Tue Aug 21 14:02:05 2012 +0900
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,294 +0,0 @@
-package ac.ryukyu.treevnc.client;
-
-import java.io.*;
-import java.net.*;
-import ac.ryukyu.treevnc.*;
-
-//import myVncProxy.MulticastQueue.Client;
-
-public class EchoClient {
-	private String name;
-	private BufferedReader is = null;
-	private DataOutputStream os = null;
-	private Socket echoSocket = null;
-	private boolean runflag = false;
-	private WaitReply waitReply;
-	private Socket clientSocket = null;
-	// MyVncClient client;
-	private InterfaceForViewer client;
-	private int echoPort = 9999;
-	// private IpV6 ipV6;
-	// private MyVncClient checkMove;
-	// private VncViewer vncV;
-	String responseLine;
-	String parent;// 親の番号
-	String treenum;// 自分の番号
-	String leaderflag;// リーダフラグ
-
-	// boolean passflag;
-
-	// WaitReplyに自分自身を渡している
-	public EchoClient() {
-	}
-
-	public EchoClient(EchoClient echo) {
-		this.name = echo.name;
-		this.leaderflag = echo.leaderflag;
-		this.parent = echo.parent;
-		this.treenum = echo.treenum;
-		this.client = echo.client;
-		this.waitReply = echo.waitReply;
-		// checkMove = (MyVncClient)echo.client;
-	}
-
-	// VncViewerから引数をもらってきてproxy役を認識する
-	public EchoClient(String name, MyVncClient client) {
-		this.client = (InterfaceForViewer) client;
-		this.name = name;
-	}
-
-	public EchoClient(String name, int echoPort) {
-		this.echoPort = echoPort;
-		this.name = name;
-	}
-	
-	public EchoClient(String name, MyVncClient client, int echoPort) {
-		this.client = (InterfaceForViewer) client;
-		this.name = name;
-		this.echoPort = echoPort;
-	}
-
-	public EchoClient(EchoClient echo, MyVncClient client) {
-		this.client = (InterfaceForViewer) client;
-		this.name = echo.name;
-		leaderflag = echo.leaderflag;
-		parent = echo.parent;
-		treenum = echo.treenum;
-		waitReply = echo.waitReply;
-	}
-/*
-	public EchoClient(String name, CuiMyVncClient client) {
-		this.client = client;
-		this.name = name;
-	}
-
-	public EchoClient(String name, CuiMyVncClient client, int echoPort) {
-		this.client = client;
-		this.name = name;
-		this.echoPort = echoPort;
-	}
-
-	public EchoClient(EchoClient echo, CuiMyVncClient client) {
-		this.client = client;
-		this.name = echo.name;
-		leaderflag = echo.leaderflag;
-		parent = echo.parent;
-		treenum = echo.treenum;
-	}
-*/
-
-	// void hostn(String args){
-	void openport() {
-		try {
-			if (name != null) {
-				echoSocket = new Socket(name, echoPort);
-			} else {
-				echoSocket = new Socket("133.13.48.18", echoPort);
-			}
-			os = new DataOutputStream(echoSocket.getOutputStream());
-			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
-	 * @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();
-
-				os.writeBytes(add + "\n");
-				os.writeBytes(args + "\n");
-				getProxyData(is);
-
-				streamClose();
-			} catch (UnknownHostException e) {
-				System.err.println("Trying to connect to unknown host: " + e);
-			} catch (IOException e) {
-				System.err.println("IOException: " + e);
-			}
-			waitReply = new WaitReply(treenum, client);
-			waitReply.start();
-		}
-		return this;
-	}
-
-	/**
-	 * Call at lost host
-	 */
-	boolean lostHost() {
-		if (echoSocket != null && os != null && is != null) {
-			try {
-				if (runflag) {
-					return true;
-				}
-				sendDataProxy();
-				String checkRepetition = getProxyData2(is);
-				if (checkRepetition.equals("stop")) {
-					return true;
-				}
-				// if(!(checkRepetition.equals("skip")) ||
-				// "1".equals(leaderflag)) {
-				if (!(waitReply.checkPath())) {
-					Thread.sleep(1000);
-					reConnectionMain(echoSocket);
-					streamClose();
-				}
-				// Thread.sleep(1000);
-				/*
-				 * 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 (InterruptedException e) {
-				e.printStackTrace();
-
-			} catch (NullPointerException e) {
-				openport();
-				System.out.println("notFoundParents");
-				notfoundParent();
-			}
-		}
-		return true;
-	}
-
-	boolean notfoundParent() {
-		if (echoSocket != null && os != null && is != null) {
-			runflag = true;
-			try {
-				sendDataProxy("2", parent, null);
-				getProxyData(is);
-				reConnectionMain(echoSocket);
-				streamClose();
-			} catch (UnknownHostException e) {
-				System.err.println("Trying to connect to unknown host: " + e);
-			} catch (IOException e) {
-				System.err.println("IOException: " + e);
-			}
-		}
-		return true;
-	}
-
-	EchoClient Interruption(Socket _clientSocket) {
-		clientSocket = _clientSocket;
-		BufferedReader lostis = null;// あとで修正する
-
-		try {
-			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);
-		}
-		if ((parent = is.readLine()) != null) {
-			System.out.println("parent: " + parent);
-		}
-		if ((treenum = is.readLine()) != null) {
-			System.out.println("treenum: " + treenum);
-		}
-		if ((leaderflag = is.readLine()) != null) {
-			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);
-		}
-		if ((parent = is.readLine()) != null) {
-			System.out.println("parent:test " + parent);
-		}
-		if ((checkRepetition = is.readLine()) != null) {
-			System.out.println("checkRepetition: " + checkRepetition);
-		}
-		return checkRepetition;
-	}
-
-	void reConnectionMain(Socket echoSocket) {
-		client.close();
-		client.setClientSocket(echoSocket);
-		client.run();
-		/*
-		client.init();
-		client.setEchoValue(this);
-		client.getParentName();
-		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);
-			System.out.println("---------------------------------------------");
-		} else {
-			sendDataProxy("3", parent, 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);
-		}
-	}
-	/*
-	 * String getIpV6() { ipV6 = new IpV6(); ipV6.getInterface(); return
-	 * ipV6.getV6(); }
-	 */
-}
\ No newline at end of file
--- a/src/main/java/ac/ryukyu/treevnc/client/GetDataClient.java	Tue Aug 21 14:02:05 2012 +0900
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,91 +0,0 @@
-package ac.ryukyu.treevnc.client;
-
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.InputStreamReader;
-import java.net.ServerSocket;
-import java.net.Socket;
-
-
-public class GetDataClient implements Runnable {
-	private ServerSocket server = null;
-	BufferedReader is;
-	private int port = 8182;
-	private boolean stopFlag = false;
-	public TextBoxClient text = new TextBoxClient();
-	
-	private void getData() {
-		try {
-			server = new ServerSocket(port);
-			while(true) {
-				Socket socket = server.accept();  
-				is = new BufferedReader(new InputStreamReader(
-						socket.getInputStream()));
-				String line = is.readLine();
-//				text = new TextBoxClient();
-				if(line!=null){
-					text.checkBox(line);
-				}
-				// TextBoxClient text = new TextBoxClient();
-				text.setButton();
-				text.visible();
-			}
-		} catch (IOException e) {
-			e.printStackTrace();
-		}
-	}
-	
-	
-	public String textAddress() {
-		return text.getAddress();
-	}
-	
-	public String  textPort() {
-		return text.getPort();
-	}
-	
-	void socketClose() {
-		try {
-			text.unVisible();
-			//server.close(); after the modify
-			is.close();
-		} catch (IOException e) {
-			e.printStackTrace();
-		}
-	}
-	
-/*	
-	private int castInt(byte[] a) {
-		int value = 0;
-		ByteArrayInputStream bais = new ByteArrayInputStream(a);
-		DataInputStream dis = new DataInputStream(bais);
-		try {
-			value = dis.readInt();
-		} catch (IOException e) {
-		}
-		System.out.println(value);
-		return value;
-	}
-
-	private String castString(byte[] a) {
-		String recover = new String(a);
-		recover = recover.replace("¥n", "");
-		recover = recover.trim();
-		System.out.println(recover);
-		return recover;
-	}
-*/
-	
-	public void run() {
-		getData();
-	}
-
-	public void setStopFlag(boolean stopFlag) {
-		this.stopFlag = stopFlag;
-	}
-
-	public boolean isStopFlag() {
-		return stopFlag;
-	}
-
-}
--- a/src/main/java/ac/ryukyu/treevnc/client/GetHostClient.java	Tue Aug 21 14:02:05 2012 +0900
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,57 +0,0 @@
-package ac.ryukyu.treevnc.client;
-
-import java.io.IOException;
-import java.net.DatagramPacket;
-import java.net.InetAddress;
-import java.net.MulticastSocket;
-
-public class GetHostClient {
-	final int BUFSIZE = 1024;
-	final String MCASTADDR = "224.0.0.1";
-	final int PORT = 8183;
-	private byte[] buf = new byte[BUFSIZE];
-	private InetAddress mAddr;
-	private MulticastSocket soc;
-	private String str;
-
-	public GetHostClient(String _str) {
-		str = _str;
-	}
-
-	public void createSocket() {
-		try {
-			mAddr = InetAddress.getByName(MCASTADDR);
-			soc = new MulticastSocket();
-			soc.setTimeToLive(1);
-		} catch (IOException e) {
-			e.printStackTrace();
-		}
-	}
-
-	public void sendData() {
-		buf = str.getBytes();
-		// System.out.println("strlen"+str.length());
-		// System.out.println("str"+str);
-		DatagramPacket sendPacket = new DatagramPacket(buf, str.length(),
-				mAddr, PORT);
-		try {
-			soc.send(sendPacket);
-		} catch (IOException e) {
-			e.printStackTrace();
-		}
-	}
-/*
-	@Override
-	public void run() {
-		createSocket();
-		while (true) {
-			sendData();
-			try {
-				Thread.sleep(2000);
-			} catch (InterruptedException e) {
-				System.out.println(e);
-			}
-		}
-	}
-	*/
-}
--- a/src/main/java/ac/ryukyu/treevnc/client/MyRfbProtoClient.java	Tue Aug 21 14:02:05 2012 +0900
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,511 +0,0 @@
-package ac.ryukyu.treevnc.client;
-
-import java.io.BufferedInputStream;
-import java.io.DataInputStream;
-import java.io.DataOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.net.BindException;
-import java.net.InetAddress;
-import java.net.ServerSocket;
-import java.net.Socket;
-import java.nio.ByteBuffer;
-import java.util.LinkedList;
-import java.util.concurrent.atomic.AtomicInteger;
-import java.util.zip.DataFormatException;
-import java.util.zip.Deflater;
-import java.util.zip.Inflater;
-
-import ac.ryukyu.*;
-import ac.ryukyu.treevnc.MulticastQueue;
-
-import com.glavsoft.exceptions.TransportException;
-import com.glavsoft.rfb.encoding.EncodingType;
-import com.glavsoft.transport.Reader;
-import com.glavsoft.viewer.ContainerManager;
-import com.glavsoft.viewer.swing.ParametersHandler.ConnectionParams;
-
-public class MyRfbProtoClient {
-	final static int FramebufferUpdate = 0;
-	final static int CheckDelay = 11;
-	final static String versionMsg_3_855 = "RFB 003.855\n";
-	private static final int INFLATE_BUFSIZE = 1024*100;
-	private Reader reader;
-	private EchoClient echoValue = new EchoClient();
-	private String host,treenum,parent,pHost,leaderflag;
-	private int echoPort,port,acceptPort;
-	Socket clientSocket,sock;
-	DataInputStream is;
-	OutputStream os;
-	private ContainerManager containerManager;
-	private ServerSocket servSock;
-	private byte initData[];
-	private int clients = 0;
-	private MulticastQueue<LinkedList<ByteBuffer>> multicastqueue = new MulticastQueue<LinkedList<ByteBuffer>>();
-	boolean proxyFlag = false;
-	int serverMajor, serverMinor;
-	int clientMajor, clientMinor;
-	
-	private Inflater inflater = new Inflater();
-	private Deflater deflater = new Deflater();
-	
-	public MyRfbProtoClient(Reader reader,String host,String port) {
-		this.reader = reader;
-	}
-	
-	public void setParam(ConnectionParams connectionParams) {
-		pHost = connectionParams.hostName;
-		echoPort = connectionParams.portNumber;
-	}
-	
-	public boolean readProxyFlag() throws TransportException {
-		int flag = reader.readUInt8();
-		if(flag == 1)
-			return true;
-		else
-			return false;
-	}
-	
-	public byte[] readEchoPort() throws Exception {
-		byte[] b = new byte[4];
-		reader.readBytes(b, 0, b.length);
-		//readFully(b);
-		return b;
-	}
-	
-	public void getParentName() {
-		if (echoValue == null) {
-
-			if (clientSocket == null) {
-
-				// echo = new EchoClient(pHost, this);
-				echoValue = new EchoClient(pHost, echoPort);
-				echoValue.openport();
-
-				echoValue = echoValue.requestHostName("1");
-			} else {
-				echoValue = new EchoClient();
-				echoValue = echoValue.Interruption(clientSocket);
-			}
-		}
-		// proxyからの返信で接続先を決定する
-		host = echoValue.responseLine;
-		parent = echoValue.parent;
-		if (echoValue.treenum != null) {
-			treenum = echoValue.treenum;
-		} else {
-			treenum = echoValue.treenum;
-		}
-		
-		if (echoValue.leaderflag != null) {
-			leaderflag = echoValue.leaderflag;
-		} else {
-			leaderflag = echoValue.leaderflag;
-		}
-	}
-	
-	int castByteInt(byte[] b) {
-		ByteBuffer bb = ByteBuffer.wrap(b);
-		int value = bb.getInt();
-		return value;
-	}
-	
-	Socket changeParent(String host, int port) throws IOException {
-		sock = new Socket(host, port);
-		return sock;
-	}
-	
-	public Socket accept() throws IOException {
-		return servSock.accept();
-	}
-	
-	void initServSock(int port) throws IOException {
-		servSock = new ServerSocket(port);
-		acceptPort = port;
-	}
-	
-	public void selectPort(int p) {
-		int port = p;
-		while (true) {
-			try {
-				initServSock(port);
-				break;
-			} catch (BindException e) {
-				port++;
-				continue;
-			} catch (IOException e) {
-
-			}
-		}
-		System.out.println("accept port = " + port);
-	}
-	
-	public void newClient(AcceptThread acceptThread, final Socket newCli,
-			final OutputStream os, final InputStream is) throws IOException {
-		// createBimgFlag = true;
-		// rfb.addSockTmp(newCli);
-		//		addSock(newCli);
-		final int myId = clients; 
-		final MulticastQueue.Client <LinkedList<ByteBuffer>> c = multicastqueue.newClient();
-		final AtomicInteger writerRunning = new AtomicInteger();
-		writerRunning.set(1);
-		/**
-		 * Timeout thread. If a client is suspended, it has top of queue indefinitely, which caused memory
-		 * overflow. After the timeout, we poll the queue and discard it. Start long wait if writer is running.
-		 */
-		final Runnable timer = new Runnable() {
-			public void run() {
-				int count = 0;
-				for(;;) {
-					long timeout = 40000/8;
-					try {
-						synchronized(this) {
-							int state,flag;
-							writerRunning.set(0);
-							wait(timeout);
-							flag = 0;
-							while((state=writerRunning.get())==0) {
-								c.poll(); // discard, should be timeout
-								count++;
-								if (flag==0) {
-									System.out.println("Discarding "+myId + " count="+ count); flag = 1;
-								}
-								wait(10); // if this is too short, writer cannot take the poll, if this is too long, memory will overflow...
-							}
-							if (flag==1) System.out.println("Resuming "+myId + " count="+count);
-							if (state!=1) {
-								System.out.println("Client died "+myId);
-								break;
-							}
-						}
-					} catch (InterruptedException e) {
-					}
-				}
-			}
-		};
-		new Thread(timer).start();
-		/**
-		 * discard all incoming from clients
-		 */
-		final Runnable reader = new Runnable() {
-			public void run() {
-				byte b[] = new byte[4096];
-				for(;;) {
-					try {
-						int c = is.read(b);
-						if (c<=0) throw new IOException();
-						// System.out.println("client read "+c);
-					} catch (IOException e) {
-						try {
-							writerRunning.set(2);
-							os.close();
-							is.close();
-						} catch (IOException e1) {
-						}
-						return;
-					}
-				}
-			}
-		};
-		/**
-		 * send packets to a client
-		 */
-		Runnable sender = new Runnable() {
-			public void run() {
-				writerRunning.set(1);
-				try {
-					/**
-					 *  initial connection of RFB protocol
-					 */
-					sendRfbVersion(os);
-//					readVersionMsg(is);
-					int rfbMinor = readVersionMsg(is,os);
-					sendSecurityType(os);
-					readSecType(is);
-					sendSecResult(os);
-					readClientInit(is);
-					sendInitData(os);
-					new Thread(reader).start(); // discard incoming packet here after.
-					if(rfbMinor == 855){
-						//checkDilay(os);
-						// send jpeg data of full screen.
-						// sendFullScreen("jpeg" ,os);
-					} else {
-						// send raw data of full screen.
-						
-					}
-					for (;;) {
-						LinkedList<ByteBuffer> bufs = c.poll();
-						int inputIndex = 0;
-						ByteBuffer header = bufs.get(inputIndex);
-						if (header==null) continue;
-						if (header.get(0)==CheckDelay) {
-							System.out.println("--------------------");
-							//writeToClient(os, bufs, inputIndex);
-						}
-						if (header.get(0)==FramebufferUpdate) {
-							// System.out.println("client "+ myId);
-						}
-						writeToClient(os, bufs, inputIndex);
-						writerRunning.set(1);  // yes my client is awaking.
-					}
-				} catch (IOException e) {
-					try {
-						writerRunning.set(2);
-						os.close();
-					} catch (IOException e1) {
-						/* if socket closed 	cliList.remove(newCli); */
-					}
-				}
-			}
-
-			public void writeToClient(final OutputStream os,
-					LinkedList<ByteBuffer> bufs, int inputIndex)
-					throws IOException {
-				while(inputIndex < bufs.size()) {
-					ByteBuffer b = bufs.get(inputIndex++);
-					os.write(b.array(), b.position(), b.limit());
-				}
-				os.flush();
-			}
-		};
-		clients++;
-		new Thread(sender).start();
-
-	}
-	
-	void sendRfbVersion(OutputStream os) throws IOException {
-		os.write(versionMsg_3_855.getBytes());
-//		os.write(versionMsg_3_8.getBytes());
-	}
-	int readVersionMsg(InputStream is, OutputStream os) throws IOException {
-
-		byte[] b = new byte[12];
-
-		is.read(b);
-
-		if ((b[0] != 'R') || (b[1] != 'F') || (b[2] != 'B') || (b[3] != ' ')
-				|| (b[4] < '0') || (b[4] > '9') || (b[5] < '0') || (b[5] > '9')
-				|| (b[6] < '0') || (b[6] > '9') || (b[7] != '.')
-				|| (b[8] < '0') || (b[8] > '9') || (b[9] < '0') || (b[9] > '9')
-				|| (b[10] < '0') || (b[10] > '9') || (b[11] != '\n')) {
-			throw new IOException("Host " + host + " port " + port
-					+ " is not an RFB server");
-		}
-
-		int rfbMajor = (b[4] - '0') * 100 + (b[5] - '0') * 10 + (b[6] - '0');
-		int rfbMinor = (b[8] - '0') * 100 + (b[9] - '0') * 10 + (b[10] - '0');
-
-		if (rfbMajor < 3) {
-			throw new IOException(
-			"RFB server does not support protocol version 3");
-		}
-
-		if (rfbMinor == 855) {
-			sendProxyFlag(os);
-//			if(proxyFlag)sendPortNumber(os);
-		}
-		return rfbMinor;
-		
-	}	void readVersionMsg(InputStream is) throws IOException {
-
-		byte[] b = new byte[12];
-
-		is.read(b);
-
-		if ((b[0] != 'R') || (b[1] != 'F') || (b[2] != 'B') || (b[3] != ' ')
-				|| (b[4] < '0') || (b[4] > '9') || (b[5] < '0') || (b[5] > '9')
-				|| (b[6] < '0') || (b[6] > '9') || (b[7] != '.')
-				|| (b[8] < '0') || (b[8] > '9') || (b[9] < '0') || (b[9] > '9')
-				|| (b[10] < '0') || (b[10] > '9') || (b[11] != '\n')) {
-			throw new IOException("Host " + host + " port " + port
-					+ " is not an RFB server");
-		}
-
-		serverMajor = (b[4] - '0') * 100 + (b[5] - '0') * 10 + (b[6] - '0');
-		serverMinor = (b[8] - '0') * 100 + (b[9] - '0') * 10 + (b[10] - '0');
-
-		if (serverMajor < 3) {
-			throw new IOException(
-					"RFB server does not support protocol version 3");
-		}
-
-	}
-	
-	void sendSecurityType(OutputStream os) throws IOException {
-		// number-of-security-types
-		os.write(1);
-		// security-types
-		// 1:None
-		os.write(1);
-	}
-	void readSecType(InputStream is) throws IOException {
-		byte[] b = new byte[1];
-		is.read(b);
-
-	}
-	
-	void sendSecResult(OutputStream os) throws IOException {
-		byte[] b = castIntByte(0);
-		os.write(b);
-	}
-	
-	void readClientInit(InputStream in) throws IOException {
-		byte[] b = new byte[0];
-		in.read(b);
-	}
-	
-	void sendInitData(OutputStream os) throws IOException {
-		os.write(initData);
-	}
-	
-	void sendProxyFlag(OutputStream os) throws IOException {
-		if(proxyFlag) os.write(1);
-		else os.write(0);
-	}
-	
-	byte[] castIntByte(int len) {
-		byte[] b = new byte[4];
-		b[0] = (byte) ((len >>> 24) & 0xFF);
-		b[1] = (byte) ((len >>> 16) & 0xFF);
-		b[2] = (byte) ((len >>> 8) & 0xFF);
-		b[3] = (byte) ((len >>> 0) & 0xFF);
-		return b;
-	}
-	
-	/**
-	 * gzip byte arrays
-	 * @param deflater
-	 * @param inputs
-	 *            byte data[]
-	 * @param inputIndex 
-	 * @param outputs
-	 *            byte data[]
-	 * @return  byte length in last byte array
-	 * @throws IOException
-	 */
-	public int zip(Deflater deflater,LinkedList<ByteBuffer> inputs, int inputIndex, LinkedList<ByteBuffer> outputs) throws IOException {
-		int len = 0;
-		ByteBuffer c1= ByteBuffer.allocate(INFLATE_BUFSIZE);
-		while(inputIndex < inputs.size() ) {
-			ByteBuffer b1 = inputs.get(inputIndex++);
-			deflater.setInput(b1.array(),b1.position(),b1.remaining());
-			/**
-			 * If we finish() stream and reset() it, Deflater start new gzip stream, this makes continuous zlib reader unhappy.
-			 * if we remove finish(), Deflater.deflate() never flushes its output. The original zlib deflate has flush flag. I'm pretty
-			 * sure this a kind of bug of Java library.
-			 */
-			if (inputIndex==inputs.size())	
-				deflater.finish();
-			int len1 = 0;
-			do {
-				len1 = deflater.deflate(c1.array(),c1.position(),c1.remaining());
-				if (len1>0) {
-					len += len1;
-					c1.position(c1.position()+len1); 
-					if (c1.remaining()==0) {
-						c1.flip();	outputs.addLast(c1);
-						c1 = ByteBuffer.allocate(INFLATE_BUFSIZE);
-					}
-				}
-			} while (len1 >0 || !deflater.needsInput()); // &&!deflater.finished());
-		}
-		if (c1.position()!=0) {
-			c1.flip();	outputs.addLast(c1);
-		}
-		deflater.reset();
-		return len;
-	}
-	
-	
-	/**
-	 * gunzip byte arrays
-	 * @param inflater
-	 * @param inputs
-	 *            byte data[]
-	 * @param outputs
-	 *            byte data[]
-	 *@return  number of total bytes            
-	 * @throws IOException
-	 */
-	public int unzip(Inflater inflater, LinkedList<ByteBuffer> inputs,
-			int inputIndex, LinkedList<ByteBuffer> outputs, int bufSize)
-			throws DataFormatException {
-		int len = 0;
-		ByteBuffer buf = ByteBuffer.allocate(bufSize);
-		while (inputIndex < inputs.size()) {
-			ByteBuffer input = inputs.get(inputIndex++);
-			inflater.setInput(input.array(), input.position(), input.limit());
-			// if (inputIndex==inputs.size()) if inflater/deflater has symmetry,
-			// we need this
-			// inflater.end(); but this won't work
-			do {
-				int len0 = inflater.inflate(buf.array(), buf.position(),
-						buf.remaining());
-				if (len0 > 0) {
-					buf.position(buf.position() + len0);
-					len += len0;
-					if (buf.remaining() == 0) {
-						buf.flip();
-						outputs.addLast(buf);
-						buf = ByteBuffer.allocate(bufSize);
-					}
-				}
-			} while (!inflater.needsInput());
-		}
-		if (buf.position() != 0) {
-			buf.flip();
-			outputs.addLast(buf);
-		}
-		return len;
-	}
-	
-	void readSendData(int dataLen,Reader reader) throws IOException, DataFormatException, TransportException {
-		LinkedList<ByteBuffer>bufs = new LinkedList<ByteBuffer>();
-		ByteBuffer header = ByteBuffer.allocate(16);
-		reader.readBytes(header.array(),0,16); 
-		header.limit(16);
-		if (header.get(0)==FramebufferUpdate) {
-			int encoding = header.getInt(12);
-			if (encoding==EncodingType.ZRLE.getId()||encoding==EncodingType.ZLIB.getId()) { // ZRLEE is already recompressed
-				ByteBuffer len = ByteBuffer.allocate(4);
-				reader.readBytes(len.array(),0,4); len.limit(4);
-				ByteBuffer inputData = ByteBuffer.allocate(dataLen-20);
-				reader.readBytes(inputData.array(),0,inputData.capacity()); inputData.limit(dataLen-20);
-				LinkedList<ByteBuffer>inputs = new LinkedList<ByteBuffer>();
-				inputs.add(inputData);
-
-				header.putInt(12, EncodingType.ZRLEE.getId()); // means recompress every time
-				// using new Deflecter every time is incompatible with the protocol, clients have to be modified.
-				Deflater nDeflater = deflater; // new Deflater();
-				LinkedList<ByteBuffer> out = new LinkedList<ByteBuffer>();
-				unzip(inflater, inputs, 0 , out, INFLATE_BUFSIZE);
-				// dump32(inputs);
-				int len2 = zip(nDeflater, out, 0, bufs);
-				ByteBuffer blen = ByteBuffer.allocate(4); blen.putInt(len2); blen.flip();
-				bufs.addFirst(blen);
-
-				bufs.addFirst(header);
-				multicastqueue.put(bufs);
-				is.reset();
-				return ;
-			}
-		} 
-		bufs.add(header);
-		if (dataLen>16) {
-			ByteBuffer b = ByteBuffer.allocate(dataLen-16);
-			reader.readBytes(b.array(),0,dataLen-16); b.limit(dataLen-16);
-			bufs.add(b);
-		}
-		multicastqueue.put(bufs);
-		is.reset();
-
-		// It may be compressed. We can inflate here to avoid repeating clients decompressing here,
-		// 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.
-	}
-
-
-	
-}
--- a/src/main/java/ac/ryukyu/treevnc/client/MyVncClient.java	Tue Aug 21 14:02:05 2012 +0900
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,204 +0,0 @@
-package ac.ryukyu.treevnc.client;
-
-import java.awt.event.WindowEvent;
-import java.awt.event.WindowListener;
-import java.io.IOException;
-import java.util.logging.Logger;
-
-import javax.swing.SwingUtilities;
-
-
-import com.glavsoft.exceptions.AuthenticationFailedException;
-import com.glavsoft.exceptions.FatalException;
-import com.glavsoft.exceptions.TransportException;
-import com.glavsoft.exceptions.UnsupportedProtocolVersionException;
-import com.glavsoft.exceptions.UnsupportedSecurityTypeException;
-import com.glavsoft.rfb.IChangeSettingsListener;
-import com.glavsoft.rfb.IRfbSessionListener;
-import com.glavsoft.rfb.protocol.Protocol;
-import com.glavsoft.rfb.protocol.ProtocolSettings;
-import com.glavsoft.transport.Reader;
-import com.glavsoft.transport.Writer;
-import com.glavsoft.viewer.ConnectionManager;
-import com.glavsoft.viewer.TreeConnectionManager;
-import com.glavsoft.viewer.Viewer;
-import com.glavsoft.viewer.cli.Parser;
-import com.glavsoft.viewer.swing.ClipboardControllerImpl;
-import com.glavsoft.viewer.swing.ParametersHandler;
-import com.glavsoft.viewer.swing.Surface;
-import com.glavsoft.viewer.swing.UiSettings;
-import com.glavsoft.viewer.swing.ParametersHandler.ConnectionParams;
-
-
-public class MyVncClient extends Viewer implements IRfbSessionListener,
-	WindowListener, IChangeSettingsListener {
-
-	/**
-	 * 
-	 */
-	private static final long serialVersionUID = 1L;
-	// private boolean runflag = false;
-
-	boolean isClient = false;
-	public static final int DEFAULT_PORT = 5900;
-	public static Logger logger = Logger.getLogger("com.glavsoft");
-	private boolean forceReconnection;
-	private String reconnectionReason;
-	private ConnectionParams connectionParams;
-	private final ProtocolSettings settings;
-	private final UiSettings uiSettings;
-	private String[] arguments;
-	private TreeConnectionManager treeConnectionManager;
-	
-	
-	public MyVncClient() {
-		connectionParams = new ParametersHandler.ConnectionParams();
-		settings = ProtocolSettings.getDefaultSettings();
-		uiSettings = super.uiSettings;
-		treeConnectionManager = new TreeConnectionManager(this, isApplet);
-	}
-	
-	public MyVncClient(Parser parser) {
-		this();
-		ParametersHandler.completeSettingsFromCLI(parser, connectionParams, settings, uiSettings);
-		showControls = ParametersHandler.showControls;
-		passwordFromParams = parser.getValueFor(ParametersHandler.ARG_PASSWORD);
-		logger.info("TightVNC Viewer version " + ver());
-		isApplet = false;
-	}
-
-	public void treeVncClient(String[] argv) {
-		new MyVncClient();
-		//v.runClient(argv);
-	}
-
-	// private void runClient(String[] argv) {
-	public static void main(String[] argv) {
-		String[] mainArgs = argv;
-		System.out.println(mainArgs.length);
-		// input into arguments Decision
-
-		Parser parser = new Parser();
-		ParametersHandler.completeParserOptions(parser);
-
-		parser.parse(argv);
-		if (parser.isSet(ParametersHandler.ARG_HELP)) {
-			printUsage(parser.optionsUsage());
-			System.exit(0);
-		}
-		MyVncClient myClient = new MyVncClient(parser);
-		myClient.setType();
-		SwingUtilities.invokeLater(myClient);
-	}
-	
-	public void setType() {
-		super.setType(treeConnectionManager);
-	}
-	
-	public void mainLoop() {
-	//	getHostData();
-		if (forceReconnection) {
-			treeConnectionManager.showReconnectDialog("Connection lost", reconnectionReason);
-			forceReconnection = false;
-		}
-		tryAgain = true;
-		while (tryAgain) {
-		  connectionParams.hostName = arguments[0];
-		//	workingSocket = connectionManager.connectToTreeHost(connectionParams, settings);
-			workingSocket = treeConnectionManager.connectToHost(connectionParams, settings);
-			if (null == workingSocket) {
-				closeApp();
-				break;
-			}
-			logger.info("Connected");
-
-			try {
-				workingSocket.setTcpNoDelay(true); // disable Nagle algorithm
-				Reader reader = new Reader(workingSocket.getInputStream());
-				Writer writer = new Writer(workingSocket.getOutputStream());
-				
-				workingProtocol = new Protocol(reader, writer,
-						new PasswordChooser(passwordFromParams, connectionParams, containerFrame, this),
-						settings);
-
-				workingProtocol.handshake();
-				// input into change parents
-                ClipboardControllerImpl clipboardController =
-		                new ClipboardControllerImpl(workingProtocol, settings.getRemoteCharsetName());
-				clipboardController.setEnabled(settings.isAllowClipboardTransfer());
-				settings.addListener(clipboardController);
-
-				surface = new Surface(workingProtocol, this, uiSettings.getScaleFactor());
-				settings.addListener(this);
-				uiSettings.addListener(surface);
-				containerFrame = createContainer();
-				treeConnectionManager.setContainerFrame(containerFrame);
-				updateFrameTitle();
-
-				workingProtocol.startNormalHandling(this, surface, clipboardController);
-				tryAgain = false;
-			} catch (UnsupportedProtocolVersionException e) {
-				treeConnectionManager.showReconnectDialog("Unsupported Protocol Version", e.getMessage());
-				logger.severe(e.getMessage());
-			} catch (UnsupportedSecurityTypeException e) {
-				treeConnectionManager.showReconnectDialog("Unsupported Security Type", e.getMessage());
-				logger.severe(e.getMessage());
-			} catch (AuthenticationFailedException e) {
-				passwordFromParams = null;
-				treeConnectionManager.showReconnectDialog("Authentication Failed", e.getMessage());
-				logger.severe(e.getMessage());
-			} catch (TransportException e) {
-				treeConnectionManager.showReconnectDialog("Connection Error", "Connection Error" + ": " + e.getMessage());
-				logger.severe(e.getMessage());
-			} catch (IOException e) {
-				treeConnectionManager.showReconnectDialog("Connection Error", "Connection Error" + ": " + e.getMessage());
-				logger.severe(e.getMessage());
-			} catch (FatalException e) {
-				treeConnectionManager.showReconnectDialog("Connection Error", "Connection Error" + ": " + e.getMessage());
-				logger.severe(e.getMessage());
-			}
-		}
-
-	}
-
-
-	public void setArgments(String[] args) {
-		arguments = args;
-	}
-
-
-	@Override
-	public void destroy() {
-		// TODO Auto-generated method stub
-
-	}
-
-	
-
-	@Override
-	public void windowClosing(WindowEvent e) {
-		if (e != null && e.getComponent() != null) {
-			e.getWindow().setVisible(false);
-		}
-		closeApp();
-	}
-
-	@Override
-	public void windowActivated(WindowEvent e) { /*nop*/ }
-
-	@Override
-	public void windowClosed(WindowEvent e) { /*nop*/ }
-
-	@Override
-	public void windowDeactivated(WindowEvent e) { /*nop*/ }
-
-	@Override
-	public void windowDeiconified(WindowEvent e) { /*nop*/ }
-
-	@Override
-	public void windowIconified(WindowEvent e) { /*nop*/ }
-
-	@Override
-	public void windowOpened(WindowEvent e) { /*nop*/ }
-
-}
--- a/src/main/java/ac/ryukyu/treevnc/client/TextBoxClient.java	Tue Aug 21 14:02:05 2012 +0900
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,206 +0,0 @@
-package ac.ryukyu.treevnc.client;
-
-import javax.swing.*;
-import java.awt.*;
-import java.awt.event.*;
-import java.util.ArrayList;
-
-public class TextBoxClient extends JFrame implements ActionListener,
-		ItemListener {
-
-	/**
-	 * 
-	 */
-	private static final long serialVersionUID = 1L;
-	private JPanel panel = new JPanel();
-	private JButton button = new JButton("Connect");
-	private TextField t1;
-	private TextField t2;
-	private double width = 750;
-	private double height = 500;
-	private JLabel label;
-	private boolean flag;
-	private ArrayList<String> temp = new ArrayList<String>();
-	private int counter = 0;
-	// 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();
-		setButton();
-		visible();
-	}
-
-	private void setSize() {
-		Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
-		width = (d.getWidth() / 2);
-		height = (d.getHeight() / 2);
-	}
-
-	public void visible() {
-		Point point = new Point();
-		point.setLocation(width - 250, height - 80);
-		setLocation(point.getLocation());
-		pack();
-		setVisible(true);
-	}
-
-	public void unVisible() {
-		setVisible(false);
-	}
-
-	private  void setText() {
-		t1 = new TextField("Address", 30);
-		t2 = new TextField("5999", 5);
-		panel.add(t1);
-		panel.add(t2);
-		//panel.add(button);
-		//button.addActionListener(this);
-		label = new JLabel();
-		Container contentPane = getContentPane();
-		contentPane.add(panel, BorderLayout.CENTER);
-		contentPane.add(label, BorderLayout.SOUTH);
-	}
-
-	public void checkBox(String str) {
-		// CheckboxGroup ch = new CheckboxGroup();
-		if (counter == 0)
-			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].addItemListener(this);
-		panel.add(check[counter]);
-		panel.setLayout(new GridLayout(counter + 2, 0));
-		panel.setLocation((int) width - 250, (int) height - 80);
-		counter++;
-	}
-
-	public void setButton() {
-		panel.add(button);
-		// 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));
-		label.setFont(new Font("Arial", Font.PLAIN, 20));
-		pane.add(label);
-	}
-
-	public String getAddressOption() {
-		while (!(flag)) {
-			try {
-				Thread.sleep(500);
-			} catch (InterruptedException e) {
-				e.printStackTrace();
-			}
-		}
-		return t1.getText();
-	}
-
-	public String getAddress() {
-		int i = 0;
-		while (!(flag)) {
-			if (i >= 50) {
-				/*
-				reportWindow();
-				visible();
-				break;
-				*/
-				return "notFound";
-			}
-			try {
-				Thread.sleep(500);
-			} catch (InterruptedException e) {
-				e.printStackTrace();
-			}
-			i++;
-		}
-		return hostAddress;
-		// return t1.getText();
-	}
-
-	public String getPortOption() {
-		return t2.getText();
-	}
-
-	public String getPort() {
-		return port;
-		// return t2.getText();
-	}
-
-	public void actionPerformed(ActionEvent e) {
-		System.out.println("Action");
-		flag = true;
-		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());
-				unVisible();
-				// else
-				// setStatus()
-			}
-		}
-	}
-
-	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("port=" + port);
-			hostAddress = temp[3];
-		}
-	}
-
-	String splitString(String str) {
-		String[] split = str.split("\\*");
-		String comper;
-		if (split.length > 4) {
-			split[4] = null;
-		}
-		comper = split[1] + split[3];
-		if (firstFlag) {
-			temp.add(comper);
-			firstFlag = false;
-			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];
-				}
-			} else {
-				break;
-			}
-		}
-		return null;
-	}
-
-	public void itemStateChanged(ItemEvent e) {
-	}
-}
--- a/src/main/java/ac/ryukyu/treevnc/client/WaitReply.java	Tue Aug 21 14:02:05 2012 +0900
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,54 +0,0 @@
-package ac.ryukyu.treevnc.client;
-
-import java.io.IOException;
-import java.net.ServerSocket;
-import java.net.Socket;
-import ac.ryukyu.treevnc.*;
-
-
-public class WaitReply extends Thread {
-	InterfaceForViewer client;
-	private String treenum;
-	boolean passflag;
-	
-
-
-	public WaitReply(String treenum, InterfaceForViewer client) {
-		this.client = client;
-		this.treenum = treenum;
-	}
-	
-	public boolean checkPath() {
-		return passflag;
-	}
-	
-	public void run() {
-		Socket clientSocket = null;
-		ServerSocket echoServer = null;
-
-		while (true) {
-			try {
-				echoServer = new ServerSocket(10001);
-				clientSocket = echoServer.accept();
-				
-				if (clientSocket != null) {
-					client.close();
-					/*
-					passflag = true;
-					client.setClientSocket(clientSocket);
-					client.init();
-					client.setEchoValue(null);
-					client.getParentName();
-					client.start_threads();
-					client.start();
-					*/
-					client.run();
-					echoServer.close();
-				}
-
-			} catch (IOException e) {
-				System.out.println(e);
-			}
-		}
-	}
-}
--- a/src/main/java/ac/ryukyu/treevnc/server/AcceptClient.java	Tue Aug 21 14:02:05 2012 +0900
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,303 +0,0 @@
-package ac.ryukyu.treevnc.server;
-
-import java.net.Socket;
-import java.net.UnknownHostException;
-import java.io.*;
-import java.net.*;
-import java.util.*;
-
-public class AcceptClient {
-	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;
-	private int passCheck = 0;
-	private final int treebranch = 2; // treeの子ノードの数 
-	private String newparent,request,myAddress;
-	private String leaderflag = "0", sendleaderflag = "0";
-	private final int intv_time = 100;
-
-
-
-	public AcceptClient(String name) {
-		//this.name = name;
-	}
-
-
-	/*
-	public AcceptClient() {
-		new CreateThread(this);
-	}
-	*/
-
-	// public synchronized void transferParentAddrerss(BufferedReader
-	// is,PrintStream os) {
-	public void transferParentAddrerss(BufferedReader is,PrintStream os) {
-		// クライアントからのメッセージを待ち、受け取ったメッセージをそのまま返す
-		try {
-			while (true) {
-				String line = is.readLine();
-				String port = is.readLine();
-				myAddress = getMyAddress();
-				if ("1".equals(line)||"3".equals(line)) {
-					String treeNumber = is.readLine();
-					// reply to Parents lost node
-					checkWait(os,is,port,Integer.parseInt(treeNumber));
-					
-				} else if ("2".equals(line)) {
-					// reply to not Found Parents
-					replyNodeInformation(port);
-					listupdate(port, newparent);
-					outputStream(os, newparent, String.valueOf(parentnum),
-							port, leaderflag);
-					os.close();
-					is.close();
-				} else if (line!=null){
-					//connection First time
-					if(checkAddress(line)){
-						outputStream(os, myAddress,"0","0","0");
-						break;
-					}else {
-						if(replyCreateTree(os, port, line)) {
-							break;
-						} else {
-							break;
-						}
-					}
-				}
-			}
-		} catch (IOException e) {
-			System.out.println(e);
-		} catch (InterruptedException e) {
-			e.printStackTrace();
-		}
-	}
-	
-	private boolean checkAddress(String line){
-		String test[] = line.split("\\.");
-		int a = Integer.parseInt(test[0]);
-		int b = Integer.parseInt(test[1]);
-		if((192==a&&b==168)||(172==a&&(b>15||b<32))||10==a) {
-			return true;
-		} else{
-			return false;		
-		}
-	}
-
-	/**
-	 * @param port
-	 *            parent value
-	 */
-	private synchronized void listupdate(String port) {
-		ls.remove(Integer.parseInt(port));
-		ls.add(Integer.parseInt(port), ls.getLast());
-		ls.removeLast();
-	}
-	
-	private synchronized void listupdate(String port,String myaddr) {
-		ls.remove(Integer.parseInt(port));
-		ls.add(Integer.parseInt(port), myaddr);
-		ls.removeLast();
-	}
-
-	private void outputStream(PrintStream os, String request, String parentnum,
-			String treenum, String leaderflag) {
-		os.println(request);
-		os.println(parentnum);
-		os.println(treenum);
-		os.println(leaderflag);
-	}
-
-	private void checkParameter(int parent, int counter, String leaderflag) {
-		System.out.println("number p =" + parentnum);
-		System.out.println("number i =" + counter);
-		System.out.println("leaderflag=" + leaderflag + "\n");
-	}
-
-	private synchronized void addClientAdress(String line, LinkedList<String> ls) {
-		if (line != null) {
-			ls.add(line);
-		}
-		//displyLinkedList(ls);
-	}
-	
-	private void displyLinkedList( LinkedList<String> ls) {
-		int g = 0;
-		for (String bs : ls) {
-			System.out.println(g + "number" + bs);
-			g++;
-		}
-	}
-
-	private String decisionLeader(int counter, int treebranch) {
-		if ((counter - 1) % treebranch == 1) { // children in most young treenum
-												// have leaderflag 1 other 0
-			return "0";
-		} else {
-			return "1";
-		}
-	}
-	
-	String getMyAddress () {
-		InetAddress addr = null;
-		try {
-			addr = InetAddress.getLocalHost();
-		} catch (UnknownHostException e) {
-			e.printStackTrace();
-		}
-		return new String(addr.getHostAddress());
-	}
-	
-	private void replyNodeInformation (String port) {
-		parentnum = (Integer.parseInt(port) - 1) / treebranch;
-		newparent = ls.get(parentnum);
-		sendleaderflag = decisionLeader(Integer.parseInt(port), treebranch);
-		//leaderflag = decisionLeader(Integer.parseInt(port),treebranch);
-	}
-	
-	private void replyLeaderNode(PrintStream os,BufferedReader is,String port,String treeNumber) throws IOException, InterruptedException {
-		os.println(ls.getLast());
-		replyNodeInformation(port);
-		counter--;
-		passCheck = 1;
-		reportLastNode(ls.getLast(), newparent,port, String.valueOf(parentnum),sendleaderflag);
-		listupdate(port);
-		waitThread();
-		/*
-		if (Integer.parseInt(treeNumber)==ls.size()-1)
-			return;
-			*/
-		//displyLinkedList(ls);
-		os.println(port);
-		leaderflag = decisionLeader(Integer.parseInt(treeNumber),treebranch);
-		os.println(treeNumber);
-		Thread.sleep(intv_time);
-		is.close();
-		os.close();
-	}
-	
-	private void replyNormalChildren(PrintStream os,BufferedReader is,String port,String treeNumber,boolean flag) throws IOException, InterruptedException {
-		if(flag)
-			notifyThread();
-		else
-			waitThread();
-		if (Integer.parseInt(treeNumber)==ls.size())
-			return;
-		os.println(ls.get(Integer.parseInt(port)));
-		os.println(port);
-		if(ls.size()-1+passCheck == Integer.parseInt(treeNumber))
-			treeNumber = "skip";
-		passCheck = 0;
-		os.println(treeNumber);
-		System.out.println("num4="+ ls.get(Integer.parseInt(port)));
-		runflag = false;
-		is.close();
-		os.close();
-	}
-	
-	private synchronized boolean replyCreateTree(PrintStream os,String port,String line) throws InterruptedException {
-		if (addrRegistor == true) {
-			ls.add(myAddress);
-			addrRegistor = false;
-		}
-
-		if (line != null) {
-			addClientAdress(line, ls);
-			counter++;
-		} else {
-			return true;
-		}
-		
-		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),
-					String.valueOf(counter), leaderflag);
-			checkParameter(parentnum, counter, leaderflag);
-		} else {
-			// treeの親ノードに接続する人に接続する人を教える
-			outputStream(os, myAddress, "0",
-					String.valueOf(counter), leaderflag);
-		}
-		Thread.sleep(intv_time);
-		return false;
-	}
-
-	void reportLastNode(String newchild, String newparent, String newtreenum,
-			String newpnum, String newleaderflag) throws IOException {
-		try {
-			Socket echoSocket;
-			System.out.println(newchild + "connect");
-			// echoSocket = new Socket(newchild, 10001 + (i + 1));//
-			// i+1は実験中に同じマシーンを使っていたのでportを変えて対応、本番時には取り除く予定。
-			echoSocket = new Socket(newchild, 10001);
-			DataOutputStream os = new DataOutputStream(echoSocket.getOutputStream());
-			os.writeBytes(newparent + "\n");
-			os.writeBytes(newpnum + "\n");
-			os.writeBytes(newtreenum + "\n");
-			os.writeBytes(newleaderflag + "\n");
-			os.close();
-		} catch (UnknownHostException e) {
-			System.err.println("Don't know about host: localhost");
-		} catch (IOException e) {
-			System.err
-					.println("Couldn't get I/O for the connection to: localhost");
-		}
-	}
-
-	void reportFinishFlag(String nextLastNode) {
-		Socket echoSocket;
-		try {
-			echoSocket = new Socket(nextLastNode, 10001);
-			DataOutputStream os = new DataOutputStream(
-					echoSocket.getOutputStream());
-			os.writeBytes("lastnode" + "\n");
-		} catch (UnknownHostException e) {
-			e.printStackTrace();
-		} catch (IOException e) {
-			e.printStackTrace();
-		}
-
-	}
-	
-	synchronized void checkWait(PrintStream os,BufferedReader is,String port,int treeNum) throws InterruptedException, IOException {
-		final int TIMEOUT = 3000;
-		if (passNumber == 0) {
-			passNumber++;
-			numberZone = ((treeNum - 1) / treebranch);
-			//System.out.println(treeNum + "--wait--");
-			replyLeaderNode(os,is,port,String.valueOf(treeNum));
-			notifyAll();
-			passNumber = 0;
-		} else if (numberZone == ((treeNum - 1) / treebranch)) {
-			if (++passNumber == treebranch) {
-				//System.out.println(treeNum + "--notify--");
-				passNumber = 0;
-				replyNormalChildren(os,is,port,String.valueOf(treeNum),true);
-			} else {
-				//System.out.println(treeNum + "--waityobi--");
-				replyNormalChildren(os,is,port,String.valueOf(treeNum),false);
-				wait(TIMEOUT);
-			}
-		} else {
-			wait();
-			checkWait(os,is,port,treeNum);
-		}
-	}
-	
-	private void waitThread() {
-		final int TIMEOUT = 3000;
-		try {
-			wait(TIMEOUT);
-		} catch (InterruptedException e) {
-			e.printStackTrace();
-		}
-	}
-	private void notifyThread() {
-		notifyAll();
-	}
- }
\ No newline at end of file
--- a/src/main/java/ac/ryukyu/treevnc/server/AcceptThread.java	Tue Aug 21 14:02:05 2012 +0900
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,42 +0,0 @@
-package ac.ryukyu.treevnc.server;
-import java.net.Socket;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-
-public class AcceptThread implements Runnable {
-        MyRfbProto rfb = null;
-        byte[] imageBytes;
-        int port;
-        
-        AcceptThread(MyRfbProto _rfb) {
-                rfb = _rfb;
-        }
-
-
-        AcceptThread(MyRfbProto _rfb, int p) {
-            rfb = _rfb;
-            port = p;
-        }
-       
-	public void changeRfb(MyRfbProto _rfb) {
-		rfb = _rfb;
-	}
-
-	public void run() {
-		rfb.selectPort(port);
-
-		while (true) {
-			try {
-				Socket newCli = rfb.accept();
-
-				OutputStream os = newCli.getOutputStream();
-				InputStream is = newCli.getInputStream();
-				rfb.newClient(this, newCli, os, is);
-			} catch (IOException e) {
-				e.printStackTrace();
-				System.out.println(e);
-			}
-		}
-	}
-}
--- a/src/main/java/ac/ryukyu/treevnc/server/BroadCastProxy.java	Tue Aug 21 14:02:05 2012 +0900
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,40 +0,0 @@
-package ac.ryukyu.treevnc.server;
-
-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) {	
-		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();
-			}
-		}
-	}
-
-	void sendData() {
-		os.println(str);
-	}
-
-}
--- a/src/main/java/ac/ryukyu/treevnc/server/CreateThread.java	Tue Aug 21 14:02:05 2012 +0900
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,88 +0,0 @@
-package ac.ryukyu.treevnc.server;
-
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.InputStreamReader;
-import java.io.PrintStream;
-import java.net.BindException;
-import java.net.ServerSocket;
-import java.net.Socket;
-
-public class CreateThread implements Runnable {
-	ServerSocket echoServer;
-	AcceptClient acceptClient;
-	int port;
-	
-	public CreateThread(AcceptClient _acc) {
-		acceptClient = _acc;
-		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
-				acceptClient.transferParentAddrerss(is,os);
-			}
-		};
-		new Thread(echoSender).start();
-	}
-
-	void selectPort(int p) {
-		int port = p;
-		while (true) {
-			try {
-				initServSock(port);
-				break;
-			} catch (BindException e) {
-				port++;
-				continue;
-			} catch (IOException e) {
-
-			}
-		}
-		System.out.println("accept Echo port = " + port);
-	}
-	
-	void initServSock(int port) throws IOException {
-		echoServer = new ServerSocket(port);
-		this.port = port;
-	}
-	
-	
-	public void run() {
-		selectPort(port);
-		
-		while (true) {
-			try {
-//				echoServer = new ServerSocket(9999);
-				Socket clientSocket = echoServer.accept();
-				BufferedReader is = new BufferedReader(new InputStreamReader(
-						clientSocket.getInputStream()));
-				PrintStream os = new PrintStream(clientSocket.getOutputStream());
-				newEchoClient(is,os);
-//				acceptClient.transferParentAddrerss(is, os);
-			} catch (IOException e) {
-				System.out.println(e);
-			}
-/*
-			try {
-				echoServer.close();
-			} catch (IOException e) {
-				System.out.println(e);
-			}
-*/
-
-		}
-
-	}
-
-}
--- a/src/main/java/ac/ryukyu/treevnc/server/GetBroadCastProxy.java	Tue Aug 21 14:02:05 2012 +0900
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,98 +0,0 @@
-package ac.ryukyu.treevnc.server;
-
-import java.io.ByteArrayInputStream;
-import java.io.IOException;
-import java.net.DatagramPacket;
-import java.net.InetAddress;
-import java.net.MulticastSocket;
-import java.net.SocketAddress;
-
-//import TextBoxProxy;
-
-public class GetBroadCastProxy implements Runnable {
-	static final String McastAddr = "224.0.0.1";
-	static final int Port = 8183;
-	static final int BufSize = 1024;
-	private byte[] buf = new byte[BufSize];
-	private byte[] resorve = new byte[BufSize];
-	private ByteArrayInputStream inputStream;
-	private boolean stopFlag = false;
-	private VncProxyService vps;
-	private BroadCastProxy bCast;
-	private String address;
-
-	public GetBroadCastProxy(VncProxyService _vps){
-		vps = _vps;
-		bCast = new BroadCastProxy(vps.rfb.acceptPort+":"+vps.host+":"
-				+vps.rfb.desktopName+":"+vps.acc.getMyAddress()+":");
-	}
-	
-	private synchronized void getData() {
-		try {
-			InetAddress mAddr = InetAddress.getByName(McastAddr);
-			MulticastSocket soc = new MulticastSocket(Port);
-			DatagramPacket recvPacket = new DatagramPacket(buf, BufSize);
-			soc.joinGroup(mAddr);
-			while (true) {
-				soc.receive(recvPacket);
-				address = getAddress(recvPacket.getSocketAddress());
-				inputStream = new ByteArrayInputStream(recvPacket.getData());
-				inputStream.read(resorve);
-				if("who".equals(castString(resorve))){
-						replyBroadCast();
-				}
-			}
-		} catch (IOException e) {
-			e.printStackTrace();
-		}
-	}
-	
-	private void replyBroadCast() {
-		Runnable sender = new Runnable() {
-			public void run() {
-				bCast.createSocket(address);
-			}
-		};
-		new Thread(sender).start();
-	}
-
-	private String getAddress(SocketAddress addr) {
-		String str = addr.toString();
-		str = str.substring(1,str.indexOf(":"));
-		return str;
-	}
-/*	
-	private int castBytoToInt(byte[] a) {
-		int value = 0;
-		ByteArrayInputStream bais = new ByteArrayInputStream(a);
-		DataInputStream dis = new DataInputStream(bais);
-		try {
-			value = dis.readInt();
-		} catch (IOException e) {
-		}
-		System.out.println(value);
-		return value;
-	}
-*/
-	private String castString(byte[] a) {
-		String recover = new String(a);
-		recover = recover.replace("¥n", "");
-		recover = recover.trim();
-//		System.out.println(recover);
-		return recover;
-	}
-	
-	
-	public void run() {
-		getData();
-	}
-
-	public void setStopFlag(boolean stopFlag) {
-		this.stopFlag = stopFlag;
-	}
-
-	public boolean isStopFlag() {
-		return stopFlag;
-	}
-
-}
--- a/src/main/java/ac/ryukyu/treevnc/server/MyRfbProtoProxy.java	Tue Aug 21 14:02:05 2012 +0900
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,663 +0,0 @@
-package ac.ryukyu.treevnc.server;
-
-import static org.junit.Assert.*;
-
-import java.awt.Graphics;
-import java.awt.Image;
-import java.awt.image.BufferedImage;
-import java.io.BufferedOutputStream;
-import java.io.BufferedReader;
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.net.BindException;
-import java.net.ServerSocket;
-import java.net.Socket;
-import java.nio.ByteBuffer;
-import java.util.Iterator;
-import java.util.LinkedList;
-
-import javax.imageio.ImageIO;
-
-import org.junit.Test;
-
-import ac.ryukyu.treevnc.MulticastQueue;
-
-//import myVncProxy.MulticastQueue.Client;
-
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.atomic.AtomicInteger;
-import java.util.zip.DataFormatException;
-import java.util.zip.Deflater;
-import java.util.zip.Inflater;
-import java.io.OutputStream;
-
-public class MyRfbProtoProxy {
-	final static String versionMsg_3_855 = "RFB 003.855\n";
-	/**
-	 * CheckMillis is one of new msgType for RFB 3.855.
-	 */
-	final static byte SpeedCheckMillis = 4;
-
-	// Secyrity type of OS X
-	final static int SecTypeReqAccess = 32;
-
-	// Supported authentication types
-	final static int AuthAccess = 32;
-
-	private static final int INFLATE_BUFSIZE = 1024 * 100;
-	boolean printStatusFlag = false;
-	long startCheckTime;
-	private int messageType;
-	private int rectangles;
-	private int rectX;
-	private int rectY;
-	private int rectW;
-	private int rectH;
-	private int encoding;
-	private int zLen;
-	private boolean clicomp = false;
-
-	private ServerSocket servSock;
-	protected int acceptPort;
-	// private byte initData[];
-	byte initData[];
-	private LinkedList<Socket> cliListTmp;
-	private LinkedList<Socket> cliList;
-	boolean createBimgFlag;
-	boolean proxyFlag = true;
-
-	ExecutorService executor;
-
-	byte[] pngBytes;
-
-	// private MulticastQueue<LinkedList<ByteBuffer>> multicastqueue = new
-	// MostRecentMultiCast<LinkedList<ByteBuffer>>(10);
-	private MulticastQueue<LinkedList<ByteBuffer>> multicastqueue = new MulticastQueue<LinkedList<ByteBuffer>>();
-	private int clients = 0;
-	private Inflater inflater = new Inflater();
-	private Deflater deflater = new Deflater();
-	private CreateThread geth;
-	// private Thread requestThread;
-	private RequestScreenThread rThread;
-	private Thread requestThread;
-
-	public MyRfbProtoProxy() throws IOException {
-	}
-
-
-	void initServSock(int port) throws IOException {
-		servSock = new ServerSocket(port);
-		acceptPort = port;
-	}
-
-	void authenticationRequestAccess() throws IOException {
-
-		byte[] headBuf = new byte[2];
-		is.read(headBuf);
-		if (headBuf[1] == 2) {
-			byte[] b = new byte[258];
-			is.read(b);
-
-			byte[] outBuf = new byte[256];
-			os.write(outBuf);
-			os.flush();
-		} else if (headBuf[1] == 23) {
-			byte[] b = new byte[130];
-			is.read(b);
-			byte[] outBuf = new byte[192];
-			os.write(outBuf);
-			os.flush();
-		}
-
-		int result = readU32();
-		if (result != 0) {
-			System.out.println("faild authentication  ");
-			throw new IOException();
-		}
-
-	}
-
-	/*
-	 * default port number is 5999.
-	 */
-	public void selectPort(int p) {
-		if (servSock != null)
-			return;
-		int port = p;
-		while (true) {
-			try {
-				initServSock(port);
-				break;
-			} catch (BindException e) {
-				port++;
-				continue;
-			} catch (IOException e) {
-
-			}
-		}
-		System.out.println("accept port = " + port);
-	}
-
-	int getAcceptPort() {
-		return acceptPort;
-	}
-
-	void setSoTimeout(int num) throws IOException {
-		servSock.setSoTimeout(num);
-	}
-
-	public Socket accept() throws IOException {
-		return servSock.accept();
-	}
-
-	void addSock(Socket sock) {
-		cliList.add(sock);
-	}
-
-	void addSockTmp(Socket sock) {
-		System.out.println("connected " + sock.getInetAddress());
-		cliListTmp.add(sock);
-	}
-
-	boolean markSupported() {
-		return is.markSupported();
-	}
-
-	synchronized void changeStatusFlag() {
-		printStatusFlag = true;
-	}
-
-	void printMills() {
-		if (printStatusFlag) {
-
-			changeStatusFlag();
-		} else {
-			changeStatusFlag();
-		}
-	}
-
-
-	void requestThreadStart() {
-		requestThread.start();
-	}
-
-	public synchronized void requestThreadNotify() {
-		rThread.reStart();
-	}
-
-	/**
-	 * gzip byte arrays
-	 * 
-	 * @param deflater
-	 * @param inputs
-	 *            byte data[]
-	 * @param inputIndex
-	 * @param outputs
-	 *            byte data[]
-	 * @return byte length in last byte array
-	 * @throws IOException
-	 */
-	public int zip(Deflater deflater, LinkedList<ByteBuffer> inputs,
-			int inputIndex, LinkedList<ByteBuffer> outputs) throws IOException {
-		int len = 0;
-		ByteBuffer c1 = ByteBuffer.allocate(INFLATE_BUFSIZE);
-		while (inputIndex < inputs.size()) {
-			ByteBuffer b1 = inputs.get(inputIndex++);
-			deflater.setInput(b1.array(), b1.position(), b1.remaining());
-			/**
-			 * If we finish() stream and reset() it, Deflater start new gzip
-			 * stream, this makes continuous zlib reader unhappy. if we remove
-			 * finish(), Deflater.deflate() never flushes its output. The
-			 * original zlib deflate has flush flag. I'm pretty sure this a kind
-			 * of bug of Java library.
-			 */
-			if (inputIndex == inputs.size())
-				deflater.finish();
-			int len1 = 0;
-			do {
-				len1 = deflater.deflate(c1.array(), c1.position(),
-						c1.remaining());
-				if (len1 > 0) {
-					len += len1;
-					c1.position(c1.position() + len1);
-					if (c1.remaining() == 0) {
-						c1.flip();
-						outputs.addLast(c1);
-						c1 = ByteBuffer.allocate(INFLATE_BUFSIZE);
-					}
-				}
-			} while (len1 > 0 || !deflater.needsInput()); // &&!deflater.finished());
-		}
-		if (c1.position() != 0) {
-			c1.flip();
-			outputs.addLast(c1);
-		}
-		deflater.reset();
-		return len;
-	}
-
-	/**
-	 * gunzip byte arrays
-	 * 
-	 * @param inflater
-	 * @param inputs
-	 *            byte data[]
-	 * @param outputs
-	 *            byte data[]
-	 * @return number of total bytes
-	 * @throws IOException
-	 */
-	public int unzip(Inflater inflater, LinkedList<ByteBuffer> inputs,
-			int inputIndex, LinkedList<ByteBuffer> outputs, int bufSize)
-			throws DataFormatException {
-		int len = 0;
-		ByteBuffer buf = ByteBuffer.allocate(bufSize);
-		while (inputIndex < inputs.size()) {
-			ByteBuffer input = inputs.get(inputIndex++);
-			inflater.setInput(input.array(), input.position(), input.limit());
-			// if (inputIndex==inputs.size()) if inflater/deflater has symmetry,
-			// we need this
-			// inflater.end(); but this won't work
-			do {
-				int len0 = inflater.inflate(buf.array(), buf.position(),
-						buf.remaining());
-				if (len0 > 0) {
-					buf.position(buf.position() + len0);
-					len += len0;
-					if (buf.remaining() == 0) {
-						buf.flip();
-						outputs.addLast(buf);
-						buf = ByteBuffer.allocate(bufSize);
-					}
-				}
-			} while (!inflater.needsInput());
-		}
-		if (buf.position() != 0) {
-			buf.flip();
-			outputs.addLast(buf);
-		}
-		return len;
-	}
-
-	float maxMag = 1;
-
-	/**
-	 * send data to clients
-	 * 
-	 * @param dataLen
-	 * @throws IOException
-	 * @throws DataFormatException
-	 * 
-	 *             Zlibed packet is compressed in context dependent way, that
-	 *             is, it have to send from the beginning. But this is
-	 *             impossible. So we have to compress it again for each clients.
-	 *             Separate deflater for each clients is necessary.
-	 * 
-	 *             Java's deflater does not support flush. This means to get the
-	 *             result, we have to finish the compression. Reseting start new
-	 *             compression, but it is not accepted well in zlib continuous
-	 *             reading. So we need new Encoding ZRLEE which reset decoder
-	 *             for each packet. ZRLEE can be invisible from user, but it
-	 *             have to be implemented in the clients. 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);
-		header.limit(16);
-		if (header.get(0) == RfbProto.FramebufferUpdate) {
-			int encoding = header.getInt(12);
-			if (encoding == RfbProto.EncodingZRLE
-					|| encoding == RfbProto.EncodingZlib) { // ZRLEE is already
-															// recompressed
-				ByteBuffer len = ByteBuffer.allocate(4);
-				readFully(len.array(), 0, 4);
-				len.limit(4);
-				ByteBuffer inputData = ByteBuffer.allocate(dataLen - 20);
-
-				startTiming();
-				readFully(inputData.array(), 0, inputData.capacity());
-//				System.out.println(dataLen);
-				inputData.limit(dataLen - 20);
-				stopTiming();
-
-				LinkedList<ByteBuffer> inputs = new LinkedList<ByteBuffer>();
-				inputs.add(inputData);
-
-				header.putInt(12, RfbProto.EncodingZRLEE); // means recompress
-															// every time
-				// using new Deflecter every time is incompatible with the
-				// protocol, clients have to be modified.
-				Deflater nDeflater = deflater; // new Deflater();
-				LinkedList<ByteBuffer> out = new LinkedList<ByteBuffer>();
-				unzip(inflater, inputs, 0, out, INFLATE_BUFSIZE);
-				// dump32(inputs);
-				int len2 = zip(nDeflater, out, 0, bufs);
-				ByteBuffer blen = ByteBuffer.allocate(4);
-				blen.putInt(len2);
-				blen.flip();
-				bufs.addFirst(blen);
-
-				bufs.addFirst(header);
-			//	if(dataLen<=64000)
-					multicastqueue.put(bufs);
-				// is.reset();
-
-				/*
-				 * System.out.println("ZRLE = "+dataLen);
-				 * System.out.println("ZRLEE = "+(len2+20)); float mag =
-				 * (float)dataLen / (float)(len2 + 20);
-				 * System.out.println("ZRLE / ZRLEE = "+ mag); if(mag > maxMag)
-				 * maxMag = mag; System.out.println("maxMag = "+maxMag);
-				 */
-				return;
-			}
-			bufs.add(header);
-			if (dataLen > 16) {
-				ByteBuffer b = ByteBuffer.allocate(dataLen - 16);
-				startTiming();
-				readFully(b.array(), 0, dataLen - 16);
-				b.limit(dataLen - 16);
-				stopTiming();
-				bufs.add(b);
-			}
-			multicastqueue.put(bufs);
-			// is.reset();
-			return;
-		}
-		is.reset();
-
-		// It may be compressed. We can inflate here to avoid repeating clients
-		// decompressing here,
-		// 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.
-	}
-
-	public void newClient(AcceptThread acceptThread, final Socket newCli,
-			final OutputStream os, final InputStream is) throws IOException {
-		// createBimgFlag = true;
-		// rfb.addSockTmp(newCli);
-		// addSock(newCli);
-		final int myId = clients;
-		final MulticastQueue.Client<LinkedList<ByteBuffer>> c = multicastqueue
-				.newClient();
-		final AtomicInteger writerRunning = new AtomicInteger();
-		writerRunning.set(1);
-		/**
-		 * Timeout thread. If a client is suspended, it has top of queue
-		 * indefinitely, which caused memory overflow. After the timeout, we
-		 * poll the queue and discard it. Start long wait if writer is running.
-		 */
-		final Runnable timer = new Runnable() {
-			public void run() {
-				int count = 0;
-				for (;;) {
-					long timeout = 50000 / 8;
-					try {
-						synchronized (this) {
-							int state, flag;
-							writerRunning.set(0);
-							wait(timeout);
-							flag = 0;
-							while ((state = writerRunning.get()) == 0) {
-								c.poll(); // discard, should be timeout
-								count++;
-								if (flag == 0) {
-									System.out.println("Discarding " + myId
-											+ " count=" + count);
-									flag = 1;
-								}
-								wait(10); // if this is too short, writer cannot
-											// take the poll, if this is too
-											// long, memory will overflow...
-							}
-							if (flag == 1)
-								System.out.println("Resuming " + myId
-										+ " count=" + count);
-							if (state != 1) {
-								System.out.println("Client died " + myId);
-								break;
-							}
-						}
-					} catch (InterruptedException e) {
-					}
-				}
-			}
-		};
-		new Thread(timer).start();
-		/**
-		 * discard all incoming from clients
-		 */
-		final Runnable reader = new Runnable() {
-			public void run() {
-				byte b[] = new byte[4096];
-				for (;;) {
-					try {
-						int c = is.read(b);
-						if (c <= 0)
-							throw new IOException();
-						// System.out.println("client read "+c);
-					} catch (IOException e) {
-						try {
-							writerRunning.set(2);
-							os.close();
-							is.close();
-						} catch (IOException e1) {
-						}
-						return;
-					}
-				}
-			}
-		};
-		/**
-		 * send packets to a client
-		 */
-		Runnable sender = new Runnable() {
-			public void run() {
-				writerRunning.set(1);
-				try {
-					requestThreadNotify();
-					// rThread.checkDelay();
-
-					/**
-					 * initial connection of RFB protocol
-					 */
-					sendRfbVersion(os);
-					// readVersionMsg(is);
-					int rfbMinor = readVersionMsg(is, os);
-					sendSecurityType(os);
-					readSecType(is);
-					sendSecResult(os);
-					readClientInit(is);
-					sendInitData(os);
-					new Thread(reader).start(); // discard incoming packet here
-												// after.
-					// writeFramebufferUpdateRequest(0,0, framebufferWidth,
-					// framebufferHeight, false );
-					int i  = 0;
-					for (;;) {
-						LinkedList<ByteBuffer> bufs = c.poll();
-						int inputIndex = 0;
-						ByteBuffer header = bufs.get(inputIndex);
-						if (header == null)
-							continue;
-						else if (header.get(0) == RfbProto.CheckDelay) {
-							writeToClient(os, bufs, inputIndex);
-							continue;
-						} else if (header.get(0) == RfbProto.FramebufferUpdate) {
-							// System.out.println("client "+ myId);
-						}
-						/*
-						if(i%20==0){
-							sendDataCheckDelay();
-						}
-						i++;
-						*/
-						writeToClient(os, bufs, inputIndex);
-						writerRunning.set(1); // yes my client is awaking.
-					}
-				} catch (IOException e) {
-					try {
-						writerRunning.set(2);
-						os.close();
-					} catch (IOException e1) {
-					}
-					/* if socket closed cliList.remove(newCli); */
-				}
-			}
-
-			public void writeToClient(final OutputStream os,
-					LinkedList<ByteBuffer> bufs, int inputIndex)
-					throws IOException {
-				while (inputIndex < bufs.size()) {
-					ByteBuffer b = bufs.get(inputIndex++);
-					os.write(b.array(), b.position(), b.limit());
-				}
-				os.flush();
-			}
-		};
-		clients++;
-		new Thread(sender).start();
-
-	}
-
-	public void dump32(LinkedList<ByteBuffer> bufs) {
-		int len = 0;
-		for (ByteBuffer b : bufs)
-			len += b.remaining();
-		ByteBuffer top = bufs.getFirst();
-		ByteBuffer end = bufs.getLast();
-		System.err.println("length: " + len);
-		System.err.print("head 0: ");
-		for (int i = 0; i < 16 && i < top.remaining(); i++) {
-			System.err.print(" " + top.get(i));
-		}
-		System.err.print("tail 0: ");
-		for (int i = 0; i < 16 && i < end.remaining(); i++) {
-			System.err.print(" " + end.get(i));
-		}
-		System.err.println();
-	}
-
-	@Test
-	public void test1() {
-		try {
-			LinkedList<ByteBuffer> in = new LinkedList<ByteBuffer>();
-			LinkedList<ByteBuffer> out = new LinkedList<ByteBuffer>();
-			LinkedList<ByteBuffer> out2 = new LinkedList<ByteBuffer>();
-			// if (false) {
-			// for(int i=0;i<10;i++) {
-			// in.add(ByteBuffer.wrap("test1".getBytes()));
-			// in.add(ByteBuffer.wrap("test2".getBytes()));
-			// in.add(ByteBuffer.wrap("test3".getBytes()));
-			// in.add(ByteBuffer.wrap("test44".getBytes()));
-			// }
-			// } else
-			{
-				String t = "";
-				for (int i = 0; i < 10; i++) {
-					t += "test1";
-					t += "test2";
-					t += "test3";
-					t += "test44";
-				}
-				in.add(ByteBuffer.wrap(t.getBytes()));
-			}
-
-			LinkedList<ByteBuffer> in1 = clone(in);
-
-			Deflater deflater = new Deflater();
-			zip(deflater, in, 0, out);
-			// LinkedList<ByteBuffer> out3 = clone(out); zipped result is depend
-			// on deflator's state
-			unzip(inflater, out, 0, out2, INFLATE_BUFSIZE);
-			// inflater.reset();
-			equalByteBuffers(in1, out2);
-			LinkedList<ByteBuffer> out4 = new LinkedList<ByteBuffer>();
-			deflater = new Deflater();
-			zip(deflater, out2, 0, out4);
-			LinkedList<ByteBuffer> out5 = new LinkedList<ByteBuffer>();
-			unzip(inflater, out4, 0, out5, INFLATE_BUFSIZE);
-			int len = equalByteBuffers(in1, out5);
-
-			System.out.println("Test Ok. " + len);
-		} catch (Exception e) {
-			assertEquals(0, 1);
-		}
-	}
-
-	private LinkedList<ByteBuffer> clone(LinkedList<ByteBuffer> in) {
-		LinkedList<ByteBuffer> copy = new LinkedList<ByteBuffer>();
-		for (ByteBuffer b : in) {
-			ByteBuffer c = b.duplicate();
-			copy.add(c);
-		}
-		return copy;
-	}
-
-	public int equalByteBuffers(LinkedList<ByteBuffer> in,
-			LinkedList<ByteBuffer> out2) {
-		int len = 0;
-		Iterable<Byte> i = byteBufferIterator(in);
-		Iterator<Byte> o = byteBufferIterator(out2).iterator();
-
-		for (int b : i) {
-			len++;
-			if (o.hasNext()) {
-				int c = o.next();
-				assertEquals(b, c);
-			} else
-				assertEquals(0, 1);
-		}
-		if (o.hasNext())
-			assertEquals(0, 1);
-		// System.out.println();
-		return len;
-	}
-
-	private Iterable<Byte> byteBufferIterator(final LinkedList<ByteBuffer> in) {
-		return new Iterable<Byte>() {
-			public Iterator<Byte> iterator() {
-				return new Iterator<Byte>() {
-					int bytes = 0;
-					int buffers = 0;
-
-					public boolean hasNext() {
-						for (;;) {
-							if (buffers >= in.size())
-								return false;
-							ByteBuffer b = in.get(buffers);
-							if (!(bytes < b.remaining())) {
-								buffers++;
-								bytes = 0;
-							} else
-								return true;
-						}
-					}
-
-					public Byte next() {
-						ByteBuffer bf = in.get(buffers);
-						byte b = bf.get(bytes++);
-						if (bf.remaining() <= bytes) {
-							buffers++;
-							bytes = 0;
-						}
-						// System.out.print(b);
-						return b;
-					}
-
-					public void remove() {
-					}
-				};
-			}
-		};
-	}
-
-}
--- a/src/main/java/ac/ryukyu/treevnc/server/RequestScreenThread.java	Tue Aug 21 14:02:05 2012 +0900
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,43 +0,0 @@
-package ac.ryukyu.treevnc.server;
-
-import java.io.IOException;
-
-public class RequestScreenThread implements Runnable {
-	MyRfbProtoProxy rfb;
-
-	RequestScreenThread(MyRfbProtoProxy _rfb) {
-		rfb = _rfb;
-	}
-
-	public void run() {
-		while (true) {
-			try {
-				waitThread();
-				Thread.sleep(3000);
-				rfb.writeFramebufferUpdateRequest(0, 0, rfb.framebufferWidth,
-						rfb.framebufferHeight, false);
-
-			} catch (Exception e) {
-				e.printStackTrace();
-				break;
-			}
-		}
-	}
-	
-    public synchronized void waitThread() {
-    	try{
-    		wait();
-        }catch(InterruptedException e) {
-        	e.printStackTrace();
-    	}
-    }
-
-    public synchronized void reStart() {
-    	notify();
-    }
-    
-    public void checkDelay() throws IOException {
-    	rfb.checkDelayData();
-    }
-    
-}
--- a/src/main/java/ac/ryukyu/treevnc/server/TextBoxProxy.java	Tue Aug 21 14:02:05 2012 +0900
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,126 +0,0 @@
-package ac.ryukyu.treevnc.server;
-
-import javax.swing.*;
-import java.awt.*;
-import java.awt.event.*;
-
-public class TextBoxProxy extends JFrame implements ActionListener {
-
-	/**
-	 * 
-	 */
-	private static final long serialVersionUID = 1L;
-	private JPanel panel;
-	private JButton button;
-	private JButton button1;
-	private TextField t1;
-	private TextField t2;
-	private JPasswordField pw;
-	private double width;
-	private double height;
-	private JLabel label;
-	private boolean flag;
-	private VncProxyService vps;
-
-	public void ipRegister() {
-		setSize();
-		setText();
-		visible();
-	}
-
-	public TextBoxProxy(VncProxyService _vps) {
-		vps = _vps;
-		setTitle("Informatin Connection Address");
-		setResizable(false);
-		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
-	}
-
-	private void setSize() {
-		Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
-		width = (d.getWidth() / 2);
-		height = (d.getHeight() / 2);
-	}
-
-	private void visible() {
-		Point point = new Point();
-		point.setLocation(width - 250, height - 80);
-		setLocation(point.getLocation());
-		pack();
-		setVisible(true);
-	}
-	
-	private void init(){
-		frameInit();
-//		panel = null;
-//		button = null;
-//		label = null;
-		setVisible(false);
-	}
-	
-	public void changeHost() {
-		init();
-		button1 = new JButton("Change Host");
-		t1 = new TextField("Address", 30);
-		panel = new JPanel();
-		panel.add(t1);
-		panel.add(button1);
-		button1.addActionListener(this);
-		label = new JLabel();
-		Container contentPane = getContentPane();
-		contentPane.add(panel, BorderLayout.CENTER);
-		contentPane.add(label, BorderLayout.SOUTH);
-		visible();
-	}
-
-	private void setText() {
-		panel = new JPanel();
-		t1 = new TextField("localhost", 30);
-		t2 = new TextField("5900", 5);
-//		pw = new JPasswordField("Password",30);
-		button = new JButton("Connect");
-		panel.add(t1);
-		panel.add(t2);
-//		panel.add(pw);
-		panel.add(button);
-		button.addActionListener(this);
-		label = new JLabel();
-		Container contentPane = getContentPane();
-		contentPane.add(panel, BorderLayout.CENTER);
-		contentPane.add(label, BorderLayout.SOUTH);
-	}
-	
-	public String getAddress() {
-		while(!(flag)) {
-			try {
-				Thread.sleep(500);
-			} catch (InterruptedException e) {
-				e.printStackTrace();
-			}
-		}
-		return t1.getText();
-	}
-	public String getPort() {
-		return t2.getText();
-	}
-	
-
-	public String getPassword() {
-		return String.valueOf(pw.getPassword());
-	}
-
-
-	public void actionPerformed(ActionEvent e) {
-		if(e.getSource()==button) {
-			flag = true;
-			setVisible(false);
-		}
-		if(e.getSource()==button1)
-			try {
-				init();
-				vps.host = getAddress();
-				vps.changeInit();
-			} catch (Exception e1) {
-				e1.printStackTrace();
-			}
-	}
-}
\ No newline at end of file
--- a/src/main/java/ac/ryukyu/treevnc/server/VncProxyService.java	Tue Aug 21 14:02:05 2012 +0900
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,179 +0,0 @@
-package ac.ryukyu.treevnc.server;
-
-import java.awt.event.*;
-import java.io.*;
-import java.util.logging.Logger;
-
-
-import com.glavsoft.exceptions.AuthenticationFailedException;
-import com.glavsoft.exceptions.FatalException;
-import com.glavsoft.exceptions.TransportException;
-import com.glavsoft.exceptions.UnsupportedProtocolVersionException;
-import com.glavsoft.exceptions.UnsupportedSecurityTypeException;
-import com.glavsoft.rfb.IChangeSettingsListener;
-import com.glavsoft.rfb.IRfbSessionListener;
-import com.glavsoft.rfb.protocol.Protocol;
-import com.glavsoft.rfb.protocol.ProtocolSettings;
-import com.glavsoft.transport.Reader;
-import com.glavsoft.transport.Writer;
-import com.glavsoft.viewer.ConnectionManager;
-import com.glavsoft.viewer.Viewer;
-import com.glavsoft.viewer.cli.Parser;
-import com.glavsoft.viewer.swing.ClipboardControllerImpl;
-import com.glavsoft.viewer.swing.ParametersHandler;
-import com.glavsoft.viewer.swing.Surface;
-import com.glavsoft.viewer.swing.UiSettings;
-import com.glavsoft.viewer.swing.ParametersHandler.ConnectionParams;
-
-public class VncProxyService extends Viewer implements Runnable, 
-	IRfbSessionListener, IChangeSettingsListener {
-
-	/**
-	 * 
-	 */
-	private static final long serialVersionUID = 1L;
-
-
-	public VncProxyService(Parser parser) {
-		this();
-		ParametersHandler.completeSettingsFromCLI(parser, connectionParams, settings, uiSettings);
-		showControls = ParametersHandler.showControls;
-		passwordFromParams = parser.getValueFor(ParametersHandler.ARG_PASSWORD);
-		logger.info("TightVNC Viewer version " + ver());
-		isApplet = false;
-	}
-	
-	public VncProxyService() {
-		connectionParams = new ParametersHandler.ConnectionParams();
-		settings = ProtocolSettings.getDefaultSettings();
-		uiSettings = super.uiSettings;
-
-	}
-	
-	boolean isClient = false;
-	public static final int DEFAULT_PORT = 5900;
-	public static Logger logger = Logger.getLogger("com.glavsoft");
-	private boolean forceReconnection;
-	private String reconnectionReason;
-	private ConnectionParams connectionParams;
-	private final ProtocolSettings settings;
-	private final UiSettings uiSettings;
-	private String[] arguments;
-	
-	
-	public static void main(String[] argv) {
-		String[] mainArgs = argv;
-		System.out.println(mainArgs.length);
-		// input into arguments Decision
-
-		Parser parser = new Parser();
-		ParametersHandler.completeParserOptions(parser);
-
-		parser.parse(argv);
-		if (parser.isSet(ParametersHandler.ARG_HELP)) {
-			printUsage(parser.optionsUsage());
-			System.exit(0);
-		}
-		VncProxyService vps = new VncProxyService(parser);
-		if (mainArgs.length != 0) {
-			for (int i = 0; i < argv.length; i++) {
-				vps.setArguments(mainArgs);
-				// write later
-			}
-		} else {
-			//getHostData();
-		}
-		//SwingUtilities.invokeLater(myClient);
-		Thread th = new Thread(vps);
-		th.start();
-	}
-	
-	private void setArguments(String[] mainArgs) {
-		arguments = mainArgs;		
-	}
-
-	@Override
-	public void run() {
-	//	getHostData();
-		ConnectionManager connectionManager = new ConnectionManager(this, isApplet);
-		if (forceReconnection) {
-			connectionManager.showReconnectDialog("Connection lost", reconnectionReason);
-			forceReconnection = false;
-		}
-		tryAgain = true;
-		while (tryAgain) {
-		  connectionParams.hostName = arguments[0];
-		//	workingSocket = connectionManager.connectToTreeHost(connectionParams, settings);
-			workingSocket = connectionManager.connectToTreeHost(connectionParams, settings);
-			if (null == workingSocket) {
-				closeApp();
-				break;
-			}
-			logger.info("Connected");
-
-			try {
-				workingSocket.setTcpNoDelay(true); // disable Nagle algorithm
-				Reader reader = new Reader(workingSocket.getInputStream());
-				Writer writer = new Writer(workingSocket.getOutputStream());
-				
-				workingProtocol = new Protocol(reader, writer,
-						new PasswordChooser(passwordFromParams, connectionParams, containerFrame, this),
-						settings);
-
-				workingProtocol.handshake();
-				// input into change parents
-                ClipboardControllerImpl clipboardController =
-		                new ClipboardControllerImpl(workingProtocol, settings.getRemoteCharsetName());
-				clipboardController.setEnabled(settings.isAllowClipboardTransfer());
-				settings.addListener(clipboardController);
-
-				surface = new Surface(workingProtocol, this, uiSettings.getScaleFactor());
-				settings.addListener(this);
-				uiSettings.addListener(surface);
-				containerFrame = createContainer();
-				connectionManager.setContainerFrame(containerFrame);
-				updateFrameTitle();
-
-				workingProtocol.startNormalHandling(this, surface, clipboardController);
-				tryAgain = false;
-			} catch (UnsupportedProtocolVersionException e) {
-				connectionManager.showReconnectDialog("Unsupported Protocol Version", e.getMessage());
-				logger.severe(e.getMessage());
-			} catch (UnsupportedSecurityTypeException e) {
-				connectionManager.showReconnectDialog("Unsupported Security Type", e.getMessage());
-				logger.severe(e.getMessage());
-			} catch (AuthenticationFailedException e) {
-				passwordFromParams = null;
-				connectionManager.showReconnectDialog("Authentication Failed", e.getMessage());
-				logger.severe(e.getMessage());
-			} catch (TransportException e) {
-				connectionManager.showReconnectDialog("Connection Error", "Connection Error" + ": " + e.getMessage());
-				logger.severe(e.getMessage());
-			} catch (IOException e) {
-				connectionManager.showReconnectDialog("Connection Error", "Connection Error" + ": " + e.getMessage());
-				logger.severe(e.getMessage());
-			} catch (FatalException e) {
-				connectionManager.showReconnectDialog("Connection Error", "Connection Error" + ": " + e.getMessage());
-				logger.severe(e.getMessage());
-			}
-		}
-
-	}
-
-
-
-	@Override
-	public void destroy() {
-
-	}
-
-	
-
-	@Override
-	public void windowClosing(WindowEvent e) {
-		if (e != null && e.getComponent() != null) {
-			e.getWindow().setVisible(false);
-		}
-		closeApp();
-	}
-}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/java/jp/ac/u_ryukyu/treevnc/InterfaceForViewer.java	Tue Aug 21 14:24:38 2012 +0900
@@ -0,0 +1,30 @@
+package jp.ac.u_ryukyu.treevnc;
+
+import java.awt.Image;
+import java.net.Socket;
+
+import jp.ac.u_ryukyu.treevnc.client.*;
+
+public interface InterfaceForViewer extends java.lang.Runnable{
+
+	public void setEchoValue(EchoClient value);
+	public String readParameter(String name, boolean required);
+	
+	public void getParentName();
+	// synchronized
+	public void disconnect();
+	public void fatalError(String str);
+	public void fatalError(String str, Exception e);
+
+	
+	public void destroy();
+	
+	public void enableInput(boolean enable);
+	
+
+	public void setClientSocket(Socket sock);
+	public void close();
+	public Image getScreenImage();
+	public void writeScreenData(byte[] b, String imageFormat);
+	
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/java/jp/ac/u_ryukyu/treevnc/MostRecentMultiCast.java	Tue Aug 21 14:24:38 2012 +0900
@@ -0,0 +1,27 @@
+package jp.ac.u_ryukyu.treevnc;
+
+import java.util.LinkedList;
+
+
+public class MostRecentMultiCast<T> extends MulticastQueue<T> {
+
+	LinkedList<Node<T>> alive;
+	int count = 0;
+	MostRecentMultiCast(int limit) {
+		count = limit;
+		this.alive = new LinkedList<Node<T>>();
+	}
+
+	@Override
+	public synchronized void put(T item)
+	{
+		Node<T> next = new Node<T>(item);
+		tail.set(next);
+		tail = next;
+		alive.addLast(next);
+		if (alive.size()>count) {
+			Node<T> old = alive.getFirst();
+			old.clear();
+		}
+	}
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/java/jp/ac/u_ryukyu/treevnc/MulticastQueue.java	Tue Aug 21 14:24:38 2012 +0900
@@ -0,0 +1,87 @@
+package jp.ac.u_ryukyu.treevnc;
+
+import java.util.concurrent.CountDownLatch;
+
+public class MulticastQueue<T>
+{
+	
+	Node<T> tail;
+	
+	public MulticastQueue()
+	{
+		tail = new Node<T>(null);
+	}
+
+	public synchronized void put(T item)
+	{
+		Node<T> next = new Node<T>(item);
+		tail.set(next);
+		tail = next;
+	}
+	
+	public Client<T> newClient()
+	{
+		return new Client<T>(tail);
+	}
+	
+	public static class Client<T>
+	{
+		Node<T> node;
+		
+		Client(Node<T> tail)
+		{
+			node = tail;
+		}
+		
+		synchronized public T poll()
+		{
+			Node<T> next = null;
+			T item = null;
+			do {
+				try {
+					next = node.next();
+				}catch(InterruptedException _e){
+					continue;
+				}
+//				item = node.getItem();
+				item = next.getItem();				
+				node = next;
+			} while ( item == null);
+			return item;
+		}
+	}
+	
+	static class Node<T>
+	{
+		private T item;
+		private Node<T> next;
+		private CountDownLatch latch;
+		
+		public Node(T item)
+		{
+			this.item = item;
+			this.next = null;
+			latch = new CountDownLatch(1);
+		}
+		
+		synchronized public T getItem() {
+			return item;
+		}
+
+		public void set(Node<T> next)
+		{
+			this.next = next;
+			latch.countDown();
+		}
+		
+		public Node<T> next() throws InterruptedException
+		{
+			latch.await();
+			return next;
+		}
+
+		synchronized public void clear() {
+			item = null;
+		}
+	}
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/java/jp/ac/u_ryukyu/treevnc/client/AcceptThread.java	Tue Aug 21 14:24:38 2012 +0900
@@ -0,0 +1,42 @@
+package jp.ac.u_ryukyu.treevnc.client;
+import java.net.Socket;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+public class AcceptThread implements Runnable {
+        MyRfbProtoClient rfb = null;
+        byte[] imageBytes;
+        int port;
+        
+        AcceptThread(MyRfbProtoClient _rfb) {
+                rfb = _rfb;
+        }
+
+
+        AcceptThread(MyRfbProtoClient _rfb, int p) {
+            rfb = _rfb;
+            port = p;
+        }
+       
+	public void changeRfb(MyRfbProtoClient _rfb) {
+		rfb = _rfb;
+	}
+
+	public void run() {
+		rfb.selectPort(port);
+
+		while (true) {
+			try {
+				Socket newCli = rfb.accept();
+
+				OutputStream os = newCli.getOutputStream();
+				InputStream is = newCli.getInputStream();
+				rfb.newClient(this, newCli, os, is);
+			} catch (IOException e) {
+				e.printStackTrace();
+				System.out.println(e);
+			}
+		}
+	}
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/java/jp/ac/u_ryukyu/treevnc/client/EchoClient.java	Tue Aug 21 14:24:38 2012 +0900
@@ -0,0 +1,295 @@
+package jp.ac.u_ryukyu.treevnc.client;
+
+import java.io.*;
+import java.net.*;
+
+import jp.ac.u_ryukyu.treevnc.*;
+
+//import myVncProxy.MulticastQueue.Client;
+
+public class EchoClient {
+	private String name;
+	private BufferedReader is = null;
+	private DataOutputStream os = null;
+	private Socket echoSocket = null;
+	private boolean runflag = false;
+	private WaitReply waitReply;
+	private Socket clientSocket = null;
+	// MyVncClient client;
+	private InterfaceForViewer client;
+	private int echoPort = 9999;
+	// private IpV6 ipV6;
+	// private MyVncClient checkMove;
+	// private VncViewer vncV;
+	String responseLine;
+	String parent;// 親の番号
+	String treenum;// 自分の番号
+	String leaderflag;// リーダフラグ
+
+	// boolean passflag;
+
+	// WaitReplyに自分自身を渡している
+	public EchoClient() {
+	}
+
+	public EchoClient(EchoClient echo) {
+		this.name = echo.name;
+		this.leaderflag = echo.leaderflag;
+		this.parent = echo.parent;
+		this.treenum = echo.treenum;
+		this.client = echo.client;
+		this.waitReply = echo.waitReply;
+		// checkMove = (MyVncClient)echo.client;
+	}
+
+	// VncViewerから引数をもらってきてproxy役を認識する
+	public EchoClient(String name, MyVncClient client) {
+		this.client = (InterfaceForViewer) client;
+		this.name = name;
+	}
+
+	public EchoClient(String name, int echoPort) {
+		this.echoPort = echoPort;
+		this.name = name;
+	}
+	
+	public EchoClient(String name, MyVncClient client, int echoPort) {
+		this.client = (InterfaceForViewer) client;
+		this.name = name;
+		this.echoPort = echoPort;
+	}
+
+	public EchoClient(EchoClient echo, MyVncClient client) {
+		this.client = (InterfaceForViewer) client;
+		this.name = echo.name;
+		leaderflag = echo.leaderflag;
+		parent = echo.parent;
+		treenum = echo.treenum;
+		waitReply = echo.waitReply;
+	}
+/*
+	public EchoClient(String name, CuiMyVncClient client) {
+		this.client = client;
+		this.name = name;
+	}
+
+	public EchoClient(String name, CuiMyVncClient client, int echoPort) {
+		this.client = client;
+		this.name = name;
+		this.echoPort = echoPort;
+	}
+
+	public EchoClient(EchoClient echo, CuiMyVncClient client) {
+		this.client = client;
+		this.name = echo.name;
+		leaderflag = echo.leaderflag;
+		parent = echo.parent;
+		treenum = echo.treenum;
+	}
+*/
+
+	// void hostn(String args){
+	void openport() {
+		try {
+			if (name != null) {
+				echoSocket = new Socket(name, echoPort);
+			} else {
+				echoSocket = new Socket("133.13.48.18", echoPort);
+			}
+			os = new DataOutputStream(echoSocket.getOutputStream());
+			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
+	 * @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();
+
+				os.writeBytes(add + "\n");
+				os.writeBytes(args + "\n");
+				getProxyData(is);
+
+				streamClose();
+			} catch (UnknownHostException e) {
+				System.err.println("Trying to connect to unknown host: " + e);
+			} catch (IOException e) {
+				System.err.println("IOException: " + e);
+			}
+			waitReply = new WaitReply(treenum, client);
+			waitReply.start();
+		}
+		return this;
+	}
+
+	/**
+	 * Call at lost host
+	 */
+	boolean lostHost() {
+		if (echoSocket != null && os != null && is != null) {
+			try {
+				if (runflag) {
+					return true;
+				}
+				sendDataProxy();
+				String checkRepetition = getProxyData2(is);
+				if (checkRepetition.equals("stop")) {
+					return true;
+				}
+				// if(!(checkRepetition.equals("skip")) ||
+				// "1".equals(leaderflag)) {
+				if (!(waitReply.checkPath())) {
+					Thread.sleep(1000);
+					reConnectionMain(echoSocket);
+					streamClose();
+				}
+				// Thread.sleep(1000);
+				/*
+				 * 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 (InterruptedException e) {
+				e.printStackTrace();
+
+			} catch (NullPointerException e) {
+				openport();
+				System.out.println("notFoundParents");
+				notfoundParent();
+			}
+		}
+		return true;
+	}
+
+	boolean notfoundParent() {
+		if (echoSocket != null && os != null && is != null) {
+			runflag = true;
+			try {
+				sendDataProxy("2", parent, null);
+				getProxyData(is);
+				reConnectionMain(echoSocket);
+				streamClose();
+			} catch (UnknownHostException e) {
+				System.err.println("Trying to connect to unknown host: " + e);
+			} catch (IOException e) {
+				System.err.println("IOException: " + e);
+			}
+		}
+		return true;
+	}
+
+	EchoClient Interruption(Socket _clientSocket) {
+		clientSocket = _clientSocket;
+		BufferedReader lostis = null;// あとで修正する
+
+		try {
+			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);
+		}
+		if ((parent = is.readLine()) != null) {
+			System.out.println("parent: " + parent);
+		}
+		if ((treenum = is.readLine()) != null) {
+			System.out.println("treenum: " + treenum);
+		}
+		if ((leaderflag = is.readLine()) != null) {
+			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);
+		}
+		if ((parent = is.readLine()) != null) {
+			System.out.println("parent:test " + parent);
+		}
+		if ((checkRepetition = is.readLine()) != null) {
+			System.out.println("checkRepetition: " + checkRepetition);
+		}
+		return checkRepetition;
+	}
+
+	void reConnectionMain(Socket echoSocket) {
+		client.close();
+		client.setClientSocket(echoSocket);
+		client.run();
+		/*
+		client.init();
+		client.setEchoValue(this);
+		client.getParentName();
+		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);
+			System.out.println("---------------------------------------------");
+		} else {
+			sendDataProxy("3", parent, 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);
+		}
+	}
+	/*
+	 * String getIpV6() { ipV6 = new IpV6(); ipV6.getInterface(); return
+	 * ipV6.getV6(); }
+	 */
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/java/jp/ac/u_ryukyu/treevnc/client/GetDataClient.java	Tue Aug 21 14:24:38 2012 +0900
@@ -0,0 +1,91 @@
+package jp.ac.u_ryukyu.treevnc.client;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.net.ServerSocket;
+import java.net.Socket;
+
+
+public class GetDataClient implements Runnable {
+	private ServerSocket server = null;
+	BufferedReader is;
+	private int port = 8182;
+	private boolean stopFlag = false;
+	public TextBoxClient text = new TextBoxClient();
+	
+	private void getData() {
+		try {
+			server = new ServerSocket(port);
+			while(true) {
+				Socket socket = server.accept();  
+				is = new BufferedReader(new InputStreamReader(
+						socket.getInputStream()));
+				String line = is.readLine();
+//				text = new TextBoxClient();
+				if(line!=null){
+					text.checkBox(line);
+				}
+				// TextBoxClient text = new TextBoxClient();
+				text.setButton();
+				text.visible();
+			}
+		} catch (IOException e) {
+			e.printStackTrace();
+		}
+	}
+	
+	
+	public String textAddress() {
+		return text.getAddress();
+	}
+	
+	public String  textPort() {
+		return text.getPort();
+	}
+	
+	void socketClose() {
+		try {
+			text.unVisible();
+			//server.close(); after the modify
+			is.close();
+		} catch (IOException e) {
+			e.printStackTrace();
+		}
+	}
+	
+/*	
+	private int castInt(byte[] a) {
+		int value = 0;
+		ByteArrayInputStream bais = new ByteArrayInputStream(a);
+		DataInputStream dis = new DataInputStream(bais);
+		try {
+			value = dis.readInt();
+		} catch (IOException e) {
+		}
+		System.out.println(value);
+		return value;
+	}
+
+	private String castString(byte[] a) {
+		String recover = new String(a);
+		recover = recover.replace("¥n", "");
+		recover = recover.trim();
+		System.out.println(recover);
+		return recover;
+	}
+*/
+	
+	public void run() {
+		getData();
+	}
+
+	public void setStopFlag(boolean stopFlag) {
+		this.stopFlag = stopFlag;
+	}
+
+	public boolean isStopFlag() {
+		return stopFlag;
+	}
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/java/jp/ac/u_ryukyu/treevnc/client/GetHostClient.java	Tue Aug 21 14:24:38 2012 +0900
@@ -0,0 +1,57 @@
+package jp.ac.u_ryukyu.treevnc.client;
+
+import java.io.IOException;
+import java.net.DatagramPacket;
+import java.net.InetAddress;
+import java.net.MulticastSocket;
+
+public class GetHostClient {
+	final int BUFSIZE = 1024;
+	final String MCASTADDR = "224.0.0.1";
+	final int PORT = 8183;
+	private byte[] buf = new byte[BUFSIZE];
+	private InetAddress mAddr;
+	private MulticastSocket soc;
+	private String str;
+
+	public GetHostClient(String _str) {
+		str = _str;
+	}
+
+	public void createSocket() {
+		try {
+			mAddr = InetAddress.getByName(MCASTADDR);
+			soc = new MulticastSocket();
+			soc.setTimeToLive(1);
+		} catch (IOException e) {
+			e.printStackTrace();
+		}
+	}
+
+	public void sendData() {
+		buf = str.getBytes();
+		// System.out.println("strlen"+str.length());
+		// System.out.println("str"+str);
+		DatagramPacket sendPacket = new DatagramPacket(buf, str.length(),
+				mAddr, PORT);
+		try {
+			soc.send(sendPacket);
+		} catch (IOException e) {
+			e.printStackTrace();
+		}
+	}
+/*
+	@Override
+	public void run() {
+		createSocket();
+		while (true) {
+			sendData();
+			try {
+				Thread.sleep(2000);
+			} catch (InterruptedException e) {
+				System.out.println(e);
+			}
+		}
+	}
+	*/
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/java/jp/ac/u_ryukyu/treevnc/client/MyRfbProtoClient.java	Tue Aug 21 14:24:38 2012 +0900
@@ -0,0 +1,508 @@
+package jp.ac.u_ryukyu.treevnc.client;
+
+import java.io.DataInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.BindException;
+import java.net.ServerSocket;
+import java.net.Socket;
+import java.nio.ByteBuffer;
+import java.util.LinkedList;
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.zip.DataFormatException;
+import java.util.zip.Deflater;
+import java.util.zip.Inflater;
+
+import jp.ac.u_ryukyu.treevnc.MulticastQueue;
+
+
+import com.glavsoft.exceptions.TransportException;
+import com.glavsoft.rfb.encoding.EncodingType;
+import com.glavsoft.transport.Reader;
+import com.glavsoft.viewer.ContainerManager;
+import com.glavsoft.viewer.swing.ParametersHandler.ConnectionParams;
+
+public class MyRfbProtoClient {
+	final static int FramebufferUpdate = 0;
+	final static int CheckDelay = 11;
+	final static String versionMsg_3_855 = "RFB 003.855\n";
+	private static final int INFLATE_BUFSIZE = 1024*100;
+	private Reader reader;
+	private EchoClient echoValue = new EchoClient();
+	private String host,treenum,parent,pHost,leaderflag;
+	private int echoPort,port,acceptPort;
+	Socket clientSocket,sock;
+	DataInputStream is;
+	OutputStream os;
+	private ContainerManager containerManager;
+	private ServerSocket servSock;
+	private byte initData[];
+	private int clients = 0;
+	private MulticastQueue<LinkedList<ByteBuffer>> multicastqueue = new MulticastQueue<LinkedList<ByteBuffer>>();
+	boolean proxyFlag = false;
+	int serverMajor, serverMinor;
+	int clientMajor, clientMinor;
+	
+	private Inflater inflater = new Inflater();
+	private Deflater deflater = new Deflater();
+	
+	public MyRfbProtoClient(Reader reader,String host,String port) {
+		this.reader = reader;
+	}
+	
+	public void setParam(ConnectionParams connectionParams) {
+		pHost = connectionParams.hostName;
+		echoPort = connectionParams.portNumber;
+	}
+	
+	public boolean readProxyFlag() throws TransportException {
+		int flag = reader.readUInt8();
+		if(flag == 1)
+			return true;
+		else
+			return false;
+	}
+	
+	public byte[] readEchoPort() throws Exception {
+		byte[] b = new byte[4];
+		reader.readBytes(b, 0, b.length);
+		//readFully(b);
+		return b;
+	}
+	
+	public void getParentName() {
+		if (echoValue == null) {
+
+			if (clientSocket == null) {
+
+				// echo = new EchoClient(pHost, this);
+				echoValue = new EchoClient(pHost, echoPort);
+				echoValue.openport();
+
+				echoValue = echoValue.requestHostName("1");
+			} else {
+				echoValue = new EchoClient();
+				echoValue = echoValue.Interruption(clientSocket);
+			}
+		}
+		// proxyからの返信で接続先を決定する
+		host = echoValue.responseLine;
+		parent = echoValue.parent;
+		if (echoValue.treenum != null) {
+			treenum = echoValue.treenum;
+		} else {
+			treenum = echoValue.treenum;
+		}
+		
+		if (echoValue.leaderflag != null) {
+			leaderflag = echoValue.leaderflag;
+		} else {
+			leaderflag = echoValue.leaderflag;
+		}
+	}
+	
+	int castByteInt(byte[] b) {
+		ByteBuffer bb = ByteBuffer.wrap(b);
+		int value = bb.getInt();
+		return value;
+	}
+	
+	Socket changeParent(String host, int port) throws IOException {
+		sock = new Socket(host, port);
+		return sock;
+	}
+	
+	public Socket accept() throws IOException {
+		return servSock.accept();
+	}
+	
+	void initServSock(int port) throws IOException {
+		servSock = new ServerSocket(port);
+		acceptPort = port;
+	}
+	
+	public void selectPort(int p) {
+		int port = p;
+		while (true) {
+			try {
+				initServSock(port);
+				break;
+			} catch (BindException e) {
+				port++;
+				continue;
+			} catch (IOException e) {
+
+			}
+		}
+		System.out.println("accept port = " + port);
+	}
+	
+	public void newClient(AcceptThread acceptThread, final Socket newCli,
+			final OutputStream os, final InputStream is) throws IOException {
+		// createBimgFlag = true;
+		// rfb.addSockTmp(newCli);
+		//		addSock(newCli);
+		final int myId = clients; 
+		final MulticastQueue.Client <LinkedList<ByteBuffer>> c = multicastqueue.newClient();
+		final AtomicInteger writerRunning = new AtomicInteger();
+		writerRunning.set(1);
+		/**
+		 * Timeout thread. If a client is suspended, it has top of queue indefinitely, which caused memory
+		 * overflow. After the timeout, we poll the queue and discard it. Start long wait if writer is running.
+		 */
+		final Runnable timer = new Runnable() {
+			public void run() {
+				int count = 0;
+				for(;;) {
+					long timeout = 40000/8;
+					try {
+						synchronized(this) {
+							int state,flag;
+							writerRunning.set(0);
+							wait(timeout);
+							flag = 0;
+							while((state=writerRunning.get())==0) {
+								c.poll(); // discard, should be timeout
+								count++;
+								if (flag==0) {
+									System.out.println("Discarding "+myId + " count="+ count); flag = 1;
+								}
+								wait(10); // if this is too short, writer cannot take the poll, if this is too long, memory will overflow...
+							}
+							if (flag==1) System.out.println("Resuming "+myId + " count="+count);
+							if (state!=1) {
+								System.out.println("Client died "+myId);
+								break;
+							}
+						}
+					} catch (InterruptedException e) {
+					}
+				}
+			}
+		};
+		new Thread(timer).start();
+		/**
+		 * discard all incoming from clients
+		 */
+		final Runnable reader = new Runnable() {
+			public void run() {
+				byte b[] = new byte[4096];
+				for(;;) {
+					try {
+						int c = is.read(b);
+						if (c<=0) throw new IOException();
+						// System.out.println("client read "+c);
+					} catch (IOException e) {
+						try {
+							writerRunning.set(2);
+							os.close();
+							is.close();
+						} catch (IOException e1) {
+						}
+						return;
+					}
+				}
+			}
+		};
+		/**
+		 * send packets to a client
+		 */
+		Runnable sender = new Runnable() {
+			public void run() {
+				writerRunning.set(1);
+				try {
+					/**
+					 *  initial connection of RFB protocol
+					 */
+					sendRfbVersion(os);
+//					readVersionMsg(is);
+					int rfbMinor = readVersionMsg(is,os);
+					sendSecurityType(os);
+					readSecType(is);
+					sendSecResult(os);
+					readClientInit(is);
+					sendInitData(os);
+					new Thread(reader).start(); // discard incoming packet here after.
+					if(rfbMinor == 855){
+						//checkDilay(os);
+						// send jpeg data of full screen.
+						// sendFullScreen("jpeg" ,os);
+					} else {
+						// send raw data of full screen.
+						
+					}
+					for (;;) {
+						LinkedList<ByteBuffer> bufs = c.poll();
+						int inputIndex = 0;
+						ByteBuffer header = bufs.get(inputIndex);
+						if (header==null) continue;
+						if (header.get(0)==CheckDelay) {
+							System.out.println("--------------------");
+							//writeToClient(os, bufs, inputIndex);
+						}
+						if (header.get(0)==FramebufferUpdate) {
+							// System.out.println("client "+ myId);
+						}
+						writeToClient(os, bufs, inputIndex);
+						writerRunning.set(1);  // yes my client is awaking.
+					}
+				} catch (IOException e) {
+					try {
+						writerRunning.set(2);
+						os.close();
+					} catch (IOException e1) {
+						/* if socket closed 	cliList.remove(newCli); */
+					}
+				}
+			}
+
+			public void writeToClient(final OutputStream os,
+					LinkedList<ByteBuffer> bufs, int inputIndex)
+					throws IOException {
+				while(inputIndex < bufs.size()) {
+					ByteBuffer b = bufs.get(inputIndex++);
+					os.write(b.array(), b.position(), b.limit());
+				}
+				os.flush();
+			}
+		};
+		clients++;
+		new Thread(sender).start();
+
+	}
+	
+	void sendRfbVersion(OutputStream os) throws IOException {
+		os.write(versionMsg_3_855.getBytes());
+//		os.write(versionMsg_3_8.getBytes());
+	}
+	int readVersionMsg(InputStream is, OutputStream os) throws IOException {
+
+		byte[] b = new byte[12];
+
+		is.read(b);
+
+		if ((b[0] != 'R') || (b[1] != 'F') || (b[2] != 'B') || (b[3] != ' ')
+				|| (b[4] < '0') || (b[4] > '9') || (b[5] < '0') || (b[5] > '9')
+				|| (b[6] < '0') || (b[6] > '9') || (b[7] != '.')
+				|| (b[8] < '0') || (b[8] > '9') || (b[9] < '0') || (b[9] > '9')
+				|| (b[10] < '0') || (b[10] > '9') || (b[11] != '\n')) {
+			throw new IOException("Host " + host + " port " + port
+					+ " is not an RFB server");
+		}
+
+		int rfbMajor = (b[4] - '0') * 100 + (b[5] - '0') * 10 + (b[6] - '0');
+		int rfbMinor = (b[8] - '0') * 100 + (b[9] - '0') * 10 + (b[10] - '0');
+
+		if (rfbMajor < 3) {
+			throw new IOException(
+			"RFB server does not support protocol version 3");
+		}
+
+		if (rfbMinor == 855) {
+			sendProxyFlag(os);
+//			if(proxyFlag)sendPortNumber(os);
+		}
+		return rfbMinor;
+		
+	}	void readVersionMsg(InputStream is) throws IOException {
+
+		byte[] b = new byte[12];
+
+		is.read(b);
+
+		if ((b[0] != 'R') || (b[1] != 'F') || (b[2] != 'B') || (b[3] != ' ')
+				|| (b[4] < '0') || (b[4] > '9') || (b[5] < '0') || (b[5] > '9')
+				|| (b[6] < '0') || (b[6] > '9') || (b[7] != '.')
+				|| (b[8] < '0') || (b[8] > '9') || (b[9] < '0') || (b[9] > '9')
+				|| (b[10] < '0') || (b[10] > '9') || (b[11] != '\n')) {
+			throw new IOException("Host " + host + " port " + port
+					+ " is not an RFB server");
+		}
+
+		serverMajor = (b[4] - '0') * 100 + (b[5] - '0') * 10 + (b[6] - '0');
+		serverMinor = (b[8] - '0') * 100 + (b[9] - '0') * 10 + (b[10] - '0');
+
+		if (serverMajor < 3) {
+			throw new IOException(
+					"RFB server does not support protocol version 3");
+		}
+
+	}
+	
+	void sendSecurityType(OutputStream os) throws IOException {
+		// number-of-security-types
+		os.write(1);
+		// security-types
+		// 1:None
+		os.write(1);
+	}
+	void readSecType(InputStream is) throws IOException {
+		byte[] b = new byte[1];
+		is.read(b);
+
+	}
+	
+	void sendSecResult(OutputStream os) throws IOException {
+		byte[] b = castIntByte(0);
+		os.write(b);
+	}
+	
+	void readClientInit(InputStream in) throws IOException {
+		byte[] b = new byte[0];
+		in.read(b);
+	}
+	
+	void sendInitData(OutputStream os) throws IOException {
+		os.write(initData);
+	}
+	
+	void sendProxyFlag(OutputStream os) throws IOException {
+		if(proxyFlag) os.write(1);
+		else os.write(0);
+	}
+	
+	byte[] castIntByte(int len) {
+		byte[] b = new byte[4];
+		b[0] = (byte) ((len >>> 24) & 0xFF);
+		b[1] = (byte) ((len >>> 16) & 0xFF);
+		b[2] = (byte) ((len >>> 8) & 0xFF);
+		b[3] = (byte) ((len >>> 0) & 0xFF);
+		return b;
+	}
+	
+	/**
+	 * gzip byte arrays
+	 * @param deflater
+	 * @param inputs
+	 *            byte data[]
+	 * @param inputIndex 
+	 * @param outputs
+	 *            byte data[]
+	 * @return  byte length in last byte array
+	 * @throws IOException
+	 */
+	public int zip(Deflater deflater,LinkedList<ByteBuffer> inputs, int inputIndex, LinkedList<ByteBuffer> outputs) throws IOException {
+		int len = 0;
+		ByteBuffer c1= ByteBuffer.allocate(INFLATE_BUFSIZE);
+		while(inputIndex < inputs.size() ) {
+			ByteBuffer b1 = inputs.get(inputIndex++);
+			deflater.setInput(b1.array(),b1.position(),b1.remaining());
+			/**
+			 * If we finish() stream and reset() it, Deflater start new gzip stream, this makes continuous zlib reader unhappy.
+			 * if we remove finish(), Deflater.deflate() never flushes its output. The original zlib deflate has flush flag. I'm pretty
+			 * sure this a kind of bug of Java library.
+			 */
+			if (inputIndex==inputs.size())	
+				deflater.finish();
+			int len1 = 0;
+			do {
+				len1 = deflater.deflate(c1.array(),c1.position(),c1.remaining());
+				if (len1>0) {
+					len += len1;
+					c1.position(c1.position()+len1); 
+					if (c1.remaining()==0) {
+						c1.flip();	outputs.addLast(c1);
+						c1 = ByteBuffer.allocate(INFLATE_BUFSIZE);
+					}
+				}
+			} while (len1 >0 || !deflater.needsInput()); // &&!deflater.finished());
+		}
+		if (c1.position()!=0) {
+			c1.flip();	outputs.addLast(c1);
+		}
+		deflater.reset();
+		return len;
+	}
+	
+	
+	/**
+	 * gunzip byte arrays
+	 * @param inflater
+	 * @param inputs
+	 *            byte data[]
+	 * @param outputs
+	 *            byte data[]
+	 *@return  number of total bytes            
+	 * @throws IOException
+	 */
+	public int unzip(Inflater inflater, LinkedList<ByteBuffer> inputs,
+			int inputIndex, LinkedList<ByteBuffer> outputs, int bufSize)
+			throws DataFormatException {
+		int len = 0;
+		ByteBuffer buf = ByteBuffer.allocate(bufSize);
+		while (inputIndex < inputs.size()) {
+			ByteBuffer input = inputs.get(inputIndex++);
+			inflater.setInput(input.array(), input.position(), input.limit());
+			// if (inputIndex==inputs.size()) if inflater/deflater has symmetry,
+			// we need this
+			// inflater.end(); but this won't work
+			do {
+				int len0 = inflater.inflate(buf.array(), buf.position(),
+						buf.remaining());
+				if (len0 > 0) {
+					buf.position(buf.position() + len0);
+					len += len0;
+					if (buf.remaining() == 0) {
+						buf.flip();
+						outputs.addLast(buf);
+						buf = ByteBuffer.allocate(bufSize);
+					}
+				}
+			} while (!inflater.needsInput());
+		}
+		if (buf.position() != 0) {
+			buf.flip();
+			outputs.addLast(buf);
+		}
+		return len;
+	}
+	
+	void readSendData(int dataLen,Reader reader) throws IOException, DataFormatException, TransportException {
+		LinkedList<ByteBuffer>bufs = new LinkedList<ByteBuffer>();
+		ByteBuffer header = ByteBuffer.allocate(16);
+		reader.readBytes(header.array(),0,16); 
+		header.limit(16);
+		if (header.get(0)==FramebufferUpdate) {
+			int encoding = header.getInt(12);
+			if (encoding==EncodingType.ZRLE.getId()||encoding==EncodingType.ZLIB.getId()) { // ZRLEE is already recompressed
+				ByteBuffer len = ByteBuffer.allocate(4);
+				reader.readBytes(len.array(),0,4); len.limit(4);
+				ByteBuffer inputData = ByteBuffer.allocate(dataLen-20);
+				reader.readBytes(inputData.array(),0,inputData.capacity()); inputData.limit(dataLen-20);
+				LinkedList<ByteBuffer>inputs = new LinkedList<ByteBuffer>();
+				inputs.add(inputData);
+
+				header.putInt(12, EncodingType.ZRLEE.getId()); // means recompress every time
+				// using new Deflecter every time is incompatible with the protocol, clients have to be modified.
+				Deflater nDeflater = deflater; // new Deflater();
+				LinkedList<ByteBuffer> out = new LinkedList<ByteBuffer>();
+				unzip(inflater, inputs, 0 , out, INFLATE_BUFSIZE);
+				// dump32(inputs);
+				int len2 = zip(nDeflater, out, 0, bufs);
+				ByteBuffer blen = ByteBuffer.allocate(4); blen.putInt(len2); blen.flip();
+				bufs.addFirst(blen);
+
+				bufs.addFirst(header);
+				multicastqueue.put(bufs);
+				is.reset();
+				return ;
+			}
+		} 
+		bufs.add(header);
+		if (dataLen>16) {
+			ByteBuffer b = ByteBuffer.allocate(dataLen-16);
+			reader.readBytes(b.array(),0,dataLen-16); b.limit(dataLen-16);
+			bufs.add(b);
+		}
+		multicastqueue.put(bufs);
+		is.reset();
+
+		// It may be compressed. We can inflate here to avoid repeating clients decompressing here,
+		// 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.
+	}
+
+
+	
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/java/jp/ac/u_ryukyu/treevnc/client/MyVncClient.java	Tue Aug 21 14:24:38 2012 +0900
@@ -0,0 +1,204 @@
+package jp.ac.u_ryukyu.treevnc.client;
+
+import java.awt.event.WindowEvent;
+import java.awt.event.WindowListener;
+import java.io.IOException;
+import java.util.logging.Logger;
+
+import javax.swing.SwingUtilities;
+
+
+import com.glavsoft.exceptions.AuthenticationFailedException;
+import com.glavsoft.exceptions.FatalException;
+import com.glavsoft.exceptions.TransportException;
+import com.glavsoft.exceptions.UnsupportedProtocolVersionException;
+import com.glavsoft.exceptions.UnsupportedSecurityTypeException;
+import com.glavsoft.rfb.IChangeSettingsListener;
+import com.glavsoft.rfb.IRfbSessionListener;
+import com.glavsoft.rfb.protocol.Protocol;
+import com.glavsoft.rfb.protocol.ProtocolSettings;
+import com.glavsoft.transport.Reader;
+import com.glavsoft.transport.Writer;
+import com.glavsoft.viewer.ConnectionManager;
+import com.glavsoft.viewer.TreeConnectionManager;
+import com.glavsoft.viewer.Viewer;
+import com.glavsoft.viewer.cli.Parser;
+import com.glavsoft.viewer.swing.ClipboardControllerImpl;
+import com.glavsoft.viewer.swing.ParametersHandler;
+import com.glavsoft.viewer.swing.Surface;
+import com.glavsoft.viewer.swing.UiSettings;
+import com.glavsoft.viewer.swing.ParametersHandler.ConnectionParams;
+
+
+public class MyVncClient extends Viewer implements IRfbSessionListener,
+	WindowListener, IChangeSettingsListener {
+
+	/**
+	 * 
+	 */
+	private static final long serialVersionUID = 1L;
+	// private boolean runflag = false;
+
+	boolean isClient = false;
+	public static final int DEFAULT_PORT = 5900;
+	public static Logger logger = Logger.getLogger("com.glavsoft");
+	private boolean forceReconnection;
+	private String reconnectionReason;
+	private ConnectionParams connectionParams;
+	private final ProtocolSettings settings;
+	private final UiSettings uiSettings;
+	private String[] arguments;
+	private TreeConnectionManager treeConnectionManager;
+	
+	
+	public MyVncClient() {
+		connectionParams = new ParametersHandler.ConnectionParams();
+		settings = ProtocolSettings.getDefaultSettings();
+		uiSettings = super.uiSettings;
+		treeConnectionManager = new TreeConnectionManager(this, isApplet);
+	}
+	
+	public MyVncClient(Parser parser) {
+		this();
+		ParametersHandler.completeSettingsFromCLI(parser, connectionParams, settings, uiSettings);
+		showControls = ParametersHandler.showControls;
+		passwordFromParams = parser.getValueFor(ParametersHandler.ARG_PASSWORD);
+		logger.info("TightVNC Viewer version " + ver());
+		isApplet = false;
+	}
+
+	public void treeVncClient(String[] argv) {
+		new MyVncClient();
+		//v.runClient(argv);
+	}
+
+	// private void runClient(String[] argv) {
+	public static void main(String[] argv) {
+		String[] mainArgs = argv;
+		System.out.println(mainArgs.length);
+		// input into arguments Decision
+
+		Parser parser = new Parser();
+		ParametersHandler.completeParserOptions(parser);
+
+		parser.parse(argv);
+		if (parser.isSet(ParametersHandler.ARG_HELP)) {
+			printUsage(parser.optionsUsage());
+			System.exit(0);
+		}
+		MyVncClient myClient = new MyVncClient(parser);
+		myClient.setType();
+		SwingUtilities.invokeLater(myClient);
+	}
+	
+	public void setType() {
+		super.setType(treeConnectionManager);
+	}
+	
+	public void mainLoop() {
+	//	getHostData();
+		if (forceReconnection) {
+			treeConnectionManager.showReconnectDialog("Connection lost", reconnectionReason);
+			forceReconnection = false;
+		}
+		tryAgain = true;
+		while (tryAgain) {
+		  connectionParams.hostName = arguments[0];
+		//	workingSocket = connectionManager.connectToTreeHost(connectionParams, settings);
+			workingSocket = treeConnectionManager.connectToHost(connectionParams, settings);
+			if (null == workingSocket) {
+				closeApp();
+				break;
+			}
+			logger.info("Connected");
+
+			try {
+				workingSocket.setTcpNoDelay(true); // disable Nagle algorithm
+				Reader reader = new Reader(workingSocket.getInputStream());
+				Writer writer = new Writer(workingSocket.getOutputStream());
+				
+				workingProtocol = new Protocol(reader, writer,
+						new PasswordChooser(passwordFromParams, connectionParams, containerFrame, this),
+						settings);
+
+				workingProtocol.handshake();
+				// input into change parents
+                ClipboardControllerImpl clipboardController =
+		                new ClipboardControllerImpl(workingProtocol, settings.getRemoteCharsetName());
+				clipboardController.setEnabled(settings.isAllowClipboardTransfer());
+				settings.addListener(clipboardController);
+
+				surface = new Surface(workingProtocol, this, uiSettings.getScaleFactor());
+				settings.addListener(this);
+				uiSettings.addListener(surface);
+				containerFrame = createContainer();
+				treeConnectionManager.setContainerFrame(containerFrame);
+				updateFrameTitle();
+
+				workingProtocol.startNormalHandling(this, surface, clipboardController);
+				tryAgain = false;
+			} catch (UnsupportedProtocolVersionException e) {
+				treeConnectionManager.showReconnectDialog("Unsupported Protocol Version", e.getMessage());
+				logger.severe(e.getMessage());
+			} catch (UnsupportedSecurityTypeException e) {
+				treeConnectionManager.showReconnectDialog("Unsupported Security Type", e.getMessage());
+				logger.severe(e.getMessage());
+			} catch (AuthenticationFailedException e) {
+				passwordFromParams = null;
+				treeConnectionManager.showReconnectDialog("Authentication Failed", e.getMessage());
+				logger.severe(e.getMessage());
+			} catch (TransportException e) {
+				treeConnectionManager.showReconnectDialog("Connection Error", "Connection Error" + ": " + e.getMessage());
+				logger.severe(e.getMessage());
+			} catch (IOException e) {
+				treeConnectionManager.showReconnectDialog("Connection Error", "Connection Error" + ": " + e.getMessage());
+				logger.severe(e.getMessage());
+			} catch (FatalException e) {
+				treeConnectionManager.showReconnectDialog("Connection Error", "Connection Error" + ": " + e.getMessage());
+				logger.severe(e.getMessage());
+			}
+		}
+
+	}
+
+
+	public void setArgments(String[] args) {
+		arguments = args;
+	}
+
+
+	@Override
+	public void destroy() {
+		// TODO Auto-generated method stub
+
+	}
+
+	
+
+	@Override
+	public void windowClosing(WindowEvent e) {
+		if (e != null && e.getComponent() != null) {
+			e.getWindow().setVisible(false);
+		}
+		closeApp();
+	}
+
+	@Override
+	public void windowActivated(WindowEvent e) { /*nop*/ }
+
+	@Override
+	public void windowClosed(WindowEvent e) { /*nop*/ }
+
+	@Override
+	public void windowDeactivated(WindowEvent e) { /*nop*/ }
+
+	@Override
+	public void windowDeiconified(WindowEvent e) { /*nop*/ }
+
+	@Override
+	public void windowIconified(WindowEvent e) { /*nop*/ }
+
+	@Override
+	public void windowOpened(WindowEvent e) { /*nop*/ }
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/java/jp/ac/u_ryukyu/treevnc/client/TextBoxClient.java	Tue Aug 21 14:24:38 2012 +0900
@@ -0,0 +1,206 @@
+package jp.ac.u_ryukyu.treevnc.client;
+
+import javax.swing.*;
+import java.awt.*;
+import java.awt.event.*;
+import java.util.ArrayList;
+
+public class TextBoxClient extends JFrame implements ActionListener,
+		ItemListener {
+
+	/**
+	 * 
+	 */
+	private static final long serialVersionUID = 1L;
+	private JPanel panel = new JPanel();
+	private JButton button = new JButton("Connect");
+	private TextField t1;
+	private TextField t2;
+	private double width = 750;
+	private double height = 500;
+	private JLabel label;
+	private boolean flag;
+	private ArrayList<String> temp = new ArrayList<String>();
+	private int counter = 0;
+	// 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();
+		setButton();
+		visible();
+	}
+
+	private void setSize() {
+		Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
+		width = (d.getWidth() / 2);
+		height = (d.getHeight() / 2);
+	}
+
+	public void visible() {
+		Point point = new Point();
+		point.setLocation(width - 250, height - 80);
+		setLocation(point.getLocation());
+		pack();
+		setVisible(true);
+	}
+
+	public void unVisible() {
+		setVisible(false);
+	}
+
+	private  void setText() {
+		t1 = new TextField("Address", 30);
+		t2 = new TextField("5999", 5);
+		panel.add(t1);
+		panel.add(t2);
+		//panel.add(button);
+		//button.addActionListener(this);
+		label = new JLabel();
+		Container contentPane = getContentPane();
+		contentPane.add(panel, BorderLayout.CENTER);
+		contentPane.add(label, BorderLayout.SOUTH);
+	}
+
+	public void checkBox(String str) {
+		// CheckboxGroup ch = new CheckboxGroup();
+		if (counter == 0)
+			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].addItemListener(this);
+		panel.add(check[counter]);
+		panel.setLayout(new GridLayout(counter + 2, 0));
+		panel.setLocation((int) width - 250, (int) height - 80);
+		counter++;
+	}
+
+	public void setButton() {
+		panel.add(button);
+		// 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));
+		label.setFont(new Font("Arial", Font.PLAIN, 20));
+		pane.add(label);
+	}
+
+	public String getAddressOption() {
+		while (!(flag)) {
+			try {
+				Thread.sleep(500);
+			} catch (InterruptedException e) {
+				e.printStackTrace();
+			}
+		}
+		return t1.getText();
+	}
+
+	public String getAddress() {
+		int i = 0;
+		while (!(flag)) {
+			if (i >= 50) {
+				/*
+				reportWindow();
+				visible();
+				break;
+				*/
+				return "notFound";
+			}
+			try {
+				Thread.sleep(500);
+			} catch (InterruptedException e) {
+				e.printStackTrace();
+			}
+			i++;
+		}
+		return hostAddress;
+		// return t1.getText();
+	}
+
+	public String getPortOption() {
+		return t2.getText();
+	}
+
+	public String getPort() {
+		return port;
+		// return t2.getText();
+	}
+
+	public void actionPerformed(ActionEvent e) {
+		System.out.println("Action");
+		flag = true;
+		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());
+				unVisible();
+				// else
+				// setStatus()
+			}
+		}
+	}
+
+	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("port=" + port);
+			hostAddress = temp[3];
+		}
+	}
+
+	String splitString(String str) {
+		String[] split = str.split("\\*");
+		String comper;
+		if (split.length > 4) {
+			split[4] = null;
+		}
+		comper = split[1] + split[3];
+		if (firstFlag) {
+			temp.add(comper);
+			firstFlag = false;
+			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];
+				}
+			} else {
+				break;
+			}
+		}
+		return null;
+	}
+
+	public void itemStateChanged(ItemEvent e) {
+	}
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/java/jp/ac/u_ryukyu/treevnc/client/WaitReply.java	Tue Aug 21 14:24:38 2012 +0900
@@ -0,0 +1,55 @@
+package jp.ac.u_ryukyu.treevnc.client;
+
+import java.io.IOException;
+import java.net.ServerSocket;
+import java.net.Socket;
+
+import jp.ac.u_ryukyu.treevnc.*;
+
+
+public class WaitReply extends Thread {
+	InterfaceForViewer client;
+	private String treenum;
+	boolean passflag;
+	
+
+
+	public WaitReply(String treenum, InterfaceForViewer client) {
+		this.client = client;
+		this.treenum = treenum;
+	}
+	
+	public boolean checkPath() {
+		return passflag;
+	}
+	
+	public void run() {
+		Socket clientSocket = null;
+		ServerSocket echoServer = null;
+
+		while (true) {
+			try {
+				echoServer = new ServerSocket(10001);
+				clientSocket = echoServer.accept();
+				
+				if (clientSocket != null) {
+					client.close();
+					/*
+					passflag = true;
+					client.setClientSocket(clientSocket);
+					client.init();
+					client.setEchoValue(null);
+					client.getParentName();
+					client.start_threads();
+					client.start();
+					*/
+					client.run();
+					echoServer.close();
+				}
+
+			} catch (IOException e) {
+				System.out.println(e);
+			}
+		}
+	}
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/java/jp/ac/u_ryukyu/treevnc/server/AcceptClient.java	Tue Aug 21 14:24:38 2012 +0900
@@ -0,0 +1,303 @@
+package jp.ac.u_ryukyu.treevnc.server;
+
+import java.net.Socket;
+import java.net.UnknownHostException;
+import java.io.*;
+import java.net.*;
+import java.util.*;
+
+public class AcceptClient {
+	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;
+	private int passCheck = 0;
+	private final int treebranch = 2; // treeの子ノードの数 
+	private String newparent,request,myAddress;
+	private String leaderflag = "0", sendleaderflag = "0";
+	private final int intv_time = 100;
+
+
+
+	public AcceptClient(String name) {
+		//this.name = name;
+	}
+
+
+	/*
+	public AcceptClient() {
+		new CreateThread(this);
+	}
+	*/
+
+	// public synchronized void transferParentAddrerss(BufferedReader
+	// is,PrintStream os) {
+	public void transferParentAddrerss(BufferedReader is,PrintStream os) {
+		// クライアントからのメッセージを待ち、受け取ったメッセージをそのまま返す
+		try {
+			while (true) {
+				String line = is.readLine();
+				String port = is.readLine();
+				myAddress = getMyAddress();
+				if ("1".equals(line)||"3".equals(line)) {
+					String treeNumber = is.readLine();
+					// reply to Parents lost node
+					checkWait(os,is,port,Integer.parseInt(treeNumber));
+					
+				} else if ("2".equals(line)) {
+					// reply to not Found Parents
+					replyNodeInformation(port);
+					listupdate(port, newparent);
+					outputStream(os, newparent, String.valueOf(parentnum),
+							port, leaderflag);
+					os.close();
+					is.close();
+				} else if (line!=null){
+					//connection First time
+					if(checkAddress(line)){
+						outputStream(os, myAddress,"0","0","0");
+						break;
+					}else {
+						if(replyCreateTree(os, port, line)) {
+							break;
+						} else {
+							break;
+						}
+					}
+				}
+			}
+		} catch (IOException e) {
+			System.out.println(e);
+		} catch (InterruptedException e) {
+			e.printStackTrace();
+		}
+	}
+	
+	private boolean checkAddress(String line){
+		String test[] = line.split("\\.");
+		int a = Integer.parseInt(test[0]);
+		int b = Integer.parseInt(test[1]);
+		if((192==a&&b==168)||(172==a&&(b>15||b<32))||10==a) {
+			return true;
+		} else{
+			return false;		
+		}
+	}
+
+	/**
+	 * @param port
+	 *            parent value
+	 */
+	private synchronized void listupdate(String port) {
+		ls.remove(Integer.parseInt(port));
+		ls.add(Integer.parseInt(port), ls.getLast());
+		ls.removeLast();
+	}
+	
+	private synchronized void listupdate(String port,String myaddr) {
+		ls.remove(Integer.parseInt(port));
+		ls.add(Integer.parseInt(port), myaddr);
+		ls.removeLast();
+	}
+
+	private void outputStream(PrintStream os, String request, String parentnum,
+			String treenum, String leaderflag) {
+		os.println(request);
+		os.println(parentnum);
+		os.println(treenum);
+		os.println(leaderflag);
+	}
+
+	private void checkParameter(int parent, int counter, String leaderflag) {
+		System.out.println("number p =" + parentnum);
+		System.out.println("number i =" + counter);
+		System.out.println("leaderflag=" + leaderflag + "\n");
+	}
+
+	private synchronized void addClientAdress(String line, LinkedList<String> ls) {
+		if (line != null) {
+			ls.add(line);
+		}
+		//displyLinkedList(ls);
+	}
+	
+	private void displyLinkedList( LinkedList<String> ls) {
+		int g = 0;
+		for (String bs : ls) {
+			System.out.println(g + "number" + bs);
+			g++;
+		}
+	}
+
+	private String decisionLeader(int counter, int treebranch) {
+		if ((counter - 1) % treebranch == 1) { // children in most young treenum
+												// have leaderflag 1 other 0
+			return "0";
+		} else {
+			return "1";
+		}
+	}
+	
+	String getMyAddress () {
+		InetAddress addr = null;
+		try {
+			addr = InetAddress.getLocalHost();
+		} catch (UnknownHostException e) {
+			e.printStackTrace();
+		}
+		return new String(addr.getHostAddress());
+	}
+	
+	private void replyNodeInformation (String port) {
+		parentnum = (Integer.parseInt(port) - 1) / treebranch;
+		newparent = ls.get(parentnum);
+		sendleaderflag = decisionLeader(Integer.parseInt(port), treebranch);
+		//leaderflag = decisionLeader(Integer.parseInt(port),treebranch);
+	}
+	
+	private void replyLeaderNode(PrintStream os,BufferedReader is,String port,String treeNumber) throws IOException, InterruptedException {
+		os.println(ls.getLast());
+		replyNodeInformation(port);
+		counter--;
+		passCheck = 1;
+		reportLastNode(ls.getLast(), newparent,port, String.valueOf(parentnum),sendleaderflag);
+		listupdate(port);
+		waitThread();
+		/*
+		if (Integer.parseInt(treeNumber)==ls.size()-1)
+			return;
+			*/
+		//displyLinkedList(ls);
+		os.println(port);
+		leaderflag = decisionLeader(Integer.parseInt(treeNumber),treebranch);
+		os.println(treeNumber);
+		Thread.sleep(intv_time);
+		is.close();
+		os.close();
+	}
+	
+	private void replyNormalChildren(PrintStream os,BufferedReader is,String port,String treeNumber,boolean flag) throws IOException, InterruptedException {
+		if(flag)
+			notifyThread();
+		else
+			waitThread();
+		if (Integer.parseInt(treeNumber)==ls.size())
+			return;
+		os.println(ls.get(Integer.parseInt(port)));
+		os.println(port);
+		if(ls.size()-1+passCheck == Integer.parseInt(treeNumber))
+			treeNumber = "skip";
+		passCheck = 0;
+		os.println(treeNumber);
+		System.out.println("num4="+ ls.get(Integer.parseInt(port)));
+		runflag = false;
+		is.close();
+		os.close();
+	}
+	
+	private synchronized boolean replyCreateTree(PrintStream os,String port,String line) throws InterruptedException {
+		if (addrRegistor == true) {
+			ls.add(myAddress);
+			addrRegistor = false;
+		}
+
+		if (line != null) {
+			addClientAdress(line, ls);
+			counter++;
+		} else {
+			return true;
+		}
+		
+		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),
+					String.valueOf(counter), leaderflag);
+			checkParameter(parentnum, counter, leaderflag);
+		} else {
+			// treeの親ノードに接続する人に接続する人を教える
+			outputStream(os, myAddress, "0",
+					String.valueOf(counter), leaderflag);
+		}
+		Thread.sleep(intv_time);
+		return false;
+	}
+
+	void reportLastNode(String newchild, String newparent, String newtreenum,
+			String newpnum, String newleaderflag) throws IOException {
+		try {
+			Socket echoSocket;
+			System.out.println(newchild + "connect");
+			// echoSocket = new Socket(newchild, 10001 + (i + 1));//
+			// i+1は実験中に同じマシーンを使っていたのでportを変えて対応、本番時には取り除く予定。
+			echoSocket = new Socket(newchild, 10001);
+			DataOutputStream os = new DataOutputStream(echoSocket.getOutputStream());
+			os.writeBytes(newparent + "\n");
+			os.writeBytes(newpnum + "\n");
+			os.writeBytes(newtreenum + "\n");
+			os.writeBytes(newleaderflag + "\n");
+			os.close();
+		} catch (UnknownHostException e) {
+			System.err.println("Don't know about host: localhost");
+		} catch (IOException e) {
+			System.err
+					.println("Couldn't get I/O for the connection to: localhost");
+		}
+	}
+
+	void reportFinishFlag(String nextLastNode) {
+		Socket echoSocket;
+		try {
+			echoSocket = new Socket(nextLastNode, 10001);
+			DataOutputStream os = new DataOutputStream(
+					echoSocket.getOutputStream());
+			os.writeBytes("lastnode" + "\n");
+		} catch (UnknownHostException e) {
+			e.printStackTrace();
+		} catch (IOException e) {
+			e.printStackTrace();
+		}
+
+	}
+	
+	synchronized void checkWait(PrintStream os,BufferedReader is,String port,int treeNum) throws InterruptedException, IOException {
+		final int TIMEOUT = 3000;
+		if (passNumber == 0) {
+			passNumber++;
+			numberZone = ((treeNum - 1) / treebranch);
+			//System.out.println(treeNum + "--wait--");
+			replyLeaderNode(os,is,port,String.valueOf(treeNum));
+			notifyAll();
+			passNumber = 0;
+		} else if (numberZone == ((treeNum - 1) / treebranch)) {
+			if (++passNumber == treebranch) {
+				//System.out.println(treeNum + "--notify--");
+				passNumber = 0;
+				replyNormalChildren(os,is,port,String.valueOf(treeNum),true);
+			} else {
+				//System.out.println(treeNum + "--waityobi--");
+				replyNormalChildren(os,is,port,String.valueOf(treeNum),false);
+				wait(TIMEOUT);
+			}
+		} else {
+			wait();
+			checkWait(os,is,port,treeNum);
+		}
+	}
+	
+	private void waitThread() {
+		final int TIMEOUT = 3000;
+		try {
+			wait(TIMEOUT);
+		} catch (InterruptedException e) {
+			e.printStackTrace();
+		}
+	}
+	private void notifyThread() {
+		notifyAll();
+	}
+ }
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/java/jp/ac/u_ryukyu/treevnc/server/AcceptThread.java	Tue Aug 21 14:24:38 2012 +0900
@@ -0,0 +1,42 @@
+package jp.ac.u_ryukyu.treevnc.server;
+import java.net.Socket;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+public class AcceptThread implements Runnable {
+        MyRfbProtoProxy rfb = null;
+        byte[] imageBytes;
+        int port;
+        
+        AcceptThread(MyRfbProtoProxy _rfb) {
+                rfb = _rfb;
+        }
+
+
+        AcceptThread(MyRfbProtoProxy _rfb, int p) {
+            rfb = _rfb;
+            port = p;
+        }
+       
+	public void changeRfb(MyRfbProtoProxy _rfb) {
+		rfb = _rfb;
+	}
+
+	public void run() {
+		rfb.selectPort(port);
+
+		while (true) {
+			try {
+				Socket newCli = rfb.accept();
+
+				OutputStream os = newCli.getOutputStream();
+				InputStream is = newCli.getInputStream();
+				rfb.newClient(this, newCli, os, is);
+			} catch (IOException e) {
+				e.printStackTrace();
+				System.out.println(e);
+			}
+		}
+	}
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/java/jp/ac/u_ryukyu/treevnc/server/BroadCastProxy.java	Tue Aug 21 14:24:38 2012 +0900
@@ -0,0 +1,40 @@
+package jp.ac.u_ryukyu.treevnc.server;
+
+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) {	
+		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();
+			}
+		}
+	}
+
+	void sendData() {
+		os.println(str);
+	}
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/java/jp/ac/u_ryukyu/treevnc/server/CreateThread.java	Tue Aug 21 14:24:38 2012 +0900
@@ -0,0 +1,88 @@
+package jp.ac.u_ryukyu.treevnc.server;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.PrintStream;
+import java.net.BindException;
+import java.net.ServerSocket;
+import java.net.Socket;
+
+public class CreateThread implements Runnable {
+	ServerSocket echoServer;
+	AcceptClient acceptClient;
+	int port;
+	
+	public CreateThread(AcceptClient _acc) {
+		acceptClient = _acc;
+		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
+				acceptClient.transferParentAddrerss(is,os);
+			}
+		};
+		new Thread(echoSender).start();
+	}
+
+	void selectPort(int p) {
+		int port = p;
+		while (true) {
+			try {
+				initServSock(port);
+				break;
+			} catch (BindException e) {
+				port++;
+				continue;
+			} catch (IOException e) {
+
+			}
+		}
+		System.out.println("accept Echo port = " + port);
+	}
+	
+	void initServSock(int port) throws IOException {
+		echoServer = new ServerSocket(port);
+		this.port = port;
+	}
+	
+	
+	public void run() {
+		selectPort(port);
+		
+		while (true) {
+			try {
+//				echoServer = new ServerSocket(9999);
+				Socket clientSocket = echoServer.accept();
+				BufferedReader is = new BufferedReader(new InputStreamReader(
+						clientSocket.getInputStream()));
+				PrintStream os = new PrintStream(clientSocket.getOutputStream());
+				newEchoClient(is,os);
+//				acceptClient.transferParentAddrerss(is, os);
+			} catch (IOException e) {
+				System.out.println(e);
+			}
+/*
+			try {
+				echoServer.close();
+			} catch (IOException e) {
+				System.out.println(e);
+			}
+*/
+
+		}
+
+	}
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/java/jp/ac/u_ryukyu/treevnc/server/GetBroadCastProxy.java	Tue Aug 21 14:24:38 2012 +0900
@@ -0,0 +1,98 @@
+package jp.ac.u_ryukyu.treevnc.server;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.net.DatagramPacket;
+import java.net.InetAddress;
+import java.net.MulticastSocket;
+import java.net.SocketAddress;
+
+//import TextBoxProxy;
+
+public class GetBroadCastProxy implements Runnable {
+	static final String McastAddr = "224.0.0.1";
+	static final int Port = 8183;
+	static final int BufSize = 1024;
+	private byte[] buf = new byte[BufSize];
+	private byte[] resorve = new byte[BufSize];
+	private ByteArrayInputStream inputStream;
+	private boolean stopFlag = false;
+	private VncProxyService vps;
+	private BroadCastProxy bCast;
+	private String address;
+
+	public GetBroadCastProxy(VncProxyService _vps){
+		vps = _vps;
+		bCast = new BroadCastProxy(vps.rfb.acceptPort+":"+vps.host+":"
+				+vps.rfb.desktopName+":"+vps.acc.getMyAddress()+":");
+	}
+	
+	private synchronized void getData() {
+		try {
+			InetAddress mAddr = InetAddress.getByName(McastAddr);
+			MulticastSocket soc = new MulticastSocket(Port);
+			DatagramPacket recvPacket = new DatagramPacket(buf, BufSize);
+			soc.joinGroup(mAddr);
+			while (true) {
+				soc.receive(recvPacket);
+				address = getAddress(recvPacket.getSocketAddress());
+				inputStream = new ByteArrayInputStream(recvPacket.getData());
+				inputStream.read(resorve);
+				if("who".equals(castString(resorve))){
+						replyBroadCast();
+				}
+			}
+		} catch (IOException e) {
+			e.printStackTrace();
+		}
+	}
+	
+	private void replyBroadCast() {
+		Runnable sender = new Runnable() {
+			public void run() {
+				bCast.createSocket(address);
+			}
+		};
+		new Thread(sender).start();
+	}
+
+	private String getAddress(SocketAddress addr) {
+		String str = addr.toString();
+		str = str.substring(1,str.indexOf(":"));
+		return str;
+	}
+/*	
+	private int castBytoToInt(byte[] a) {
+		int value = 0;
+		ByteArrayInputStream bais = new ByteArrayInputStream(a);
+		DataInputStream dis = new DataInputStream(bais);
+		try {
+			value = dis.readInt();
+		} catch (IOException e) {
+		}
+		System.out.println(value);
+		return value;
+	}
+*/
+	private String castString(byte[] a) {
+		String recover = new String(a);
+		recover = recover.replace("¥n", "");
+		recover = recover.trim();
+//		System.out.println(recover);
+		return recover;
+	}
+	
+	
+	public void run() {
+		getData();
+	}
+
+	public void setStopFlag(boolean stopFlag) {
+		this.stopFlag = stopFlag;
+	}
+
+	public boolean isStopFlag() {
+		return stopFlag;
+	}
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/java/jp/ac/u_ryukyu/treevnc/server/MyRfbProtoProxy.java	Tue Aug 21 14:24:38 2012 +0900
@@ -0,0 +1,664 @@
+package jp.ac.u_ryukyu.treevnc.server;
+
+import static org.junit.Assert.*;
+
+import java.awt.Graphics;
+import java.awt.Image;
+import java.awt.image.BufferedImage;
+import java.io.BufferedOutputStream;
+import java.io.BufferedReader;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.net.BindException;
+import java.net.ServerSocket;
+import java.net.Socket;
+import java.nio.ByteBuffer;
+import java.util.Iterator;
+import java.util.LinkedList;
+
+import javax.imageio.ImageIO;
+
+import org.junit.Test;
+
+
+//import myVncProxy.MulticastQueue.Client;
+
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.zip.DataFormatException;
+import java.util.zip.Deflater;
+import java.util.zip.Inflater;
+import java.io.OutputStream;
+
+import jp.ac.u_ryukyu.treevnc.MulticastQueue;
+
+public class MyRfbProtoProxy {
+	final static String versionMsg_3_855 = "RFB 003.855\n";
+	/**
+	 * CheckMillis is one of new msgType for RFB 3.855.
+	 */
+	final static byte SpeedCheckMillis = 4;
+
+	// Secyrity type of OS X
+	final static int SecTypeReqAccess = 32;
+
+	// Supported authentication types
+	final static int AuthAccess = 32;
+
+	private static final int INFLATE_BUFSIZE = 1024 * 100;
+	boolean printStatusFlag = false;
+	long startCheckTime;
+	private int messageType;
+	private int rectangles;
+	private int rectX;
+	private int rectY;
+	private int rectW;
+	private int rectH;
+	private int encoding;
+	private int zLen;
+	private boolean clicomp = false;
+
+	private ServerSocket servSock;
+	protected int acceptPort;
+	// private byte initData[];
+	byte initData[];
+	private LinkedList<Socket> cliListTmp;
+	private LinkedList<Socket> cliList;
+	boolean createBimgFlag;
+	boolean proxyFlag = true;
+
+	ExecutorService executor;
+
+	byte[] pngBytes;
+
+	// private MulticastQueue<LinkedList<ByteBuffer>> multicastqueue = new
+	// MostRecentMultiCast<LinkedList<ByteBuffer>>(10);
+	private MulticastQueue<LinkedList<ByteBuffer>> multicastqueue = new MulticastQueue<LinkedList<ByteBuffer>>();
+	private int clients = 0;
+	private Inflater inflater = new Inflater();
+	private Deflater deflater = new Deflater();
+	private CreateThread geth;
+	// private Thread requestThread;
+	private RequestScreenThread rThread;
+	private Thread requestThread;
+
+	public MyRfbProtoProxy() throws IOException {
+	}
+
+
+	void initServSock(int port) throws IOException {
+		servSock = new ServerSocket(port);
+		acceptPort = port;
+	}
+
+	void authenticationRequestAccess() throws IOException {
+
+		byte[] headBuf = new byte[2];
+		is.read(headBuf);
+		if (headBuf[1] == 2) {
+			byte[] b = new byte[258];
+			is.read(b);
+
+			byte[] outBuf = new byte[256];
+			os.write(outBuf);
+			os.flush();
+		} else if (headBuf[1] == 23) {
+			byte[] b = new byte[130];
+			is.read(b);
+			byte[] outBuf = new byte[192];
+			os.write(outBuf);
+			os.flush();
+		}
+
+		int result = readU32();
+		if (result != 0) {
+			System.out.println("faild authentication  ");
+			throw new IOException();
+		}
+
+	}
+
+	/*
+	 * default port number is 5999.
+	 */
+	public void selectPort(int p) {
+		if (servSock != null)
+			return;
+		int port = p;
+		while (true) {
+			try {
+				initServSock(port);
+				break;
+			} catch (BindException e) {
+				port++;
+				continue;
+			} catch (IOException e) {
+
+			}
+		}
+		System.out.println("accept port = " + port);
+	}
+
+	int getAcceptPort() {
+		return acceptPort;
+	}
+
+	void setSoTimeout(int num) throws IOException {
+		servSock.setSoTimeout(num);
+	}
+
+	public Socket accept() throws IOException {
+		return servSock.accept();
+	}
+
+	void addSock(Socket sock) {
+		cliList.add(sock);
+	}
+
+	void addSockTmp(Socket sock) {
+		System.out.println("connected " + sock.getInetAddress());
+		cliListTmp.add(sock);
+	}
+
+	boolean markSupported() {
+		return is.markSupported();
+	}
+
+	synchronized void changeStatusFlag() {
+		printStatusFlag = true;
+	}
+
+	void printMills() {
+		if (printStatusFlag) {
+
+			changeStatusFlag();
+		} else {
+			changeStatusFlag();
+		}
+	}
+
+
+	void requestThreadStart() {
+		requestThread.start();
+	}
+
+	public synchronized void requestThreadNotify() {
+		rThread.reStart();
+	}
+
+	/**
+	 * gzip byte arrays
+	 * 
+	 * @param deflater
+	 * @param inputs
+	 *            byte data[]
+	 * @param inputIndex
+	 * @param outputs
+	 *            byte data[]
+	 * @return byte length in last byte array
+	 * @throws IOException
+	 */
+	public int zip(Deflater deflater, LinkedList<ByteBuffer> inputs,
+			int inputIndex, LinkedList<ByteBuffer> outputs) throws IOException {
+		int len = 0;
+		ByteBuffer c1 = ByteBuffer.allocate(INFLATE_BUFSIZE);
+		while (inputIndex < inputs.size()) {
+			ByteBuffer b1 = inputs.get(inputIndex++);
+			deflater.setInput(b1.array(), b1.position(), b1.remaining());
+			/**
+			 * If we finish() stream and reset() it, Deflater start new gzip
+			 * stream, this makes continuous zlib reader unhappy. if we remove
+			 * finish(), Deflater.deflate() never flushes its output. The
+			 * original zlib deflate has flush flag. I'm pretty sure this a kind
+			 * of bug of Java library.
+			 */
+			if (inputIndex == inputs.size())
+				deflater.finish();
+			int len1 = 0;
+			do {
+				len1 = deflater.deflate(c1.array(), c1.position(),
+						c1.remaining());
+				if (len1 > 0) {
+					len += len1;
+					c1.position(c1.position() + len1);
+					if (c1.remaining() == 0) {
+						c1.flip();
+						outputs.addLast(c1);
+						c1 = ByteBuffer.allocate(INFLATE_BUFSIZE);
+					}
+				}
+			} while (len1 > 0 || !deflater.needsInput()); // &&!deflater.finished());
+		}
+		if (c1.position() != 0) {
+			c1.flip();
+			outputs.addLast(c1);
+		}
+		deflater.reset();
+		return len;
+	}
+
+	/**
+	 * gunzip byte arrays
+	 * 
+	 * @param inflater
+	 * @param inputs
+	 *            byte data[]
+	 * @param outputs
+	 *            byte data[]
+	 * @return number of total bytes
+	 * @throws IOException
+	 */
+	public int unzip(Inflater inflater, LinkedList<ByteBuffer> inputs,
+			int inputIndex, LinkedList<ByteBuffer> outputs, int bufSize)
+			throws DataFormatException {
+		int len = 0;
+		ByteBuffer buf = ByteBuffer.allocate(bufSize);
+		while (inputIndex < inputs.size()) {
+			ByteBuffer input = inputs.get(inputIndex++);
+			inflater.setInput(input.array(), input.position(), input.limit());
+			// if (inputIndex==inputs.size()) if inflater/deflater has symmetry,
+			// we need this
+			// inflater.end(); but this won't work
+			do {
+				int len0 = inflater.inflate(buf.array(), buf.position(),
+						buf.remaining());
+				if (len0 > 0) {
+					buf.position(buf.position() + len0);
+					len += len0;
+					if (buf.remaining() == 0) {
+						buf.flip();
+						outputs.addLast(buf);
+						buf = ByteBuffer.allocate(bufSize);
+					}
+				}
+			} while (!inflater.needsInput());
+		}
+		if (buf.position() != 0) {
+			buf.flip();
+			outputs.addLast(buf);
+		}
+		return len;
+	}
+
+	float maxMag = 1;
+
+	/**
+	 * send data to clients
+	 * 
+	 * @param dataLen
+	 * @throws IOException
+	 * @throws DataFormatException
+	 * 
+	 *             Zlibed packet is compressed in context dependent way, that
+	 *             is, it have to send from the beginning. But this is
+	 *             impossible. So we have to compress it again for each clients.
+	 *             Separate deflater for each clients is necessary.
+	 * 
+	 *             Java's deflater does not support flush. This means to get the
+	 *             result, we have to finish the compression. Reseting start new
+	 *             compression, but it is not accepted well in zlib continuous
+	 *             reading. So we need new Encoding ZRLEE which reset decoder
+	 *             for each packet. ZRLEE can be invisible from user, but it
+	 *             have to be implemented in the clients. 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);
+		header.limit(16);
+		if (header.get(0) == RfbProto.FramebufferUpdate) {
+			int encoding = header.getInt(12);
+			if (encoding == RfbProto.EncodingZRLE
+					|| encoding == RfbProto.EncodingZlib) { // ZRLEE is already
+															// recompressed
+				ByteBuffer len = ByteBuffer.allocate(4);
+				readFully(len.array(), 0, 4);
+				len.limit(4);
+				ByteBuffer inputData = ByteBuffer.allocate(dataLen - 20);
+
+				startTiming();
+				readFully(inputData.array(), 0, inputData.capacity());
+//				System.out.println(dataLen);
+				inputData.limit(dataLen - 20);
+				stopTiming();
+
+				LinkedList<ByteBuffer> inputs = new LinkedList<ByteBuffer>();
+				inputs.add(inputData);
+
+				header.putInt(12, RfbProto.EncodingZRLEE); // means recompress
+															// every time
+				// using new Deflecter every time is incompatible with the
+				// protocol, clients have to be modified.
+				Deflater nDeflater = deflater; // new Deflater();
+				LinkedList<ByteBuffer> out = new LinkedList<ByteBuffer>();
+				unzip(inflater, inputs, 0, out, INFLATE_BUFSIZE);
+				// dump32(inputs);
+				int len2 = zip(nDeflater, out, 0, bufs);
+				ByteBuffer blen = ByteBuffer.allocate(4);
+				blen.putInt(len2);
+				blen.flip();
+				bufs.addFirst(blen);
+
+				bufs.addFirst(header);
+			//	if(dataLen<=64000)
+					multicastqueue.put(bufs);
+				// is.reset();
+
+				/*
+				 * System.out.println("ZRLE = "+dataLen);
+				 * System.out.println("ZRLEE = "+(len2+20)); float mag =
+				 * (float)dataLen / (float)(len2 + 20);
+				 * System.out.println("ZRLE / ZRLEE = "+ mag); if(mag > maxMag)
+				 * maxMag = mag; System.out.println("maxMag = "+maxMag);
+				 */
+				return;
+			}
+			bufs.add(header);
+			if (dataLen > 16) {
+				ByteBuffer b = ByteBuffer.allocate(dataLen - 16);
+				startTiming();
+				readFully(b.array(), 0, dataLen - 16);
+				b.limit(dataLen - 16);
+				stopTiming();
+				bufs.add(b);
+			}
+			multicastqueue.put(bufs);
+			// is.reset();
+			return;
+		}
+		is.reset();
+
+		// It may be compressed. We can inflate here to avoid repeating clients
+		// decompressing here,
+		// 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.
+	}
+
+	public void newClient(AcceptThread acceptThread, final Socket newCli,
+			final OutputStream os, final InputStream is) throws IOException {
+		// createBimgFlag = true;
+		// rfb.addSockTmp(newCli);
+		// addSock(newCli);
+		final int myId = clients;
+		final MulticastQueue.Client<LinkedList<ByteBuffer>> c = multicastqueue
+				.newClient();
+		final AtomicInteger writerRunning = new AtomicInteger();
+		writerRunning.set(1);
+		/**
+		 * Timeout thread. If a client is suspended, it has top of queue
+		 * indefinitely, which caused memory overflow. After the timeout, we
+		 * poll the queue and discard it. Start long wait if writer is running.
+		 */
+		final Runnable timer = new Runnable() {
+			public void run() {
+				int count = 0;
+				for (;;) {
+					long timeout = 50000 / 8;
+					try {
+						synchronized (this) {
+							int state, flag;
+							writerRunning.set(0);
+							wait(timeout);
+							flag = 0;
+							while ((state = writerRunning.get()) == 0) {
+								c.poll(); // discard, should be timeout
+								count++;
+								if (flag == 0) {
+									System.out.println("Discarding " + myId
+											+ " count=" + count);
+									flag = 1;
+								}
+								wait(10); // if this is too short, writer cannot
+											// take the poll, if this is too
+											// long, memory will overflow...
+							}
+							if (flag == 1)
+								System.out.println("Resuming " + myId
+										+ " count=" + count);
+							if (state != 1) {
+								System.out.println("Client died " + myId);
+								break;
+							}
+						}
+					} catch (InterruptedException e) {
+					}
+				}
+			}
+		};
+		new Thread(timer).start();
+		/**
+		 * discard all incoming from clients
+		 */
+		final Runnable reader = new Runnable() {
+			public void run() {
+				byte b[] = new byte[4096];
+				for (;;) {
+					try {
+						int c = is.read(b);
+						if (c <= 0)
+							throw new IOException();
+						// System.out.println("client read "+c);
+					} catch (IOException e) {
+						try {
+							writerRunning.set(2);
+							os.close();
+							is.close();
+						} catch (IOException e1) {
+						}
+						return;
+					}
+				}
+			}
+		};
+		/**
+		 * send packets to a client
+		 */
+		Runnable sender = new Runnable() {
+			public void run() {
+				writerRunning.set(1);
+				try {
+					requestThreadNotify();
+					// rThread.checkDelay();
+
+					/**
+					 * initial connection of RFB protocol
+					 */
+					sendRfbVersion(os);
+					// readVersionMsg(is);
+					int rfbMinor = readVersionMsg(is, os);
+					sendSecurityType(os);
+					readSecType(is);
+					sendSecResult(os);
+					readClientInit(is);
+					sendInitData(os);
+					new Thread(reader).start(); // discard incoming packet here
+												// after.
+					// writeFramebufferUpdateRequest(0,0, framebufferWidth,
+					// framebufferHeight, false );
+					int i  = 0;
+					for (;;) {
+						LinkedList<ByteBuffer> bufs = c.poll();
+						int inputIndex = 0;
+						ByteBuffer header = bufs.get(inputIndex);
+						if (header == null)
+							continue;
+						else if (header.get(0) == RfbProto.CheckDelay) {
+							writeToClient(os, bufs, inputIndex);
+							continue;
+						} else if (header.get(0) == RfbProto.FramebufferUpdate) {
+							// System.out.println("client "+ myId);
+						}
+						/*
+						if(i%20==0){
+							sendDataCheckDelay();
+						}
+						i++;
+						*/
+						writeToClient(os, bufs, inputIndex);
+						writerRunning.set(1); // yes my client is awaking.
+					}
+				} catch (IOException e) {
+					try {
+						writerRunning.set(2);
+						os.close();
+					} catch (IOException e1) {
+					}
+					/* if socket closed cliList.remove(newCli); */
+				}
+			}
+
+			public void writeToClient(final OutputStream os,
+					LinkedList<ByteBuffer> bufs, int inputIndex)
+					throws IOException {
+				while (inputIndex < bufs.size()) {
+					ByteBuffer b = bufs.get(inputIndex++);
+					os.write(b.array(), b.position(), b.limit());
+				}
+				os.flush();
+			}
+		};
+		clients++;
+		new Thread(sender).start();
+
+	}
+
+	public void dump32(LinkedList<ByteBuffer> bufs) {
+		int len = 0;
+		for (ByteBuffer b : bufs)
+			len += b.remaining();
+		ByteBuffer top = bufs.getFirst();
+		ByteBuffer end = bufs.getLast();
+		System.err.println("length: " + len);
+		System.err.print("head 0: ");
+		for (int i = 0; i < 16 && i < top.remaining(); i++) {
+			System.err.print(" " + top.get(i));
+		}
+		System.err.print("tail 0: ");
+		for (int i = 0; i < 16 && i < end.remaining(); i++) {
+			System.err.print(" " + end.get(i));
+		}
+		System.err.println();
+	}
+
+	@Test
+	public void test1() {
+		try {
+			LinkedList<ByteBuffer> in = new LinkedList<ByteBuffer>();
+			LinkedList<ByteBuffer> out = new LinkedList<ByteBuffer>();
+			LinkedList<ByteBuffer> out2 = new LinkedList<ByteBuffer>();
+			// if (false) {
+			// for(int i=0;i<10;i++) {
+			// in.add(ByteBuffer.wrap("test1".getBytes()));
+			// in.add(ByteBuffer.wrap("test2".getBytes()));
+			// in.add(ByteBuffer.wrap("test3".getBytes()));
+			// in.add(ByteBuffer.wrap("test44".getBytes()));
+			// }
+			// } else
+			{
+				String t = "";
+				for (int i = 0; i < 10; i++) {
+					t += "test1";
+					t += "test2";
+					t += "test3";
+					t += "test44";
+				}
+				in.add(ByteBuffer.wrap(t.getBytes()));
+			}
+
+			LinkedList<ByteBuffer> in1 = clone(in);
+
+			Deflater deflater = new Deflater();
+			zip(deflater, in, 0, out);
+			// LinkedList<ByteBuffer> out3 = clone(out); zipped result is depend
+			// on deflator's state
+			unzip(inflater, out, 0, out2, INFLATE_BUFSIZE);
+			// inflater.reset();
+			equalByteBuffers(in1, out2);
+			LinkedList<ByteBuffer> out4 = new LinkedList<ByteBuffer>();
+			deflater = new Deflater();
+			zip(deflater, out2, 0, out4);
+			LinkedList<ByteBuffer> out5 = new LinkedList<ByteBuffer>();
+			unzip(inflater, out4, 0, out5, INFLATE_BUFSIZE);
+			int len = equalByteBuffers(in1, out5);
+
+			System.out.println("Test Ok. " + len);
+		} catch (Exception e) {
+			assertEquals(0, 1);
+		}
+	}
+
+	private LinkedList<ByteBuffer> clone(LinkedList<ByteBuffer> in) {
+		LinkedList<ByteBuffer> copy = new LinkedList<ByteBuffer>();
+		for (ByteBuffer b : in) {
+			ByteBuffer c = b.duplicate();
+			copy.add(c);
+		}
+		return copy;
+	}
+
+	public int equalByteBuffers(LinkedList<ByteBuffer> in,
+			LinkedList<ByteBuffer> out2) {
+		int len = 0;
+		Iterable<Byte> i = byteBufferIterator(in);
+		Iterator<Byte> o = byteBufferIterator(out2).iterator();
+
+		for (int b : i) {
+			len++;
+			if (o.hasNext()) {
+				int c = o.next();
+				assertEquals(b, c);
+			} else
+				assertEquals(0, 1);
+		}
+		if (o.hasNext())
+			assertEquals(0, 1);
+		// System.out.println();
+		return len;
+	}
+
+	private Iterable<Byte> byteBufferIterator(final LinkedList<ByteBuffer> in) {
+		return new Iterable<Byte>() {
+			public Iterator<Byte> iterator() {
+				return new Iterator<Byte>() {
+					int bytes = 0;
+					int buffers = 0;
+
+					public boolean hasNext() {
+						for (;;) {
+							if (buffers >= in.size())
+								return false;
+							ByteBuffer b = in.get(buffers);
+							if (!(bytes < b.remaining())) {
+								buffers++;
+								bytes = 0;
+							} else
+								return true;
+						}
+					}
+
+					public Byte next() {
+						ByteBuffer bf = in.get(buffers);
+						byte b = bf.get(bytes++);
+						if (bf.remaining() <= bytes) {
+							buffers++;
+							bytes = 0;
+						}
+						// System.out.print(b);
+						return b;
+					}
+
+					public void remove() {
+					}
+				};
+			}
+		};
+	}
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/java/jp/ac/u_ryukyu/treevnc/server/RequestScreenThread.java	Tue Aug 21 14:24:38 2012 +0900
@@ -0,0 +1,43 @@
+package jp.ac.u_ryukyu.treevnc.server;
+
+import java.io.IOException;
+
+public class RequestScreenThread implements Runnable {
+	MyRfbProtoProxy rfb;
+
+	RequestScreenThread(MyRfbProtoProxy _rfb) {
+		rfb = _rfb;
+	}
+
+	public void run() {
+		while (true) {
+			try {
+				waitThread();
+				Thread.sleep(3000);
+				rfb.writeFramebufferUpdateRequest(0, 0, rfb.framebufferWidth,
+						rfb.framebufferHeight, false);
+
+			} catch (Exception e) {
+				e.printStackTrace();
+				break;
+			}
+		}
+	}
+	
+    public synchronized void waitThread() {
+    	try{
+    		wait();
+        }catch(InterruptedException e) {
+        	e.printStackTrace();
+    	}
+    }
+
+    public synchronized void reStart() {
+    	notify();
+    }
+    
+    public void checkDelay() throws IOException {
+    	rfb.checkDelayData();
+    }
+    
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/java/jp/ac/u_ryukyu/treevnc/server/TextBoxProxy.java	Tue Aug 21 14:24:38 2012 +0900
@@ -0,0 +1,126 @@
+package jp.ac.u_ryukyu.treevnc.server;
+
+import javax.swing.*;
+import java.awt.*;
+import java.awt.event.*;
+
+public class TextBoxProxy extends JFrame implements ActionListener {
+
+	/**
+	 * 
+	 */
+	private static final long serialVersionUID = 1L;
+	private JPanel panel;
+	private JButton button;
+	private JButton button1;
+	private TextField t1;
+	private TextField t2;
+	private JPasswordField pw;
+	private double width;
+	private double height;
+	private JLabel label;
+	private boolean flag;
+	private VncProxyService vps;
+
+	public void ipRegister() {
+		setSize();
+		setText();
+		visible();
+	}
+
+	public TextBoxProxy(VncProxyService _vps) {
+		vps = _vps;
+		setTitle("Informatin Connection Address");
+		setResizable(false);
+		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
+	}
+
+	private void setSize() {
+		Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
+		width = (d.getWidth() / 2);
+		height = (d.getHeight() / 2);
+	}
+
+	private void visible() {
+		Point point = new Point();
+		point.setLocation(width - 250, height - 80);
+		setLocation(point.getLocation());
+		pack();
+		setVisible(true);
+	}
+	
+	private void init(){
+		frameInit();
+//		panel = null;
+//		button = null;
+//		label = null;
+		setVisible(false);
+	}
+	
+	public void changeHost() {
+		init();
+		button1 = new JButton("Change Host");
+		t1 = new TextField("Address", 30);
+		panel = new JPanel();
+		panel.add(t1);
+		panel.add(button1);
+		button1.addActionListener(this);
+		label = new JLabel();
+		Container contentPane = getContentPane();
+		contentPane.add(panel, BorderLayout.CENTER);
+		contentPane.add(label, BorderLayout.SOUTH);
+		visible();
+	}
+
+	private void setText() {
+		panel = new JPanel();
+		t1 = new TextField("localhost", 30);
+		t2 = new TextField("5900", 5);
+//		pw = new JPasswordField("Password",30);
+		button = new JButton("Connect");
+		panel.add(t1);
+		panel.add(t2);
+//		panel.add(pw);
+		panel.add(button);
+		button.addActionListener(this);
+		label = new JLabel();
+		Container contentPane = getContentPane();
+		contentPane.add(panel, BorderLayout.CENTER);
+		contentPane.add(label, BorderLayout.SOUTH);
+	}
+	
+	public String getAddress() {
+		while(!(flag)) {
+			try {
+				Thread.sleep(500);
+			} catch (InterruptedException e) {
+				e.printStackTrace();
+			}
+		}
+		return t1.getText();
+	}
+	public String getPort() {
+		return t2.getText();
+	}
+	
+
+	public String getPassword() {
+		return String.valueOf(pw.getPassword());
+	}
+
+
+	public void actionPerformed(ActionEvent e) {
+		if(e.getSource()==button) {
+			flag = true;
+			setVisible(false);
+		}
+		if(e.getSource()==button1)
+			try {
+				init();
+				vps.host = getAddress();
+				vps.changeInit();
+			} catch (Exception e1) {
+				e1.printStackTrace();
+			}
+	}
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/java/jp/ac/u_ryukyu/treevnc/server/VncProxyService.java	Tue Aug 21 14:24:38 2012 +0900
@@ -0,0 +1,184 @@
+package jp.ac.u_ryukyu.treevnc.server;
+
+import java.awt.event.*;
+import java.io.*;
+import java.util.logging.Logger;
+
+
+import com.glavsoft.exceptions.AuthenticationFailedException;
+import com.glavsoft.exceptions.FatalException;
+import com.glavsoft.exceptions.TransportException;
+import com.glavsoft.exceptions.UnsupportedProtocolVersionException;
+import com.glavsoft.exceptions.UnsupportedSecurityTypeException;
+import com.glavsoft.rfb.IChangeSettingsListener;
+import com.glavsoft.rfb.IRfbSessionListener;
+import com.glavsoft.rfb.protocol.Protocol;
+import com.glavsoft.rfb.protocol.ProtocolSettings;
+import com.glavsoft.transport.Reader;
+import com.glavsoft.transport.Writer;
+import com.glavsoft.viewer.ConnectionManager;
+import com.glavsoft.viewer.Viewer;
+import com.glavsoft.viewer.cli.Parser;
+import com.glavsoft.viewer.swing.ClipboardControllerImpl;
+import com.glavsoft.viewer.swing.ParametersHandler;
+import com.glavsoft.viewer.swing.Surface;
+import com.glavsoft.viewer.swing.UiSettings;
+import com.glavsoft.viewer.swing.ParametersHandler.ConnectionParams;
+
+public class VncProxyService extends Viewer implements Runnable, 
+	IRfbSessionListener, IChangeSettingsListener {
+
+	/**
+	 * 
+	 */
+	private static final long serialVersionUID = 1L;
+
+	public MyRfbProtoProxy rfb;
+	public VncProxyService(Parser parser) {
+		this();
+		try {
+			rfb = new MyRfbProtoProxy();
+		} catch (IOException e) {
+			e.printStackTrace();
+		}
+		ParametersHandler.completeSettingsFromCLI(parser, connectionParams, settings, uiSettings);
+		showControls = ParametersHandler.showControls;
+		passwordFromParams = parser.getValueFor(ParametersHandler.ARG_PASSWORD);
+		logger.info("TightVNC Viewer version " + ver());
+		isApplet = false;
+	}
+	
+	public VncProxyService() {
+		connectionParams = new ParametersHandler.ConnectionParams();
+		settings = ProtocolSettings.getDefaultSettings();
+		uiSettings = super.uiSettings;
+
+	}
+	
+	boolean isClient = false;
+	public static final int DEFAULT_PORT = 5900;
+	public static Logger logger = Logger.getLogger("com.glavsoft");
+	private boolean forceReconnection;
+	private String reconnectionReason;
+	private ConnectionParams connectionParams;
+	private final ProtocolSettings settings;
+	private final UiSettings uiSettings;
+	private String[] arguments;
+	
+	
+	public static void main(String[] argv) {
+		String[] mainArgs = argv;
+		System.out.println(mainArgs.length);
+		// input into arguments Decision
+
+		Parser parser = new Parser();
+		ParametersHandler.completeParserOptions(parser);
+
+		parser.parse(argv);
+		if (parser.isSet(ParametersHandler.ARG_HELP)) {
+			printUsage(parser.optionsUsage());
+			System.exit(0);
+		}
+		VncProxyService vps = new VncProxyService(parser);
+		if (mainArgs.length != 0) {
+			for (int i = 0; i < argv.length; i++) {
+				vps.setArguments(mainArgs);
+				// write later
+			}
+		} else {
+			//getHostData();
+		}
+		//SwingUtilities.invokeLater(myClient);
+		Thread th = new Thread(vps);
+		th.start();
+	}
+	
+	private void setArguments(String[] mainArgs) {
+		arguments = mainArgs;		
+	}
+
+	@Override
+	public void run() {
+	//	getHostData();
+		ConnectionManager connectionManager = new ConnectionManager(this, isApplet);
+		if (forceReconnection) {
+			connectionManager.showReconnectDialog("Connection lost", reconnectionReason);
+			forceReconnection = false;
+		}
+		tryAgain = true;
+		while (tryAgain) {
+		  connectionParams.hostName = arguments[0];
+		//	workingSocket = connectionManager.connectToTreeHost(connectionParams, settings);
+			workingSocket = connectionManager.connectToHost(connectionParams, settings);
+			if (null == workingSocket) {
+				closeApp();
+				break;
+			}
+			logger.info("Connected");
+
+			try {
+				workingSocket.setTcpNoDelay(true); // disable Nagle algorithm
+				Reader reader = new Reader(workingSocket.getInputStream());
+				Writer writer = new Writer(workingSocket.getOutputStream());
+				
+				workingProtocol = new Protocol(reader, writer,
+						new PasswordChooser(passwordFromParams, connectionParams, containerFrame, this),
+						settings);
+
+				workingProtocol.handshake();
+				// input into change parents
+                ClipboardControllerImpl clipboardController =
+		                new ClipboardControllerImpl(workingProtocol, settings.getRemoteCharsetName());
+				clipboardController.setEnabled(settings.isAllowClipboardTransfer());
+				settings.addListener(clipboardController);
+
+				surface = new Surface(workingProtocol, this, uiSettings.getScaleFactor());
+				settings.addListener(this);
+				uiSettings.addListener(surface);
+				containerFrame = createContainer();
+				connectionManager.setContainerFrame(containerFrame);
+				updateFrameTitle();
+
+				workingProtocol.startNormalHandling(this, surface, clipboardController);
+				tryAgain = false;
+			} catch (UnsupportedProtocolVersionException e) {
+				connectionManager.showReconnectDialog("Unsupported Protocol Version", e.getMessage());
+				logger.severe(e.getMessage());
+			} catch (UnsupportedSecurityTypeException e) {
+				connectionManager.showReconnectDialog("Unsupported Security Type", e.getMessage());
+				logger.severe(e.getMessage());
+			} catch (AuthenticationFailedException e) {
+				passwordFromParams = null;
+				connectionManager.showReconnectDialog("Authentication Failed", e.getMessage());
+				logger.severe(e.getMessage());
+			} catch (TransportException e) {
+				connectionManager.showReconnectDialog("Connection Error", "Connection Error" + ": " + e.getMessage());
+				logger.severe(e.getMessage());
+			} catch (IOException e) {
+				connectionManager.showReconnectDialog("Connection Error", "Connection Error" + ": " + e.getMessage());
+				logger.severe(e.getMessage());
+			} catch (FatalException e) {
+				connectionManager.showReconnectDialog("Connection Error", "Connection Error" + ": " + e.getMessage());
+				logger.severe(e.getMessage());
+			}
+		}
+
+	}
+
+
+
+	@Override
+	public void destroy() {
+
+	}
+
+	
+
+	@Override
+	public void windowClosing(WindowEvent e) {
+		if (e != null && e.getComponent() != null) {
+			e.getWindow().setVisible(false);
+		}
+		closeApp();
+	}
+}
--- a/src/viewer_swing/java/com/glavsoft/viewer/ConnectionManager.java	Tue Aug 21 14:02:05 2012 +0900
+++ b/src/viewer_swing/java/com/glavsoft/viewer/ConnectionManager.java	Tue Aug 21 14:24:38 2012 +0900
@@ -24,9 +24,6 @@
 
 package com.glavsoft.viewer;
 
-import ac.ryukyu.treevnc.client.GetDataClient;
-import ac.ryukyu.treevnc.client.GetHostClient;
-import ac.ryukyu.treevnc.client.TextBoxClient;
 
 import com.glavsoft.rfb.protocol.ProtocolSettings;
 import com.glavsoft.viewer.swing.ParametersHandler;
@@ -41,6 +38,10 @@
 import java.net.Socket;
 import java.net.UnknownHostException;
 
+import jp.ac.u_ryukyu.treevnc.client.GetDataClient;
+import jp.ac.u_ryukyu.treevnc.client.GetHostClient;
+import jp.ac.u_ryukyu.treevnc.client.TextBoxClient;
+
 
 public class ConnectionManager implements Serializable {
 	/**
--- a/src/viewer_swing/java/com/glavsoft/viewer/ContainerManager.java	Tue Aug 21 14:02:05 2012 +0900
+++ b/src/viewer_swing/java/com/glavsoft/viewer/ContainerManager.java	Tue Aug 21 14:24:38 2012 +0900
@@ -24,7 +24,6 @@
 
 package com.glavsoft.viewer;
 
-import ac.ryukyu.treevnc.client.MyVncClient;
 
 import com.glavsoft.viewer.swing.Surface;
 import com.glavsoft.viewer.swing.UiSettings;
@@ -35,6 +34,8 @@
 import java.awt.event.*;
 import java.io.Serializable;
 
+import jp.ac.u_ryukyu.treevnc.client.MyVncClient;
+
 public class ContainerManager implements Serializable {
 	/**
 	 * 
--- a/src/viewer_swing/java/com/glavsoft/viewer/TreeConnectionManager.java	Tue Aug 21 14:02:05 2012 +0900
+++ b/src/viewer_swing/java/com/glavsoft/viewer/TreeConnectionManager.java	Tue Aug 21 14:24:38 2012 +0900
@@ -5,8 +5,9 @@
 import java.net.Socket;
 import java.net.UnknownHostException;
 
-import ac.ryukyu.treevnc.client.GetDataClient;
-import ac.ryukyu.treevnc.client.GetHostClient;
+import jp.ac.u_ryukyu.treevnc.client.GetDataClient;
+import jp.ac.u_ryukyu.treevnc.client.GetHostClient;
+
 
 import com.glavsoft.rfb.protocol.ProtocolSettings;
 import com.glavsoft.viewer.swing.ParametersHandler;