changeset 1:75b54fd9e73a

add new package treevnc
author Yu Taninari <you@cr.ie.u-ryukyu.ac.jp>
date Tue, 03 Jul 2012 13:34:43 +0900
parents 4689cc86d6cb
children dca3bd61b830
files src/main/java/ac/ryukyu/treevnc/InterfaceForViewer.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/MyVncClient.java src/main/java/ac/ryukyu/treevnc/client/TextBoxClient.java src/main/java/ac/ryukyu/treevnc/client/WaitReply.java
diffstat 7 files changed, 1027 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/java/ac/ryukyu/treevnc/InterfaceForViewer.java	Tue Jul 03 13:34:43 2012 +0900
@@ -0,0 +1,29 @@
+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);
+	
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/java/ac/ryukyu/treevnc/client/EchoClient.java	Tue Jul 03 13:34:43 2012 +0900
@@ -0,0 +1,289 @@
+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 = client;
+		this.name = name;
+	}
+
+	public EchoClient(String name, MyVncClient client, int echoPort) {
+		this.client = client;
+		this.name = name;
+		this.echoPort = echoPort;
+	}
+
+	public EchoClient(EchoClient echo, MyVncClient client) {
+		this.client = 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/ac/ryukyu/treevnc/client/GetDataClient.java	Tue Jul 03 13:34:43 2012 +0900
@@ -0,0 +1,81 @@
+package ac.ryukyu.treevnc.client;
+
+import java.io.BufferedReader;
+//import java.io.ByteArrayInputStream;
+//import java.io.DataInputStream;
+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;
+	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();
+				if(line!=null){
+					text.checkBox(line);
+				}
+				text.setButton();
+				text.visible();
+			}
+		} catch (IOException e) {
+			e.printStackTrace();
+		}
+	}
+	
+	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/ac/ryukyu/treevnc/client/GetHostClient.java	Tue Jul 03 13:34:43 2012 +0900
@@ -0,0 +1,57 @@
+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;
+	}
+
+	void createSocket() {
+		try {
+			mAddr = InetAddress.getByName(MCASTADDR);
+			soc = new MulticastSocket();
+			soc.setTimeToLive(1);
+		} catch (IOException e) {
+			e.printStackTrace();
+		}
+	}
+
+	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/ac/ryukyu/treevnc/client/MyVncClient.java	Tue Jul 03 13:34:43 2012 +0900
@@ -0,0 +1,313 @@
+package ac.ryukyu.treevnc.client;
+
+import java.awt.Image;
+import java.awt.Insets;
+import java.awt.event.WindowEvent;
+import java.awt.event.WindowListener;
+import java.io.IOException;
+import java.net.Socket;
+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.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.Viewer.PasswordChooser;
+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;
+
+import ac.ryukyu.treevnc.InterfaceForViewer;
+
+public class MyVncClient extends Viewer implements InterfaceForViewer,
+		java.lang.Runnable, WindowListener {
+
+	/**
+	 * 
+	 */
+	private static final long serialVersionUID = 1L;
+	private boolean inAnApplet = true;
+	private boolean inSeparateFrame = false;
+	private Socket clientSocket = null;
+	private String parent, treenum;
+	private String leaderflag;
+	// private boolean runflag = false;
+	private boolean first = true;
+
+	private EchoClient echoValue;
+	private int echoPort;
+	private String pHost;
+	private TextBoxClient getHost;
+	private GetDataClient getBcast;
+	private Thread runBcast;
+	private GetHostClient bCast;
+	boolean isClient = false;
+	public static final int DEFAULT_PORT = 5900;
+	public static Logger logger = Logger.getLogger("com.glavsoft");
+	private static final Insets BUTTONS_MARGIN = new Insets(2, 2, 2, 2);
+	private boolean isZoomToFitSelected;
+	private boolean forceReconnection;
+	private String reconnectionReason;
+	private ConnectionParams connectionParams;
+	private final ProtocolSettings settings;
+	private final UiSettings uiSettings;
+	
+	
+	public MyVncClient() {
+		connectionParams = new ParametersHandler.ConnectionParams();
+		settings = ProtocolSettings.getDefaultSettings();
+		uiSettings = new UiSettings();
+	}
+	
+	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) {
+		MyVncClient v = 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
+		if (mainArgs.length != 0) {
+			for (int i = 0; i < argv.length; i++) {
+				if ("-c".equals(argv[i])) {
+					// later write
+				}
+			}
+		} else {
+			//getHostData();
+		}
+		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);
+		SwingUtilities.invokeLater(myClient);
+	}
+	
+	private void getHostData() {
+		bCast = new GetHostClient("who");
+		bCast.createSocket();
+		bCast.sendData();
+		getBcast = new GetDataClient();
+		runBcast = new Thread(getBcast);
+		runBcast.start();
+		getBcast.setStopFlag(true);
+		connectionParams.hostName = getBcast.text.getAddress();
+		if("notFound".equals(pHost)) {
+			getHost = new TextBoxClient();
+			getHost.ipRegister();
+			connectionParams.hostName = getHost.getAddressOption();
+			connectionParams.portNumber = Integer.parseInt(getHost.getPortOption());
+		} else {
+			connectionParams.portNumber = Integer.parseInt(getBcast.text.getPort());
+		}
+	}
+
+	@Override
+	public void run() {
+		ConnectionManager connectionManager = new ConnectionManager(this, isApplet);
+		if (forceReconnection) {
+			connectionManager.showReconnectDialog("Connection lost", reconnectionReason);
+			forceReconnection = false;
+		}
+		tryAgain = true;
+		while (tryAgain) {
+			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();
+
+                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 setEchoValue(EchoClient value) {
+		// TODO Auto-generated method stub
+
+	}
+
+	@Override
+	public String readParameter(String name, boolean required) {
+		// TODO Auto-generated method stub
+		return null;
+	}
+
+	@Override
+	public void getParentName() {
+		// TODO Auto-generated method stub
+
+	}
+
+	@Override
+	public void disconnect() {
+		// TODO Auto-generated method stub
+
+	}
+
+	@Override
+	public void fatalError(String str) {
+		// TODO Auto-generated method stub
+
+	}
+
+	@Override
+	public void fatalError(String str, Exception e) {
+		// TODO Auto-generated method stub
+
+	}
+
+	@Override
+	public void destroy() {
+		// TODO Auto-generated method stub
+
+	}
+
+	@Override
+	public void enableInput(boolean enable) {
+		// TODO Auto-generated method stub
+
+	}
+
+	@Override
+	public void setClientSocket(Socket sock) {
+		// TODO Auto-generated method stub
+
+	}
+
+	@Override
+	public void close() {
+		// TODO Auto-generated method stub
+
+	}
+
+	@Override
+	public Image getScreenImage() {
+		// TODO Auto-generated method stub
+		return null;
+	}
+
+	@Override
+	public void writeScreenData(byte[] b, String imageFormat) {
+		// TODO Auto-generated method stub
+
+	}
+
+	@Override
+	public void windowActivated(WindowEvent e) {
+		// TODO Auto-generated method stub
+
+	}
+
+	@Override
+	public void windowClosed(WindowEvent e) {
+		// TODO Auto-generated method stub
+
+	}
+
+	@Override
+	public void windowClosing(WindowEvent e) {
+		// TODO Auto-generated method stub
+
+	}
+
+	@Override
+	public void windowDeactivated(WindowEvent e) {
+		// TODO Auto-generated method stub
+
+	}
+
+	@Override
+	public void windowDeiconified(WindowEvent e) {
+		// TODO Auto-generated method stub
+
+	}
+
+	@Override
+	public void windowIconified(WindowEvent e) {
+		// TODO Auto-generated method stub
+
+	}
+
+	@Override
+	public void windowOpened(WindowEvent e) {
+		// TODO Auto-generated method stub
+
+	}
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/java/ac/ryukyu/treevnc/client/TextBoxClient.java	Tue Jul 03 13:34:43 2012 +0900
@@ -0,0 +1,204 @@
+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();
+		visible();
+	}
+
+	private void setSize() {
+		Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
+		width = (d.getWidth() / 2);
+		height = (d.getHeight() / 2);
+	}
+
+	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);
+	}
+
+	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) {
+		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/ac/ryukyu/treevnc/client/WaitReply.java	Tue Jul 03 13:34:43 2012 +0900
@@ -0,0 +1,54 @@
+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);
+			}
+		}
+	}
+}