changeset 27:53c831c3a513

add RFB 003.998
author e085711
date Thu, 23 Jun 2011 07:59:55 +0900
parents 072306e78a95
children 68f0bc9c4211
files src/myVncClient/MyRfbProto.java src/myVncClient/MyVncClient.java src/myVncClient/acceptThread.java
diffstat 3 files changed, 74 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/src/myVncClient/MyRfbProto.java	Thu Jun 23 04:48:16 2011 +0900
+++ b/src/myVncClient/MyRfbProto.java	Thu Jun 23 07:59:55 2011 +0900
@@ -7,6 +7,7 @@
 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;
@@ -21,6 +22,9 @@
 
 class MyRfbProto extends RfbProto {
 
+	final static String versionMsg_3_998 = "RFB 003.998\n";
+	
+	
 	private int messageType;
 	private int rectangles;
 	private int rectX;
@@ -64,6 +68,31 @@
 		executor = Executors.newSingleThreadExecutor();
 	}
 
+	// override
+	void writeVersionMsg() throws IOException {
+		clientMajor = 3;
+		if (serverMinor >= 9) {
+		clientMinor = 9;
+		os.write(versionMsg_3_998.getBytes());
+		} else if (serverMajor > 3 || serverMinor >= 8) {
+			clientMinor = 8;
+			os.write(versionMsg_3_8.getBytes());
+		} else if (serverMinor >= 9) {
+			clientMinor = 9;
+			os.write(versionMsg_3_998.getBytes());
+		} else if (serverMinor >= 7) {
+			clientMinor = 7;
+			os.write(versionMsg_3_7.getBytes());
+		} else {
+			clientMinor = 3;
+			os.write(versionMsg_3_3.getBytes());
+		}
+		protocolTightVNC = false;
+		initCapabilities();
+	}
+
+
+	
 	void initServSock(int port) throws IOException{
 		servSock = new ServerSocket(port);
 		acceptPort = port;
@@ -160,8 +189,23 @@
 		inNormalProtocol = true;
 	}
 
-	void sendInitData(Socket sock) throws IOException{
-			sock.getOutputStream().write(initData);
+	void sendRfbVersion(OutputStream os) throws IOException{
+		os.write(versionMsg_3_998.getBytes());	
+	}
+	void sendSecurityType(OutputStream os) throws IOException {
+		// number-of-security-types
+		os.write(1);
+		// security-types 
+		// 1:None
+		os.write(1);
+	}
+	void readClientInit(InputStream in) throws IOException {
+		byte[] b = new byte[0];
+		in.read(b);
+	}
+	
+	void sendInitData(OutputStream os) throws IOException{
+			os.write(initData);
 	}
 
 	void sendData(byte b[]){
@@ -310,8 +354,7 @@
 		return bimg;
 	}
 	void readPngData()throws IOException{
-		int length = readU32();
-		pngBytes = new byte[length];
+		pngBytes = new byte[is.available()];
 		readFully(pngBytes);
 	}
 	void printFramebufferUpdate(){
@@ -327,3 +370,5 @@
 		}
 	}
 }
+
+
--- a/src/myVncClient/MyVncClient.java	Thu Jun 23 04:48:16 2011 +0900
+++ b/src/myVncClient/MyVncClient.java	Thu Jun 23 07:59:55 2011 +0900
@@ -66,12 +66,13 @@
 		if (inSeparateFrame)
 			vncFrame.addWindowListener(this);
 
+
+		
 		rfbThread = new Thread(this);
 		rfbThread.start();
 		accThread = new Thread(new acceptThread(rfb)); 
 		accThread.start();
 		
-		
 	}
 
 	public void update(Graphics g) {
@@ -97,14 +98,16 @@
 		}
 
 /*****************************************************************************/
-		vncFrame.pack();
-		vncFrame.setVisible(true);
+//		vncFrame.pack();
+//		vncFrame.setVisible(true);
 		try {
+//			rfb = new MyRfbProto(host, port, this);
+//			rfb.readServerInit();
 
 
-			rfb = new MyRfbProto(host, port, this);
-			rfb.readServerInit();
-			
+			connectAndAuthenticate();
+			doProtocolInitialisation();
+
 			createCanvas(0, 0);
 
 			// read & draw Png Data
@@ -115,6 +118,8 @@
 		} catch (IOException e) {
 			System.out.println("Socket error");
 			System.exit(0);
+		} catch (Exception e){
+			
 		}
 
 		gbc.weightx = 1.0;
@@ -261,6 +266,7 @@
 	//
 
 	void connectAndAuthenticate() throws Exception {
+
 		showConnectionStatus("Initializing...");
 		if (inSeparateFrame) {
 			vncFrame.pack();
--- a/src/myVncClient/acceptThread.java	Thu Jun 23 04:48:16 2011 +0900
+++ b/src/myVncClient/acceptThread.java	Thu Jun 23 07:59:55 2011 +0900
@@ -1,27 +1,34 @@
 package myVncClient;
 import java.net.Socket;
 import java.io.IOException;
-
+import java.io.InputStream;
+import java.io.OutputStream;
 
 public class acceptThread implements Runnable {
 	MyRfbProto rfb;
+	byte[] imageBytes;
 
-	acceptThread(MyRfbProto _rfb) {
+	acceptThread(MyRfbProto _rfb ) {
 		rfb = _rfb;
 	}
-
 	public void run() {
 		rfb.selectPort();
 		while (true) {
 			try {
 				Socket newCli = rfb.accept();
-				rfb.sendInitData(newCli);
+				OutputStream os = newCli.getOutputStream();
+				InputStream is = newCli.getInputStream();
+				rfb.sendRfbVersion(os);
+				rfb.sendSecurityType(os);
+				rfb.readClientInit(is);
+				rfb.sendInitData(os);
 				rfb.createBimgFlag = true;
-				rfb.addSockTmp(newCli);
+//				rfb.addSockTmp(newCli);
+				rfb.addSock(newCli);
 			} catch (IOException e) {
 				e.printStackTrace();
 				System.out.println(e);
 			}
 		}
 	}
-}
\ No newline at end of file
+}