Mercurial > hg > Members > nobuyasu > tightVNCProxy
diff src/myVncProxy/MyRfbProto.java @ 128:fa2122e5c807
modify ProxyVncCanva
author | e085711 |
---|---|
date | Tue, 02 Aug 2011 20:15:01 +0900 |
parents | 97bb1436e34c |
children | acd88e63854b |
line wrap: on
line diff
--- a/src/myVncProxy/MyRfbProto.java Tue Aug 02 13:17:23 2011 +0900 +++ b/src/myVncProxy/MyRfbProto.java Tue Aug 02 20:15:01 2011 +0900 @@ -3,10 +3,12 @@ import java.awt.Graphics; import java.awt.Image; import java.awt.image.BufferedImage; +import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import java.io.BufferedReader; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; +import java.io.DataInputStream; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; @@ -48,9 +50,12 @@ private LinkedList<Socket> cliList; private LinkedList<Thread> sendThreads; boolean createBimgFlag; - + boolean sendFlag = true; ExecutorService executor; + // override viewer to VncProxyService from VncViewer + VncProxyService viewer; + byte[] pngBytes; private MulticastQueue<byte[]> multicastqueue = new MulticastQueue<byte[]>(); @@ -65,6 +70,11 @@ // executor = Executors.newSingleThreadExecutor(); } + MyRfbProto(String h, int p, VncProxyService v) throws IOException { + super(h, p); + viewer = v; + } + MyRfbProto(String h, int p) throws IOException { super(h, p); cliList = new LinkedList<Socket>(); @@ -74,7 +84,8 @@ // executor = Executors.newCachedThreadPool(); // executor = Executors.newSingleThreadExecutor(); } - + + // over write void writeVersionMsg() throws IOException { clientMajor = 3; @@ -103,9 +114,9 @@ acceptPort = port; } - // 5550を開けるが、開いてないなら+1のポートを開ける。 + // open port 5999 for to accept client. void selectPort() { - int i = 5955;// i = 5550; + int i = 5999;// i = 5550; while (true) { try { initServSock(i); @@ -317,6 +328,9 @@ case RfbProto.EncodingRaw: dataLen = rectW * rectH * 4 + 16; break; + case RfbProto.EncodingTight: + dataLen = 4000000; + break; case RfbProto.EncodingZRLE: int zLen = readU32(); dataLen = zLen + 20; @@ -324,9 +338,9 @@ case RfbProto.EncodingRRE: case RfbProto.EncodingCoRRE: case RfbProto.EncodingHextile: + dataLen = rectW * rectH * 4 + 16; + break; case RfbProto.EncodingZlib: - case RfbProto.EncodingTight: - // dataLen <= EncodingRaw default: dataLen = rectW * rectH * 4 + 16; break; @@ -334,7 +348,7 @@ System.out.println("dataLen = "+dataLen); is.reset(); is.mark(dataLen); - + } @@ -477,8 +491,8 @@ System.out.println("rectW * rectH = " + rectW * rectH); switch (encoding) { case RfbProto.EncodingRaw: - System.out.println("rectW * rectH * 4 + 16 =" + rectW * rectH * 4 - + 16); + int dataLen = rectW * rectH * 4 + 16; + System.out.println("rectW * rectH * 4 + 16 = " + (rectW * rectH * 4 + 16)); break; default: } @@ -520,14 +534,58 @@ changeStatusFlag(); } } + void require() throws IOException { + sendFlag = false; + System.out.println("setEncodingRaw()"); + setEncodingRaw(); + writeFramebufferUpdateRequest(0, 0, + 16, 16, false); + System.out.println("setEncodingZRLE()"); + setEncodingZRLE(); + System.out.println("writeFramebufferUpdateRequest"); + writeFramebufferUpdateRequest(0, 0, + framebufferWidth, framebufferHeight, false); + } + + void setEncodingRaw() throws IOException{ + byte[] b = new byte[4 + 4]; + + b[0] = (byte) SetEncodings; + b[2] = (byte) ((1 >> 8) & 0xff); + b[3] = (byte) (1 & 0xff); + + b[4] = (byte)0; + b[5] = (byte)0; + b[6] = (byte)0; + b[7] = (byte)0; + + os.write(b); + + } + + void setEncodingZRLE() throws IOException{ + byte[] b = new byte[4 + 4]; + + b[0] = (byte) SetEncodings; + b[2] = (byte) ((1 >> 8) & 0xff); + b[3] = (byte) (1 & 0xff); + + b[4] = (byte)0; + b[5] = (byte)0; + b[6] = (byte)0; + b[7] = (byte)16; + + os.write(b); + + } - void newClient(AcceptThread acceptThread, final Socket newCli, final OutputStream os, final InputStream is) throws IOException { // createBimgFlag = true; // rfb.addSockTmp(newCli); // addSock(newCli); final Client<byte[]> c = multicastqueue.newClient(); + require(); Runnable sender = new Runnable() { public void run() { try { @@ -571,7 +629,10 @@ case 's': break; default: - startSpeedCheck(); +// startSpeedCheck(); + writeFramebufferUpdateRequest(0, 0, framebufferWidth, + framebufferHeight, false); + break; } } @@ -584,6 +645,30 @@ new Thread(stdin).start(); } + void requireFramebuffer() { + Runnable stdin = new Runnable() { + public void run() { + int c; + try { + while ((c = System.in.read()) != -1) { + sendFlag = false; + switch (c) { + default: + System.out.println("writeFramebufferUpdateRequest()"); + writeFramebufferUpdateRequest(0, 0, + framebufferWidth, framebufferHeight, false); + break; + } + } + } catch (IOException e) { + e.printStackTrace(); + } + } + }; + + new Thread(stdin).start(); + } + }