diff src/myVncProxy/MyRfbProto.java @ 75:6e703f1000e7

merge
author Yu Taninari <e085734@ie.u-ryukyu.ac.jp>
date Thu, 28 Jul 2011 17:52:48 +0900 (2011-07-28)
parents 6fc4272db7e2 f695bc56eb4f
children 347c153f74c7
line wrap: on
line diff
--- a/src/myVncProxy/MyRfbProto.java	Thu Jul 28 17:50:14 2011 +0900
+++ b/src/myVncProxy/MyRfbProto.java	Thu Jul 28 17:52:48 2011 +0900
@@ -24,8 +24,13 @@
 import java.io.OutputStream;
 
 class MyRfbProto extends RfbProto {
-
 	final static String versionMsg_3_998 = "RFB 003.998\n";
+	/**
+	 * CheckMillis is one of new msgType for RFB 3.998. 
+	 */
+	final static int CheckMillis = 4;
+	boolean printStatusFlag = false;
+	long startCheckTime;
 
 	private int messageType;
 	private int rectangles;
@@ -320,6 +325,34 @@
 		if (encoding == 16)
 			zLen = readU32();
 		reset();
+/*
+		int dataLen;
+		switch (encoding) {
+		case RfbProto.EncodingRaw:
+			dataLen = rectW * rectH * 4 + 16;
+			mark(dataLen);
+			break;
+		case RfbProto.EncodingCopyRect:
+			dataLen = 16 + 4;
+			mark(dataLen);
+			break;
+		case RfbProto.EncodingRRE:
+		case RfbProto.EncodingCoRRE:
+		case RfbProto.EncodingHextile:
+			
+		case RfbProto.EncodingZlib:
+		case RfbProto.EncodingTight:
+		case RfbProto.EncodingZRLE:
+			dataLen = zLen + 20;
+			mark(dataLen);
+			break;
+		default:
+			dataLen = 1000000;
+			mark(dataLen);
+		}
+	
+*/	
+	
 	}
 
 	int checkAndMark() throws IOException {
@@ -329,6 +362,15 @@
 			dataLen = rectW * rectH * 4 + 16;
 			mark(dataLen);
 			break;
+		case RfbProto.EncodingCopyRect:
+			dataLen = 16 + 4;
+			mark(dataLen);
+			break;
+		case RfbProto.EncodingRRE:
+		case RfbProto.EncodingCoRRE:
+		case RfbProto.EncodingHextile:
+		case RfbProto.EncodingZlib:
+		case RfbProto.EncodingTight:
 		case RfbProto.EncodingZRLE:
 			dataLen = zLen + 20;
 			mark(dataLen);
@@ -339,11 +381,13 @@
 		}
 		return dataLen;
 	}
+	
 	void readSendData(int dataLen) throws IOException {
 		byte buffer[] = new byte[dataLen];
 		readFully(buffer);
 		multicastqueue.put(buffer);
 		reset();
+
 /*
 		for (Socket cli : cliList) {
 			try {
@@ -414,12 +458,12 @@
 		BufferedImage bimg = ImageIO.read(new ByteArrayInputStream(pngBytes));
 		return bimg;
 	}
-
+/*
 	void readPngData() throws IOException {
 		pngBytes = new byte[is.available()];
 		readFully(pngBytes);
 	}
-
+*/
 	void printFramebufferUpdate() {
 
 		System.out.println("messageType=" + messageType);
@@ -433,6 +477,44 @@
 		default:
 		}
 	}
+	
+	void readCheckMillis() throws IOException {
+		byte[] b = new byte[2];
+		readFully(b);
+	}
+	
+	void startCheckMillis() {
+		byte[] b = new byte[2];
+		b[0] = (byte) CheckMillis;
+		b[1] = (byte) 0;
+		startCheckTime = System.currentTimeMillis();
+		System.out.println("startChckTime = "+ startCheckTime);
+		multicastqueue.put(b);
+	}
+
+	void endCheckMills() {
+		long accTime = System.currentTimeMillis();
+		long time = accTime - startCheckTime;
+		System.out.println("checkMillis: " + time);
+	}
+
+	void printStatus() {
+		System.out.println();
+	}
+
+	synchronized void changeStatusFlag() {
+		printStatusFlag = true;
+	}
+
+	void printMills() {
+		if(printStatusFlag) {
+
+			changeStatusFlag();
+		} else {
+			changeStatusFlag();
+		}
+	}
+	
 
 	void newClient(AcceptThread acceptThread, final Socket newCli,
 			final OutputStream os, final InputStream is) throws IOException {
@@ -443,7 +525,9 @@
 		Runnable sender = new Runnable() {
 			public void run() {
 				try {
-					// 初期接続確立の部分
+					/**
+					 *  initial connection of RFB protocol
+					 */
 					sendRfbVersion(os);
 					readVersionMsg(is);
 					sendSecurityType(os);
@@ -457,8 +541,9 @@
 						os.write(b, 0, b.length);
 					}
 				} catch (IOException e) {
-					//接続が切れた処理
-					//lockしないと駄目
+					/**
+					 * if socket closed
+					 */
 					//					cliList.remove(newCli);
 				}
 
@@ -468,4 +553,31 @@
 		new Thread(sender).start();
 
 	}
+
+	void sendCheckMillis() {
+		
+		Runnable stdin = new Runnable() {
+			public void run() {
+				int c;
+				try {
+					while( (c = System.in.read()) != -1 ) {
+						switch(c) {
+							case 's':
+								break;
+							default:
+								startCheckMillis();
+								break;
+						}
+					}
+				}catch(IOException e){
+					System.out.println(e);
+				}
+			}
+		};
+		
+		new Thread(stdin).start();
+	}
+
 }
+
+