# HG changeset patch # User Shinji KONO # Date 1312454098 -32400 # Node ID e166c3cad2b80ac1a0624afc3571e85fc3fd08d6 # Parent b649584c97121603f9caec239575f080223c5cb8 new Defleter is working with fixed TightVNC clients diff -r b649584c9712 -r e166c3cad2b8 src/myVncProxy/CreateThread.java --- a/src/myVncProxy/CreateThread.java Thu Aug 04 16:11:41 2011 +0900 +++ b/src/myVncProxy/CreateThread.java Thu Aug 04 19:34:58 2011 +0900 @@ -22,20 +22,13 @@ public void run() { while (true) { - try { echoServer = new ServerSocket(9999); - } - catch (IOException e) { - System.out.println(e); - } - try { Socket clientSocket = echoServer.accept(); BufferedReader is = new BufferedReader(new InputStreamReader(clientSocket.getInputStream())); PrintStream os = new PrintStream(clientSocket.getOutputStream()); acceptClient.gethost(is,os); } catch (IOException e){ - e.printStackTrace(); System.out.println(e); } try { diff -r b649584c9712 -r e166c3cad2b8 src/myVncProxy/MyRfbProto.java --- a/src/myVncProxy/MyRfbProto.java Thu Aug 04 16:11:41 2011 +0900 +++ b/src/myVncProxy/MyRfbProto.java Thu Aug 04 19:34:58 2011 +0900 @@ -67,6 +67,7 @@ private MulticastQueue> multicastqueue = new MulticastQueue>(); private int clients = 0; private Inflater inflater = new Inflater(); + private Deflater deflater = new Deflater(); public MyRfbProto() throws IOException { @@ -507,7 +508,8 @@ while(inputIndex < inputs.size() ) { ByteBuffer b1 = inputs.get(inputIndex++); deflater.setInput(b1.array(),b1.position(),b1.remaining()); - if (inputIndex==inputs.size()) deflater.finish(); + if (inputIndex==inputs.size()) + deflater.finish(); do { int len1 = deflater.deflate(c1.array(),c1.position(),c1.remaining()); if (len1>0) { @@ -537,13 +539,15 @@ *@return number of total bytes * @throws IOException */ - public int unzip(Inflater inflater, LinkedList inputs, int inputIndex, LinkedList outputs) + public int unzip(Inflater inflater, LinkedList inputs, int inputIndex, LinkedList outputs,int bufSize) throws DataFormatException { int len=0; - ByteBuffer buf = ByteBuffer.allocate(INFLATE_BUFSIZE); + ByteBuffer buf = ByteBuffer.allocate(bufSize); while (inputIndex < inputs.size()) { ByteBuffer input = inputs.get(inputIndex++); inflater.setInput(input.array(),input.position(),input.limit()); +// if (inputIndex==inputs.size()) if inflater/deflater has symmetry, we need this +// inflater.end(); but this won't work do { int len0 = inflater.inflate(buf.array(),buf.position(),buf.remaining()); if (len0>0) { @@ -552,7 +556,7 @@ if (buf.remaining()==0) { buf.flip(); outputs.addLast(buf); - buf = ByteBuffer.allocate(INFLATE_BUFSIZE); + buf = ByteBuffer.allocate(bufSize); } } } while (!inflater.needsInput()); @@ -578,12 +582,14 @@ readFully(inputData.array(),0,inputData.capacity()); inputData.limit(dataLen-20); LinkedListinputs = new LinkedList(); inputs.add(inputData); + // int length = rectW * rectH * (bitsPerPixel/8); if (clicomp) { - unzip(inflater, inputs, 0, bufs); + unzip(inflater, inputs, 0, bufs, INFLATE_BUFSIZE); } else { - Deflater nDeflater = new Deflater(); + Deflater nDeflater = false ? deflater : new Deflater(); LinkedList out = new LinkedList(); - unzip(inflater, inputs, 0 , out); + unzip(inflater, inputs, 0 , out, INFLATE_BUFSIZE); + dump32(inputs); int len2 = zip(nDeflater, out, 0, bufs); ByteBuffer blen = ByteBuffer.allocate(4); blen.putInt(len2); blen.flip(); bufs.addFirst(blen); @@ -635,10 +641,7 @@ } }; Runnable sender = new Runnable() { - - public void run() { - Deflater deflater = new Deflater(); try { /** @@ -673,20 +676,12 @@ outs = bufs; inputIndex = 0; } - while(inputIndex < outs.size()) { - ByteBuffer out= outs.get(inputIndex++); - os.write(out.array(),out.position(),out.limit()); - } + writeToClient(os,bufs,inputIndex); + continue; } - os.flush(); - continue; } os.write(header.array(),header.position(),header.limit()); - while(inputIndex < bufs.size()) { - ByteBuffer b = bufs.get(inputIndex++); - os.write(b.array(), b.position(), b.limit()); - } - os.flush(); + writeToClient(os, bufs, inputIndex); } } catch (IOException e) { try { @@ -696,6 +691,16 @@ /* if socket closed cliList.remove(newCli); */ } } + + public void writeToClient(final OutputStream os, + LinkedList bufs, int inputIndex) + throws IOException { + while(inputIndex < bufs.size()) { + ByteBuffer b = bufs.get(inputIndex++); + os.write(b.array(), b.position(), b.limit()); + } + os.flush(); + } }; clients++; new Thread(sender).start(); @@ -703,6 +708,22 @@ } + public void dump32(LinkedListbufs) { + int len =0; + for(ByteBuffer b: bufs) len += b.remaining(); + ByteBuffer top = bufs.getFirst(); + ByteBuffer end = bufs.getLast(); + System.err.println("length: "+len); + System.err.print("head 0: "); + for(int i = 0; i<16 && i < top.remaining(); i++) { + System.err.print(" "+ top.get(i)); + } + System.err.print("tail 0: "); + for(int i = 0; i<16 && i < end.remaining(); i++) { + System.err.print(" "+end.get(i)); + } + System.err.println(); + } @Test public void test1() { @@ -721,14 +742,14 @@ Deflater deflater = new Deflater(); zip(deflater,in,0,out); // LinkedList out3 = clone(out); zipped result is depend on deflator's state - unzip(inflater, out, 0,out2); - // inflater.reset(); + unzip(inflater, out, 0,out2, INFLATE_BUFSIZE); + inflater.reset(); equalByteBuffers(in1, out2); LinkedList out4 = new LinkedList(); deflater = new Deflater(); zip(deflater,out2,0,out4); LinkedList out5 = new LinkedList(); - unzip(inflater,out4,0, out5); + unzip(inflater,out4,0, out5, INFLATE_BUFSIZE); int len = equalByteBuffers(in1,out5); System.out.println("Test Ok. "+len);