Mercurial > hg > Members > you > BroadCastTreeVNC
changeset 3:3b341997141a
broadcast socket trying
author | one |
---|---|
date | Mon, 23 Apr 2012 20:18:23 +0900 |
parents | 5d72f4c7371d |
children | 657c691c2936 |
files | src/treeVnc/MyRfbProtoProxy.java src/treeVnc/MyVncClient.java src/treeVnc/ProxyVncCanvas.java src/treeVnc/RfbProto.java src/treeVnc/TextBoxClient.java src/treeVnc/VncCanvas.java |
diffstat | 6 files changed, 398 insertions(+), 197 deletions(-) [+] |
line wrap: on
line diff
--- a/src/treeVnc/MyRfbProtoProxy.java Sat Apr 07 14:55:34 2012 +0900 +++ b/src/treeVnc/MyRfbProtoProxy.java Mon Apr 23 20:18:23 2012 +0900 @@ -36,6 +36,7 @@ import java.io.OutputStream; public class MyRfbProtoProxy extends RfbProto implements MyRfbProto { + int test = 0; final static String versionMsg_3_855 = "RFB 003.855\n"; /** * CheckMillis is one of new msgType for RFB 3.855. @@ -425,13 +426,10 @@ rectY = readU16(); // 6 rectW = readU16(); // 8 rectH = readU16(); // 10 -/* - readU16(); // 2 - readU16(); // 4 - readU16(); // 6 - readU16(); // 8 - readU16(); // 10 -*/ + /* + * readU16(); // 2 readU16(); // 4 readU16(); // 6 readU16(); // 8 + * readU16(); // 10 + */ encoding = readU32(); // 12 // System.out.println("encoding = "+encoding); @@ -440,7 +438,7 @@ zLen = readU32(); else zLen = 0; - //System.out.println(zLen); + // System.out.println(zLen); is.reset(); } @@ -485,7 +483,7 @@ void sendDataToClient() throws Exception { regiFramebufferUpdate(); - //printFramebufferUpdate(); + // printFramebufferUpdate(); int dataLen = checkAndMark(); readSendData(dataLen); } @@ -548,12 +546,12 @@ * System.out.println("rectX = "+rectX+": rectY = "+rectY); * System.out.println("rectW = "+rectW+": rectH = "+rectH); */ - - System.out.println("messageType=" + messageType); - System.out.println("rectangles=" + rectangles); - System.out.println("encoding=" + encoding); - System.out.println("rectX = "+rectX+": rectY = "+rectY); - System.out.println("rectW = "+rectW+": rectH = "+rectH); + + System.out.println("messageType=" + messageType); + System.out.println("rectangles=" + rectangles); + System.out.println("encoding=" + encoding); + System.out.println("rectX = " + rectX + ": rectY = " + rectY); + System.out.println("rectW = " + rectW + ": rectH = " + rectH); switch (encoding) { case RfbProto.EncodingRaw: @@ -773,21 +771,20 @@ readFully(len.array(), 0, 4); len.limit(4); ByteBuffer inputData = ByteBuffer.allocate(dataLen - 20); - + startTiming(); - + /* - if(inputData.capacity()>64000) { - System.out.println("rectW = "+rectW+": rectH = "+rectH); - System.out.println("--------------------------------"); - } - */ - - //System.out.println("DataLength"+inputData.capacity()); - //System.out.println("rectW*rextdH"+rectW*rectH); - + * if(inputData.capacity()>64000) { + * System.out.println("rectW = "+rectW+": rectH = "+rectH); + * System.out.println("--------------------------------"); } + */ + + // System.out.println("DataLength"+inputData.capacity()); + // System.out.println("rectW*rextdH"+rectW*rectH); + readFully(inputData.array(), 0, inputData.capacity()); - //System.out.println(dataLen); + // System.out.println(dataLen); inputData.limit(dataLen - 20); stopTiming(); @@ -801,17 +798,36 @@ Deflater nDeflater = deflater; // new Deflater(); LinkedList<ByteBuffer> out = new LinkedList<ByteBuffer>(); 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); +// System.out.println(out.peek().get(INFLATE_BUFSIZE)); + + + /* + * System.out.println((((102400 * (out.size() - 1) + + * out.getLast() .limit())) - (rectW * rectH * 3)) + ":" + rectH + * + ":" + rectW + ":" + out.size()); + */ + + + - bufs.addFirst(header); - //if(dataLen<=64000) +// sumCheck(out); + //if((((102400 * (out.size() - 1) + out.getLast() .limit())) - (rectW * rectH * 3))==1){ + if(dataLen>64000){ + splitData(out, header); + } else { + // dump32(inputs); + nDeflater = new Deflater(); + int len2 = zip(nDeflater, out, 0, bufs); + ByteBuffer blen = ByteBuffer.allocate(4); + blen.putInt(len2); + blen.flip(); + bufs.addFirst(blen); + + bufs.addFirst(header); multicastqueue.put(bufs); - // is.reset(); + // is.reset(); + + } /* * System.out.println("ZRLE = "+dataLen); @@ -946,7 +962,7 @@ // after. // writeFramebufferUpdateRequest(0,0, framebufferWidth, // framebufferHeight, false ); - int i = 0; + int i = 0; for (;;) { LinkedList<ByteBuffer> bufs = c.poll(); int inputIndex = 0; @@ -960,11 +976,8 @@ // System.out.println("client "+ myId); } /* - if(i%20==0){ - sendDataCheckDelay(); - } - i++; - */ + * if(i%20==0){ sendDataCheckDelay(); } i++; + */ writeToClient(os, bufs, inputIndex); writerRunning.set(1); // yes my client is awaking. } @@ -977,28 +990,28 @@ /* if socket closed cliList.remove(newCli); */ } } - - void broadCastCommunication(byte[] buf,int len) { + + void broadCastCommunication(byte[] buf, int len) { String mcastAddr = "224.0.0.1"; int port = 8192; - + try { InetAddress mAddr = InetAddress.getByName(mcastAddr); MulticastSocket soc = new MulticastSocket(); - DatagramPacket sendPacket =null; + DatagramPacket sendPacket = null; soc.setTimeToLive(100); - -// System.out.println("Multicast = " + mcastAddr); - //while(buf != null) { -// int len = System.in.read(buf); - sendPacket = new DatagramPacket(buf,len,mAddr,port); + + // System.out.println("Multicast = " + mcastAddr); + // while(buf != null) { + // int len = System.in.read(buf); + sendPacket = new DatagramPacket(buf, len, mAddr, port); soc.send(sendPacket); -// } + // } soc.close(); - } catch(IOException e) { + } catch (IOException e) { e.printStackTrace(); } - + } public void writeToClient(final OutputStream os, @@ -1006,7 +1019,7 @@ throws IOException { while (inputIndex < bufs.size()) { ByteBuffer b = bufs.get(inputIndex++); -// broadCastCommunication(b.array(),b.limit()-b.position()); + // broadCastCommunication(b.array(),b.limit()-b.position()); os.write(b.array(), b.position(), b.limit()); } os.flush(); @@ -1149,4 +1162,163 @@ }; } + private LinkedList<ByteBuffer> splitBuffer(LinkedList<ByteBuffer> input) { + LinkedList<ByteBuffer> output = new LinkedList<ByteBuffer>(); + // int high = rectH / 4; + // System.out.println(INFLATE_BUFSIZE * (input.size() - 1)+ + // input.getLast().limit()); + int dataLen = rectW * 64 * 3 * 2; + int temp = 0; + int count = rectH / 128; + + if(rectW%64==0) + dataLen+=(rectW/64)*2; + else + dataLen+=(((rectW/64)+1)*2); + + for (int i = 0; i < count; i++) { + int tempDataLen = dataLen - temp; + + while (tempDataLen > INFLATE_BUFSIZE) { + output.addLast(input.poll()); + tempDataLen -= INFLATE_BUFSIZE; + } + if (tempDataLen == INFLATE_BUFSIZE) { + output.addLast(input.poll()); + output.addLast(null); + temp = INFLATE_BUFSIZE; + } else { + // System.out.println("THROWIO"); + ByteBuffer tempBuf = input.poll(); + + // System.out.println(tempBuf.remaining()); + ByteBuffer buf1 = ByteBuffer.allocate(INFLATE_BUFSIZE); + ByteBuffer buf2 = ByteBuffer.allocate(INFLATE_BUFSIZE); + tempBuf.get(buf1.array(), 0, tempDataLen); + tempBuf.get(buf2.array(), 0, tempBuf.remaining()); + buf1.limit(tempDataLen); + buf2.limit(INFLATE_BUFSIZE - tempDataLen); + buf2.position(0); + output.addLast(buf1); + output.addLast(null); + output.addLast(buf2); + temp = INFLATE_BUFSIZE - tempDataLen; + } + } + + while (input.size() != 0) { + output.addLast(input.poll()); + } + + + return output; + } + + private void splitData(LinkedList<ByteBuffer> input, ByteBuffer header) + throws IOException, DataFormatException { + + int sum2=0; + LinkedList<ByteBuffer> buf = splitBuffer(input); + for (int i = 0 ; i < (rectH/128)+1 ; i++) { + int sum=0; + LinkedList<ByteBuffer> tempBuf = new LinkedList<ByteBuffer>(); + while (buf.peek() != null) { + tempBuf.addLast(buf.poll()); + sum2+=tempBuf.getLast().limit(); + } + //Deflater nDeflater = deflater; + Deflater nDeflater = new Deflater(); + LinkedList<ByteBuffer> bufs = new LinkedList<ByteBuffer>(); + for(ByteBuffer b : tempBuf) { + sum += b.limit(); + } + + int len2 = zip(nDeflater, tempBuf, 0, bufs); + ByteBuffer blen = ByteBuffer.allocate(4); + blen.putInt(len2); + blen.flip(); + bufs.addFirst(blen); + createHeader(header,i); + + System.out.println(sum - (header.getShort(10)*header.getShort(8))*3); + System.out.println("sum2="+sum2); + + bufs.addFirst(header); + // broadcastqueue.put(bufs); + multicastqueue.put(bufs); + //System.out.println("pass"); + if(buf.size()!=0) + buf.remove(); + } + //System.out.println("throw"); + } + + private void createHeader(ByteBuffer header,int count) { + int rH = Math.min(128, rectH-(128*count)); + int rY = rectY + (128*count); + header.putShort(10, (short)rH); + header.putShort(6 , (short)rY); + } + + private void sumCheck(LinkedList<ByteBuffer> out) { + int g = out.size(); + int sum = 0; + for (int m = 0; m < g; m++) { + if (out.get(m) != null) { + if (out.get(m).limit() == 102400) + sum = sum + 102400; + else { + sum = sum + out.get(m).limit(); + } + } + } + System.out.println(sum); + } + + private void testRoutine() { + try { + LinkedList<ByteBuffer> in = new LinkedList<ByteBuffer>(); + LinkedList<ByteBuffer> out = new LinkedList<ByteBuffer>(); + LinkedList<ByteBuffer> out2 = new LinkedList<ByteBuffer>(); + // if (false) { + // for(int i=0;i<10;i++) { + // in.add(ByteBuffer.wrap("test1".getBytes())); + // in.add(ByteBuffer.wrap("test2".getBytes())); + // in.add(ByteBuffer.wrap("test3".getBytes())); + // in.add(ByteBuffer.wrap("test44".getBytes())); + // } + // } else + { + String t = ""; + for (int i = 0; i < 10; i++) { + t += "test1"; + t += "test2"; + t += "test3"; + t += "test44"; + } + in.add(ByteBuffer.wrap(t.getBytes())); + } + + // LinkedList<ByteBuffer> in1 = clone(in); + + Deflater deflater = new Deflater(); + zip(deflater, in, 0, out); + // LinkedList<ByteBuffer> out3 = clone(out); zipped result is depend + // on deflator's state + inflater = new Inflater(); + unzip(inflater, out, 0, out2, INFLATE_BUFSIZE); + // inflater.reset(); + //equalByteBuffers(in1, out2); + LinkedList<ByteBuffer> out4 = new LinkedList<ByteBuffer>(); + deflater = new Deflater(); + zip(deflater, out2, 0, out4); + LinkedList<ByteBuffer> out5 = new LinkedList<ByteBuffer>(); + unzip(inflater, out4, 0, out5, INFLATE_BUFSIZE); + //int len = equalByteBuffers(in1, out5); + + System.out.println("Test Ok. " ); + } catch (Exception e) { + assertEquals(0, 1); + } + } }
--- a/src/treeVnc/MyVncClient.java Sat Apr 07 14:55:34 2012 +0900 +++ b/src/treeVnc/MyVncClient.java Mon Apr 23 20:18:23 2012 +0900 @@ -54,7 +54,7 @@ if(argv.length==3){ pHost = argv[1]; port = Integer.parseInt(argv[2]); - } else { + } else { getHost = new TextBoxClient(); getHost.ipRegister(); pHost = getHost.getAddressOption(); @@ -78,7 +78,6 @@ port = Integer.parseInt(getBcast.text.getPort()); if (!("-reg".equals(argv[0]))) getBcast.socketClose(); - } } else { bCast = new BroadCastClient("who"); @@ -89,7 +88,14 @@ runBcast.start(); getBcast.setStopFlag(true); pHost = getBcast.text.getAddress(); - port = Integer.parseInt(getBcast.text.getPort()); + if("notFound".equals(pHost)) { + getHost = new TextBoxClient(); + getHost.ipRegister(); + pHost = getHost.getAddressOption(); + port = Integer.parseInt(getHost.getPortOption()); + } else { + port = Integer.parseInt(getBcast.text.getPort()); + } } // getBcast.text.checkBox(getNamePort());
--- a/src/treeVnc/ProxyVncCanvas.java Sat Apr 07 14:55:34 2012 +0900 +++ b/src/treeVnc/ProxyVncCanvas.java Mon Apr 23 20:18:23 2012 +0900 @@ -361,18 +361,20 @@ // main dispatch loop // - long count = 0; + // long count = 0; long buf = 0; while (true) { // System.out.println("\ncount=" + count); - count++; + // count++; /** * read Data from parents and send Data to Client. */ //rfb.sendDataCheckDelay(); + // select rfb and bcrfb + // if (in.selected()) rfb.sendDataToClient(); // rfb.checkDelayData(); // long kbitsPerSecond = rfb.kbitsPerSecond(); @@ -387,9 +389,24 @@ // rfb.checkDelayData(); continue; } - - - + + buf = decodePacket(rfb, statsRestarted,buf); + // else + // buf=decodePacket(bcrfb,statsRestarted,buf); + + /* + boolean result = false; + try{ + result = ImageIO.write(bimg, "png", new File("sample.png")); + }catch(Exception e){ + e.printStackTrace(); + result = false; + } +*/ + } + } + +long decodePacket(MyRfbProtoProxy rfb, boolean statsRestarted,long buf) throws Exception { long numBytesRead = rfb.getNumBytesRead(); // Read message type from the server. @@ -431,23 +448,23 @@ System.out.println("rx = "+ rx + " ry = "+ry+"\nrw = "+rw+" rh = "+rh); System.out.println("encoding = "+ rfb.updateRectEncoding); - if (rfb.updateRectEncoding == rfb.EncodingLastRect) + if (rfb.updateRectEncoding == RfbProto.EncodingLastRect) break; - if (rfb.updateRectEncoding == rfb.EncodingNewFBSize) { + if (rfb.updateRectEncoding == RfbProto.EncodingNewFBSize) { rfb.setFramebufferSize(rw, rh); updateFramebufferSize(); break; } - if (rfb.updateRectEncoding == rfb.EncodingXCursor - || rfb.updateRectEncoding == rfb.EncodingRichCursor) { + if (rfb.updateRectEncoding == RfbProto.EncodingXCursor + || rfb.updateRectEncoding == RfbProto.EncodingRichCursor) { handleCursorShapeUpdate(rfb.updateRectEncoding, rx, ry, rw, rh); continue; } - if (rfb.updateRectEncoding == rfb.EncodingPointerPos) { + if (rfb.updateRectEncoding == RfbProto.EncodingPointerPos) { softCursorMove(rx, ry); cursorPosReceived = true; continue; @@ -566,7 +583,7 @@ // int bufSize = (int)(rfb.getNumBytesRead() - numBytesRead); - long bufSize = rfb.getNumBytesRead() - numBytesRead; +// long bufSize = rfb.getNumBytesRead() - numBytesRead; // System.out.println("bufSize="+bufSize); buf += rfb.getNumBytesRead() - numBytesRead; @@ -582,20 +599,11 @@ rfb.createPngBytes(bimg); rfb.sendPngImage(); rfb.createBimgFlag = false; + } + return buf; +} - -/* - boolean result = false; - try{ - result = ImageIO.write(bimg, "png", new File("sample.png")); - }catch(Exception e){ - e.printStackTrace(); - result = false; - } -*/ - } - } // // Handle a raw rectangle. The second form with paint==false is used @@ -799,14 +807,14 @@ } // Is it a raw-encoded sub-rectangle? - if ((subencoding & rfb.HextileRaw) != 0) { + if ((subencoding & RfbProto.HextileRaw) != 0) { handleRawRect(tx, ty, tw, th, false); return; } // Read and draw the background if specified. byte[] cbuf = new byte[bytesPixel]; - if ((subencoding & rfb.HextileBackgroundSpecified) != 0) { + if ((subencoding & RfbProto.HextileBackgroundSpecified) != 0) { rfb.readFully(cbuf); if (bytesPixel == 1) { hextile_bg = colors[cbuf[0] & 0xFF]; @@ -822,7 +830,7 @@ memGraphics.fillRect(tx, ty, tw, th); // Read the foreground color if specified. - if ((subencoding & rfb.HextileForegroundSpecified) != 0) { + if ((subencoding & RfbProto.HextileForegroundSpecified) != 0) { rfb.readFully(cbuf); if (bytesPixel == 1) { hextile_fg = colors[cbuf[0] & 0xFF]; @@ -836,12 +844,12 @@ } // Done with this tile if there is no sub-rectangles. - if ((subencoding & rfb.HextileAnySubrects) == 0) + if ((subencoding & RfbProto.HextileAnySubrects) == 0) return; int nSubrects = rfb.readU8(); int bufsize = nSubrects * 2; - if ((subencoding & rfb.HextileSubrectsColoured) != 0) { + if ((subencoding & RfbProto.HextileSubrectsColoured) != 0) { bufsize += nSubrects * bytesPixel; } byte[] buf = new byte[bufsize]; @@ -854,7 +862,7 @@ int b1, b2, sx, sy, sw, sh; int i = 0; - if ((subencoding & rfb.HextileSubrectsColoured) == 0) { + if ((subencoding & RfbProto.HextileSubrectsColoured) == 0) { // Sub-rectangles are all of the same color. memGraphics.setColor(hextile_fg); @@ -1002,7 +1010,7 @@ } void readPixels(InStream is, int[] dst, int count) throws Exception { - int pix; + // int pix; if (bytesPixel == 1) { byte[] buf = new byte[count]; is.readBytes(buf, 0, count); @@ -1200,8 +1208,8 @@ int comp_ctl = rfb.readU8(); if (rfb.rec != null) { - if (rfb.recordFromBeginning || comp_ctl == (rfb.TightFill << 4) - || comp_ctl == (rfb.TightJpeg << 4)) { + if (rfb.recordFromBeginning || comp_ctl == (RfbProto.TightFill << 4) + || comp_ctl == (RfbProto.TightJpeg << 4)) { // Send data exactly as received. rfb.rec.writeByte(comp_ctl); } else { @@ -1219,12 +1227,12 @@ } // Check correctness of subencoding value. - if (comp_ctl > rfb.TightMaxSubencoding) { + if (comp_ctl > RfbProto.TightMaxSubencoding) { throw new Exception("Incorrect tight subencoding: " + comp_ctl); } // Handle solid-color rectangles. - if (comp_ctl == rfb.TightFill) { + if (comp_ctl == RfbProto.TightFill) { if (bytesPixel == 1) { int idx = rfb.readU8(); @@ -1248,7 +1256,7 @@ } - if (comp_ctl == rfb.TightJpeg) { + if (comp_ctl == RfbProto.TightJpeg) { statNumRectsTightJPEG++; @@ -1292,12 +1300,12 @@ byte[] palette8 = new byte[2]; int[] palette24 = new int[256]; boolean useGradient = false; - if ((comp_ctl & rfb.TightExplicitFilter) != 0) { + if ((comp_ctl & RfbProto.TightExplicitFilter) != 0) { int filter_id = rfb.readU8(); if (rfb.rec != null) { rfb.rec.writeByte(filter_id); } - if (filter_id == rfb.TightFilterPalette) { + if (filter_id == RfbProto.TightFilterPalette) { numColors = rfb.readU8() + 1; if (rfb.rec != null) { rfb.rec.writeByte(numColors - 1); @@ -1324,9 +1332,9 @@ } if (numColors == 2) rowSize = (w + 7) / 8; - } else if (filter_id == rfb.TightFilterGradient) { + } else if (filter_id == RfbProto.TightFilterGradient) { useGradient = true; - } else if (filter_id != rfb.TightFilterCopy) { + } else if (filter_id != RfbProto.TightFilterCopy) { throw new Exception("Incorrect tight filter id: " + filter_id); } } @@ -1335,7 +1343,7 @@ // Read, optionally uncompress and decode data. int dataSize = h * rowSize; - if (dataSize < rfb.TightMinToCompress) { + if (dataSize < RfbProto.TightMinToCompress) { // Data size is small - not compressed with zlib. if (numColors != 0) { // Indexed colors. @@ -1737,7 +1745,7 @@ int bytesPerRow = (width + 7) / 8; int bytesMaskData = bytesPerRow * height; - if (encodingType == rfb.EncodingXCursor) { + if (encodingType == RfbProto.EncodingXCursor) { rfb.skipBytes(6 + bytesMaskData * 2); } else { // rfb.EncodingRichCursor @@ -1777,7 +1785,7 @@ int[] softCursorPixels = new int[width * height]; - if (encodingType == rfb.EncodingXCursor) { + if (encodingType == RfbProto.EncodingXCursor) { // Read foreground and background colors of the cursor. byte[] rgb = new byte[6]; @@ -1829,7 +1837,7 @@ rfb.readFully(maskBuf); // Decode pixel data into softCursorPixels[]. - byte pixByte, maskByte; + byte maskByte; int x, y, n, result; int i = 0; for (y = 0; y < height; y++) {
--- a/src/treeVnc/RfbProto.java Sat Apr 07 14:55:34 2012 +0900 +++ b/src/treeVnc/RfbProto.java Mon Apr 23 20:18:23 2012 +0900 @@ -1,4 +1,5 @@ package treeVnc; + // // Copyright (C) 2001-2004 HorizonLive.com, Inc. All Rights Reserved. // Copyright (C) 2001-2006 Constantin Kaplinsky. All Rights Reserved. @@ -27,16 +28,21 @@ import java.io.*; import java.awt.event.*; +import java.net.InetSocketAddress; import java.net.Socket; +import java.net.SocketException; import java.nio.ByteBuffer; +import java.nio.channels.ServerSocketChannel; +import java.nio.channels.spi.AbstractSelector; +import java.nio.channels.spi.SelectorProvider; import java.util.LinkedList; import java.util.zip.*; public class RfbProto { final static String versionMsg_3_3 = "RFB 003.003\n", - versionMsg_3_7 = "RFB 003.007\n", versionMsg_3_8 = "RFB 003.008\n",versionMsg_3_855 = "RFB 003.855\n"; - + versionMsg_3_7 = "RFB 003.007\n", versionMsg_3_8 = "RFB 003.008\n", + versionMsg_3_855 = "RFB 003.855\n"; // Vendor signatures: standard VNC/RealVNC, TridiaVNC, and TightVNC final static String StandardVendor = "STDV", TridiaVncVendor = "TRDV", @@ -61,7 +67,7 @@ // Standard server-to-client messages final static int FramebufferUpdate = 0, SetColourMapEntries = 1, Bell = 2, ServerCutText = 3; - + // Check Delay Top form Bottom final static int CheckDelay = 11; @@ -80,7 +86,7 @@ // Supported encodings and pseudo-encodings final static int EncodingRaw = 0, EncodingCopyRect = 1, EncodingRRE = 2, - EncodingCoRRE = 4, EncodingHextile = 5, EncodingZlib = 6, + EncodingCoRRE = 4, EncodingHextile = 5, EncodingZlib = 6, EncodingTight = 7, EncodingZRLEE = 15, EncodingZRLE = 16, EncodingCompressLevel0 = 0xFFFFFF00, EncodingQualityLevel0 = 0xFFFFFFE0, EncodingXCursor = 0xFFFFFF10, @@ -90,8 +96,7 @@ SigEncodingCopyRect = "COPYRECT", SigEncodingRRE = "RRE_____", SigEncodingCoRRE = "CORRE___", SigEncodingHextile = "HEXTILE_", SigEncodingZlib = "ZLIB____", SigEncodingTight = "TIGHT___", - SigEncodingZRLEE = "ZRLEE___", - SigEncodingZRLE = "ZRLE____", + SigEncodingZRLEE = "ZRLEE___", SigEncodingZRLE = "ZRLE____", SigEncodingCompressLevel0 = "COMPRLVL", SigEncodingQualityLevel0 = "JPEGQLVL", SigEncodingXCursor = "X11CURSR", @@ -114,6 +119,7 @@ TightFilterCopy = 0x00, TightFilterPalette = 0x01, TightFilterGradient = 0x02; + static AbstractSelector selector; String host; int port; Socket sock; @@ -126,16 +132,15 @@ // Input stream is declared private to make sure it can be accessed // only via RfbProto methods. We have to do this because we want to // count how many bytes were read. -// private DataInputStream is; + // private DataInputStream is; protected DataInputStream is; -// private long numBytesRead = 0; + // private long numBytesRead = 0; protected long numBytesRead = 0; public long getNumBytesRead() { return numBytesRead; } - // Java on UNIX does not call keyPressed() on some keys, for example // swedish keys To prevent our workaround to produce duplicate // keypresses on JVMs that actually works, keep track of if @@ -178,9 +183,9 @@ CapsContainer encodingCaps; // If true, informs that the RFB socket was closed. -// private boolean closed; + // private boolean closed; protected boolean closed; - + private byte[] broadCastBuf = new byte[64000]; // @@ -192,7 +197,7 @@ port = p; if (viewer.socketFactory == null) { - sock = new Socket(host, port); + sock = newSocket(host, port); } else { try { Class factoryClass = Class.forName(viewer.socketFactory); @@ -215,29 +220,13 @@ timeWaitedIn100us = 5; timedKbits = 0; } - + RfbProto(String h, int p) throws IOException { host = h; port = p; - sock = new Socket(host, port); - - is = new DataInputStream(new BufferedInputStream(sock.getInputStream(),16384)); - os = sock.getOutputStream(); + sock = newSocket(host, port); - timing = false; - timeWaitedIn100us = 5; - timedKbits = 0; - } - - public RfbProto() { - - } - - public void changeRfbProto(String h,int port) throws IOException { - host = h; - sock=null; - sock = new Socket(host, port); is = new DataInputStream(new BufferedInputStream(sock.getInputStream(), 16384)); os = sock.getOutputStream(); @@ -247,7 +236,42 @@ timedKbits = 0; } + private ServerSocket newSocket(String host, int port) { + ServerSocketChannel ssChannel = SelectorProvider.provider().openServerSocketChannel(); + ssChannel.socket().setReuseAddress(true); + // this should work for IPv6/IPv4 dual stack + // check this using netstat -an result tcp46. + try { + InetSocketAddress address = new InetSocketAddress(host, port); + ssChannel.socket().bind(address); + } catch (SocketException e) { + // for some bad IPv6 implementation + ssChannel.socket().bind(new InetSocketAddress(port)); + } + ssChannel.configureBlocking(false); + return ssChannel.socket(); + } + public RfbProto() { + + } + + public void initOnce() throws IOException { + selector = SelectorProvider.provider().openSelector(); + } + + public void changeRfbProto(String h, int port) throws IOException { + host = h; + sock = null; + sock = newSocket(host, port); + is = new DataInputStream(new BufferedInputStream(sock.getInputStream(), + 16384)); + os = sock.getOutputStream(); + + timing = false; + timeWaitedIn100us = 5; + timedKbits = 0; + } synchronized void close() { try { @@ -314,7 +338,7 @@ protocolTightVNC = false; initCapabilities(); } - + // // Negotiate the authentication scheme. // @@ -367,18 +391,17 @@ return SecTypeTight; } } - // Find first supported security type. for (int i = 0; i < nSecTypes; i++) { -// if (secTypes[i] == SecTypeNone || secTypes[i] == SecTypeVncAuth) { - if (secTypes[i] == SecTypeNone || secTypes[i] == SecTypeVncAuth - || secTypes[i] == MyRfbProtoProxy.SecTypeReqAccess) { - secType = secTypes[i]; + // if (secTypes[i] == SecTypeNone || secTypes[i] == SecTypeVncAuth) + // { + if (secTypes[i] == SecTypeNone || secTypes[i] == SecTypeVncAuth + || secTypes[i] == MyRfbProtoProxy.SecTypeReqAccess) { + secType = secTypes[i]; break; } - } - + } if (secType == SecTypeInvalid) { throw new Exception("Server did not offer supported security type"); @@ -494,9 +517,9 @@ encodingCaps.add(EncodingHextile, StandardVendor, SigEncodingHextile, "Standard Hextile encoding"); encodingCaps.add(EncodingZRLE, StandardVendor, SigEncodingZRLE, - "Standard ZRLE encoding"); + "Standard ZRLE encoding"); encodingCaps.add(EncodingZRLEE, StandardVendor, SigEncodingZRLEE, - "Standard ZRLE(E) encoding"); + "Standard ZRLE(E) encoding"); encodingCaps.add(EncodingZlib, TridiaVncVendor, SigEncodingZlib, "Zlib encoding"); encodingCaps.add(EncodingTight, TightVncVendor, SigEncodingTight, @@ -589,17 +612,17 @@ // void writeClientInit() throws IOException { -/* - if (viewer.options.shareDesktop) { -*/ - + /* + * if (viewer.options.shareDesktop) { + */ + /** * shared flag */ - os.write(1); -// os.write(0); + os.write(1); + // os.write(0); -// viewer.options.disableShareDesktop(); + // viewer.options.disableShareDesktop(); } // @@ -854,13 +877,12 @@ // // Write a FramebufferUpdateRequest message // - - + void checkDelayData() throws IOException { System.out.println("sousinn"); - byte[] b = new byte[1]; - b[0] = (byte) CheckDelay; - os.write(b); + byte[] b = new byte[1]; + b[0] = (byte) CheckDelay; + os.write(b); } void writeFramebufferUpdateRequest(int x, int y, int w, int h, @@ -992,8 +1014,6 @@ final static int META_MASK = InputEvent.META_MASK; final static int ALT_MASK = InputEvent.ALT_MASK; - - // // Write a pointer event message. We may need to send modifier key events // around it to set the correct modifier state. @@ -1007,11 +1027,9 @@ int mask2 = 2; int mask3 = 4; /* - if (viewer.options.reverseMouseButtons2And3) { - mask2 = 4; - mask3 = 2; - } - */ + * if (viewer.options.reverseMouseButtons2And3) { mask2 = 4; mask3 = 2; + * } + */ // Note: For some reason, AWT does not set BUTTON1_MASK on left // button presses. Here we think that it was the left button if @@ -1370,49 +1388,39 @@ readFully(b, 0, b.length); } - long before = System.currentTimeMillis(); + long before = System.currentTimeMillis(); + public void readFully(byte b[], int off, int len) throws IOException { -// long before = 0; + // long before = 0; if (timing) before = System.currentTimeMillis(); is.readFully(b, off, len); - + /* - if(b.length==16) { - b[4] = (byte)0; - b[5] = (byte)0; - b[6] = (byte)0; - b[7] = (byte)0; - System.out.println("----------------------"); - } - */ - //System.out.println("Blength:"+b.length); - //for(int i=0 ; i<=b.length ; i++) { - //if(i>b.length/2) - //b[i] = 10; - //} + * if(b.length==16) { b[4] = (byte)0; b[5] = (byte)0; b[6] = (byte)0; + * b[7] = (byte)0; System.out.println("----------------------"); } + */ + // System.out.println("Blength:"+b.length); + // for(int i=0 ; i<=b.length ; i++) { + // if(i>b.length/2) + // b[i] = 10; + // } /* - if (timing) { - long after = System.currentTimeMillis(); - long newTimeWaited = (after - before) * 10; - int newKbits = len * 8 / 1000; - - // limit rate to between 10kbit/s and 40Mbit/s - - if (newTimeWaited > newKbits * 1000) - newTimeWaited = newKbits * 1000; - if (newTimeWaited < newKbits / 4) - newTimeWaited = newKbits / 4; - - timeWaitedIn100us += newTimeWaited; - timedKbits += newKbits; - before = after; - } - */ + * if (timing) { long after = System.currentTimeMillis(); long + * newTimeWaited = (after - before) * 10; int newKbits = len * 8 / 1000; + * + * // limit rate to between 10kbit/s and 40Mbit/s + * + * if (newTimeWaited > newKbits * 1000) newTimeWaited = newKbits * 1000; + * if (newTimeWaited < newKbits / 4) newTimeWaited = newKbits / 4; + * + * timeWaitedIn100us += newTimeWaited; timedKbits += newKbits; before = + * after; } + */ numBytesRead += len; - //System.out.println("numBytesRead:"+numBytesRead); + // System.out.println("numBytesRead:"+numBytesRead); } final int available() throws IOException { @@ -1446,7 +1454,8 @@ return r; } - public LinkedList<ByteBuffer> blockingUpdateRectangle(ByteBuffer input,int w,int h) { + public LinkedList<ByteBuffer> blockingUpdateRectangle( + LinkedList<ByteBuffer> input, int w, int h) { return null; }
--- a/src/treeVnc/TextBoxClient.java Sat Apr 07 14:55:34 2012 +0900 +++ b/src/treeVnc/TextBoxClient.java Mon Apr 23 20:18:23 2012 +0900 @@ -7,7 +7,6 @@ public class TextBoxClient extends JFrame implements ActionListener, ItemListener { - /** * */ @@ -119,9 +118,12 @@ int i = 0; while (!(flag)) { if (i >= 50) { + /* reportWindow(); visible(); break; + */ + return "notFound"; } try { Thread.sleep(500);
--- a/src/treeVnc/VncCanvas.java Sat Apr 07 14:55:34 2012 +0900 +++ b/src/treeVnc/VncCanvas.java Mon Apr 23 20:18:23 2012 +0900 @@ -966,6 +966,8 @@ if (!rle) { if (palSize == 0) { + System.out.println("mode"+mode); + System.out.println(tw+":"+th+":"+ty); readZrleRawPixels(tw, th); } else { readZrlePackedPixels(tw, th, palette, palSize); @@ -974,6 +976,8 @@ if (palSize == 0) { readZrlePlainRLEPixels(tw, th); } else { + System.out.println("mode"+mode); + System.out.println(tw+":"+th+":"+ty); readZrlePackedRLEPixels(tw, th, palette); } } @@ -1002,7 +1006,7 @@ } void readPixels(InStream is, int[] dst, int count) throws Exception { - int pix; + // int pix; if (bytesPixel == 1) { byte[] buf = new byte[count]; is.readBytes(buf, 0, count);