diff src/myVncProxy/MyRfbProto.java @ 27:13d4d3118cb8

create rfb.cliListTmp
author e085711
date Tue, 26 Apr 2011 14:48:48 +0900
parents 0aa0e0bd742c
children 2fd55d934ffa
line wrap: on
line diff
--- a/src/myVncProxy/MyRfbProto.java	Tue Apr 26 09:08:49 2011 +0900
+++ b/src/myVncProxy/MyRfbProto.java	Tue Apr 26 14:48:48 2011 +0900
@@ -26,22 +26,29 @@
 	private int rectW;
 	private int rectH;
 	private int encoding;
+	private int zLen;
 
 	private ServerSocket servSock;
 	private int acceptPort;
 	private byte initData[];
+	private LinkedList <Socket> cliListTmp;
 	private LinkedList <Socket> cliList;
+	boolean createBimgFlag;
 	
 	byte[] pngBytes;
 	
 	MyRfbProto(String h, int p, VncViewer v ) throws IOException {
 		super(h, p, v);
 		cliList = new LinkedList <Socket>();
+		cliListTmp = new LinkedList <Socket>();
+		createBimgFlag = false;
 	}
 
 	MyRfbProto(String h, int p) throws IOException {
 		super(h, p);
 		cliList = new LinkedList <Socket>();
+		cliListTmp = new LinkedList <Socket>();
+		createBimgFlag = false;
 	}
 
 	void initServSock(int port) throws IOException{
@@ -76,6 +83,9 @@
 	void addSock(Socket sock){
 		cliList.add(sock);
 	}
+	void addSockTmp(Socket sock){
+		cliListTmp.add(sock);
+	}
 	
 	void mark(int len) throws IOException {
 		is.mark(len);
@@ -140,8 +150,6 @@
 	}
 
 	void sendData(byte b[]){
-
-		
 		try{
 			for(Socket cli : cliList){
 				try{
@@ -154,7 +162,27 @@
 //		System.out.println("cliSize="+cliSize());
 		}catch(Exception e){
 		}
-	}	
+	}
+	
+	void sendPngImage(){
+		try{
+			for(Socket cli : cliListTmp){
+				try{
+					sendPngData(cli);
+					addSock(cli);
+				}catch(IOException e){
+					// if socket closed
+					cliListTmp.remove(cli);
+				}
+			}
+//		System.out.println("cliSize="+cliSize());
+		}catch(Exception e){
+		}
+		cliListTmp.clear();
+	}
+	
+	
+
 	boolean ready() throws IOException {
 		BufferedReader br = new BufferedReader(new InputStreamReader(is));
 		return br.ready();
@@ -176,7 +204,7 @@
 		sendData(buffer);
 	}
 	void regiFramebufferUpdate()throws IOException{
-		mark(16);
+		mark(20);
 		messageType = readU8();
 		skipBytes(1);
 		rectangles = readU16();
@@ -184,7 +212,9 @@
 		rectY = readU16();
 		rectW = readU16();
 		rectH = readU16();
-		encoding = readU32();	
+		encoding = readU32();
+		if(encoding == 16)
+			zLen = readU32();
 		reset();
 	}
 	void checkAndMark() throws IOException{
@@ -192,13 +222,16 @@
 		case RfbProto.EncodingRaw:
 			mark(rectW * rectH * 4 + 16);		
 			break;
+		case RfbProto.EncodingZRLE:
+			mark(zLen);
+			break;
 		default:
-			mark(1000000);
+			mark(1000000);//適当
 		}
 	}
 	BufferedImage createBufferedImage(Image img){
 		BufferedImage bimg = new BufferedImage(img.getWidth(null), img.getHeight(null), BufferedImage.TYPE_INT_RGB  );
-		
+
 		Graphics g = bimg.getGraphics();
 		g.drawImage(img, 0, 0, null);
 		g.dispose();
@@ -224,13 +257,6 @@
 	}
 
 	void sendPngData(Socket sock)throws IOException{
-		System.out.println("pngBytes.length="+pngBytes.length);
-
-//		ByteBuffer length = ByteBuffer.allocate(4);
-//		length.putInt(pngBytes.length);
-
-//		byte b = 1;
-//		sock.getOutputStream().write(b);
 		byte[] dataLength = castIntByte(pngBytes.length);
 		sock.getOutputStream().write(dataLength);
 		sock.getOutputStream().write(pngBytes);