changeset 28:68f0bc9c4211

modify MyRfbProto.java and acceptThread.java
author e085711
date Wed, 06 Jul 2011 11:31:30 +0900
parents 53c831c3a513
children 750ecaa1e1b9
files src/myVncClient/MyRfbProto.java src/myVncClient/acceptThread.java
diffstat 2 files changed, 38 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/myVncClient/MyRfbProto.java	Thu Jun 23 07:59:55 2011 +0900
+++ b/src/myVncClient/MyRfbProto.java	Wed Jul 06 11:31:30 2011 +0900
@@ -68,7 +68,7 @@
 		executor = Executors.newSingleThreadExecutor();
 	}
 
-	// override
+	// over write
 	void writeVersionMsg() throws IOException {
 		clientMajor = 3;
 		if (serverMinor >= 9) {
@@ -192,6 +192,30 @@
 	void sendRfbVersion(OutputStream os) throws IOException{
 		os.write(versionMsg_3_998.getBytes());	
 	}
+	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);
@@ -199,6 +223,16 @@
 		// 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);
--- a/src/myVncClient/acceptThread.java	Thu Jun 23 07:59:55 2011 +0900
+++ b/src/myVncClient/acceptThread.java	Wed Jul 06 11:31:30 2011 +0900
@@ -19,7 +19,10 @@
 				OutputStream os = newCli.getOutputStream();
 				InputStream is = newCli.getInputStream();
 				rfb.sendRfbVersion(os);
+				rfb.readVersionMsg(is);
 				rfb.sendSecurityType(os);
+				rfb.readSecType(is);
+				rfb.sendSecResult(os);
 				rfb.readClientInit(is);
 				rfb.sendInitData(os);
 				rfb.createBimgFlag = true;