changeset 72:ec66d1d4dca0

modify MyVncClient.connectAndAuthenticate()
author e085711
date Mon, 29 Aug 2011 03:14:53 +0900
parents f6cb1edc2036
children 83acdeca0539
files src/myVncClient/EchoClient.java src/myVncClient/MyRfbProto.java src/myVncClient/MyVncClient.java src/myVncClient/RfbProto.java
diffstat 4 files changed, 109 insertions(+), 48 deletions(-) [+]
line wrap: on
line diff
--- a/src/myVncClient/EchoClient.java	Mon Aug 29 01:39:15 2011 +0900
+++ b/src/myVncClient/EchoClient.java	Mon Aug 29 03:14:53 2011 +0900
@@ -72,8 +72,7 @@
 		} catch (UnknownHostException e) {
 			System.err.println("Don't know about host: localhost");
 		} catch (IOException e) {
-			System.out.println("接続に失敗しました");
-			System.err.println("Couldn't get I/O for the connection to: localhost");
+			System.out.println(name + " への接続に失敗しました");
 			System.exit(0);
 		}
 	}
--- a/src/myVncClient/MyRfbProto.java	Mon Aug 29 01:39:15 2011 +0900
+++ b/src/myVncClient/MyRfbProto.java	Mon Aug 29 03:14:53 2011 +0900
@@ -60,6 +60,8 @@
 	private LinkedList<Socket> cliListTmp;
 	private LinkedList<Socket> cliList;
 	boolean createBimgFlag;
+	//override
+	InterfaceForViewer viewer;
 
 	ExecutorService executor;
 
@@ -84,7 +86,7 @@
 		// executor = Executors.newCachedThreadPool();
 		// executor = Executors.newSingleThreadExecutor();
 	}
-
+	
 	MyRfbProto(String h, int p) throws IOException {
 		super(h, p);
 		cliList = new LinkedList<Socket>();
@@ -94,6 +96,37 @@
 		// executor = Executors.newCachedThreadPool();
 		// executor = Executors.newSingleThreadExecutor();
 	}
+
+	
+	void readVersionMsg() throws Exception {
+
+		byte[] b = new byte[12];
+
+		readFully(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 Exception("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 Exception(
+					"RFB server does not support protocol version 3");
+		}
+
+		if (serverMinor == 998) {
+			
+		}
+		
+	}
+	
 	void changeParent(String h, int p) throws IOException {
 		host = h;
 		port = p;
--- a/src/myVncClient/MyVncClient.java	Mon Aug 29 01:39:15 2011 +0900
+++ b/src/myVncClient/MyVncClient.java	Mon Aug 29 03:14:53 2011 +0900
@@ -20,6 +20,8 @@
 	private String leaderflag;
 	boolean runflag = false;
 	boolean first = true;
+	
+	EchoClient echovalue;
 	//
 	// main() is called when run as a java program from the command line.
 	// It simply runs the applet inside a newly-created frame.
@@ -27,6 +29,7 @@
 
 	public static void main(String[] argv) {
 		MyVncClient v = new MyVncClient();
+		v.echovalue = null;
 		v.runClient(argv);
 	}
 
@@ -46,8 +49,9 @@
 
 	public void init(EchoClient value) {
 
-		// readParameters();
+//		getParentname(value);
 		readParameters(value);
+//		readParameters();
 
 		refApplet = this;
 
@@ -92,6 +96,7 @@
 	}
 
 	public void run() {
+
 		gridbag = new GridBagLayout();
 		vncContainer.setLayout(gridbag);
 
@@ -346,6 +351,9 @@
 
 		showConnectionStatus("Connecting to " + host + ", port " + port + "...");
 
+		host = "localhost";
+		port = 5999;
+		
 		rfb = new MyRfbProto(host, port, this);
 		showConnectionStatus("Connected to server");
 
@@ -353,6 +361,16 @@
 		showConnectionStatus("RFB server supports protocol version "
 				+ rfb.serverMajor + "." + rfb.serverMinor);
 
+		if(rfb.serverMinor == 998) {
+			String h = host;
+			getParentname(echovalue);
+			if(h.equals(host)) {
+				rfb.changeParent(host, port);
+				rfb.readVersionMsg();
+			}
+		}
+		
+		
 		rfb.writeVersionMsg();
 		showConnectionStatus("Using RFB protocol version " + rfb.clientMajor
 				+ "." + rfb.clientMinor);
@@ -767,50 +785,7 @@
 		 * 
 		 * port = readIntParameter("PORT", 5550);
 		 */
-		if (value == null) {
-
-			if (clientSocket == null) {
-				String pHost;
-				if (mainArgs.length > 0)
-					pHost = mainArgs[0];
-				else
-					pHost = "cls080.ie.u-ryukyu.ac.jp";
-				echo = new EchoClient(pHost, this);
-				echo.openport();
-
-				value = echo.hostn("1");
-			} else {
-				echo = new EchoClient();
-				value = echo.Interruption(clientSocket);
-			}
-		}
-		// proxyからの返信で接続先を決定する
-		host = value.responseLine;
-		parent = value.parent;
-		if (value.treenum != null) {
-			treenum = value.treenum;
-		} else {
-			treenum = echo.treenum;
-		}
-		if (value.leaderflag != null) {
-			leaderflag = value.leaderflag;
-		} else {
-			leaderflag = echo.leaderflag;
-		}
-		System.out.println("Parent =" + parent);
-		System.out.println("mynumber =" + treenum);
-		System.out.println("connect host =" + host);
-		System.out.println("leaderflag(boolean) = " + leaderflag);
-
-		echo = value;
-
-		if (host == null) {
-			host = getCodeBase().getHost();
-			if (host.equals("")) {
-				fatalError("HOST parameter not specified");
-			}
-		}
-		port = 5999;
+		
 		// Read "ENCPASSWORD" or "PASSWORD" parameter if specified.
 		readPasswordParameters();
 
@@ -1125,6 +1100,55 @@
 
 	public void windowDeiconified(WindowEvent evt) {
 	}
+	
+	void getParentname(EchoClient value) {
+	if (value == null) {
+
+		if (clientSocket == null) {
+			String pHost;
+			if (mainArgs.length > 0)
+				pHost = mainArgs[0];
+			else
+				pHost = "cls080.ie.u-ryukyu.ac.jp";
+			echo = new EchoClient(pHost, this);
+			echo.openport();
+
+			value = echo.hostn("1");
+		} else {
+			echo = new EchoClient();
+			value = echo.Interruption(clientSocket);
+		}
+	}
+	// proxyからの返信で接続先を決定する
+	host = value.responseLine;
+	parent = value.parent;
+	if (value.treenum != null) {
+		treenum = value.treenum;
+	} else {
+		treenum = echo.treenum;
+	}
+	if (value.leaderflag != null) {
+		leaderflag = value.leaderflag;
+	} else {
+		leaderflag = echo.leaderflag;
+	}
+	System.out.println("Parent =" + parent);
+	System.out.println("mynumber =" + treenum);
+	System.out.println("connect host =" + host);
+	System.out.println("leaderflag(boolean) = " + leaderflag);
+
+	echo = value;
+
+	if (host == null) {
+		host = getCodeBase().getHost();
+		if (host.equals("")) {
+			fatalError("HOST parameter not specified");
+		}
+	}
+	port = 5999;
+
+	
+	}	
 
 	public static void main(Socket _clientSocket) {
 		MyVncClient v = new MyVncClient();
@@ -1133,6 +1157,8 @@
 		v.inAnApplet = false;
 		v.inSeparateFrame = true;
 
+		v.echovalue = null;
+		
 		v.init(null);
 		v.start_threads();
 		v.start();
@@ -1143,6 +1169,8 @@
 		v.inAnApplet = false;
 		v.inSeparateFrame = true;
 
+		v.echovalue = value;
+		
 		v.init(value);
 		v.start_threads();
 		v.start();
--- a/src/myVncClient/RfbProto.java	Mon Aug 29 01:39:15 2011 +0900
+++ b/src/myVncClient/RfbProto.java	Mon Aug 29 03:14:53 2011 +0900
@@ -272,6 +272,7 @@
 			throw new Exception(
 					"RFB server does not support protocol version 3");
 		}
+
 	}
 
 	//