Mercurial > hg > Applications > TreeVNC
changeset 239:d655db005535
create sendCheckDelay Socket.
author | oc |
---|---|
date | Sat, 11 Oct 2014 23:46:22 +0900 |
parents | e21ef8f60f7a |
children | 7310e7d7a45f |
files | src/main/java/com/glavsoft/rfb/encoding/decoder/ZRLEESender.java src/main/java/com/glavsoft/rfb/protocol/ReceiverTask.java src/main/java/jp/ac/u_ryukyu/treevnc/SendCheckDelay.java src/main/java/jp/ac/u_ryukyu/treevnc/TreeRFBProto.java src/main/java/jp/ac/u_ryukyu/treevnc/TreeVncCommandChannelListener.java |
diffstat | 5 files changed, 118 insertions(+), 56 deletions(-) [+] |
line wrap: on
line diff
--- a/src/main/java/com/glavsoft/rfb/encoding/decoder/ZRLEESender.java Sat Oct 11 14:15:48 2014 +0900 +++ b/src/main/java/com/glavsoft/rfb/encoding/decoder/ZRLEESender.java Sat Oct 11 23:46:22 2014 +0900 @@ -11,56 +11,48 @@ public class ZRLEESender extends Decoder { - private TreeRFBProto rfb; + private TreeRFBProto rfb; - public ZRLEESender(TreeRFBProto rfb) { - this.rfb = rfb; - } + public ZRLEESender(TreeRFBProto rfb) { + this.rfb = rfb; + } - public ZRLEESender() { - } + public ZRLEESender() { + } - @Override - public void decode(Reader reader, Renderer renderer, - FramebufferUpdateRectangle rect) throws TransportException, UnsupportedEncodingException { - // TreeVNC handling + @Override + public void decode(Reader reader, Renderer renderer, + FramebufferUpdateRectangle rect) throws TransportException, UnsupportedEncodingException { + // TreeVNC handling int dataLen = getZrleLength(rect, reader); byte[] bytes = new byte[rect.width * rect.height * renderer.getBytesPerPixel()]; reader.reset(); - if (rfb.hasViewer()) { - ZRLEDecoder decoder = new ZRLEDecoder(); - if (rfb.isTreeManager()) { + if (rfb.hasViewer()) { + ZRLEDecoder decoder = new ZRLEDecoder(); + if (rfb.isTreeManager()) { rfb.readSendData(dataLen, reader, bytes); - decoder.decode1(renderer, rect, bytes, 0); - return; - } else if (!rfb.getCuiVersion()) { + decoder.decode1(renderer, rect, bytes, 0); + return; + } else if (!rfb.getCuiVersion()) { rfb.readSendData(dataLen, reader, null); reader.reset(); reader.skip(16); - decoder.decode(reader, renderer, rect); - return; - } - } - rfb.readSendData(dataLen, reader, bytes); - } + decoder.decode(reader, renderer, rect); + return; + } + } + rfb.readSendData(dataLen, reader, bytes); + } - private int getZrleLength(FramebufferUpdateRectangle rect, Reader reader) - throws TransportException { - int zrleLength = 0; - if (rect.getEncodingType() == EncodingType.ZRLE - || rect.getEncodingType() == EncodingType.ZRLEE - || rect.getEncodingType() == EncodingType.ZLIB) { - zrleLength = reader.readInt32(); - } - return zrleLength + 20; - } + private int getZrleLength(FramebufferUpdateRectangle rect, Reader reader) + throws TransportException { + int zrleLength = 0; + if (rect.getEncodingType() == EncodingType.ZRLE + || rect.getEncodingType() == EncodingType.ZRLEE + || rect.getEncodingType() == EncodingType.ZLIB) { + zrleLength = reader.readInt32(); + } + return zrleLength + 20; + } - public void readCheckDelay(Reader reader) { - try { - reader.reset(); - rfb.readCheckDelay(reader); - } catch (TransportException e) { - e.printStackTrace(); - } - } }
--- a/src/main/java/com/glavsoft/rfb/protocol/ReceiverTask.java Sat Oct 11 14:15:48 2014 +0900 +++ b/src/main/java/com/glavsoft/rfb/protocol/ReceiverTask.java Sat Oct 11 23:46:22 2014 +0900 @@ -47,6 +47,7 @@ import java.util.logging.Logger; import jp.ac.u_ryukyu.treevnc.CheckDelayReply; +import jp.ac.u_ryukyu.treevnc.SendCheckDelay; import jp.ac.u_ryukyu.treevnc.TreeRFBProto; import jp.ac.u_ryukyu.treevnc.TreeVncProtocol; @@ -71,7 +72,10 @@ protected boolean needSendPixelFormat; private TreeRFBProto rfb; private long checkCounter = 0; + private boolean firstTime = true; + + public ReceiverTask(Reader reader, IRepaintController repaintController, ClipboardController clipboardController, DecodersContainer decoders, ProtocolContext context, @@ -112,7 +116,7 @@ byte messageId = reader.readByte(); switch (messageId) { case FRAMEBUFFER_UPDATE: - // logger.fine("Server message: FramebufferUpdate (0)"); + // logger.fine("Server message: FramebufferUpdate (0)"); framebufferUpdateMessage(); break; case SET_COLOR_MAP_ENTRIES: @@ -121,8 +125,8 @@ break; case BELL: logger.fine("Server message: Bell"); - // System.out.print("\0007"); - // System.out.flush(); + // System.out.print("\0007"); + // System.out.flush(); break; case SERVER_CUT_TEXT: logger.fine("Server message: CutText (3)"); @@ -208,11 +212,17 @@ public void framebufferUpdateMessage() throws CommonException, UnsupportedEncodingException { reader.readByte(); // padding int numberOfRectangles = reader.readUInt16(); - + + if(rfb.isTreeManager() && firstTime) { + SendCheckDelay sendCheckDelay = new SendCheckDelay(rfb); + Thread sendCheckDelayThread = new Thread(sendCheckDelay, "send-check-delay"); + sendCheckDelayThread.start(); + this.firstTime = false; + } + while (numberOfRectangles-- > 0) { FramebufferUpdateRectangle rect = new FramebufferUpdateRectangle(); rect.fill(reader); - Decoder decoder = decoders.getDecoderByType(rect.getEncodingType()); logger.finest(rect.toString() + (0 == numberOfRectangles ? "\n---" : "")); if (decoder != null) { @@ -258,16 +268,16 @@ int checkDelaySize = length + 24; reader.reset(); rfb.readSendData(checkDelaySize, reader, null); - int port = rfb.acceptPort; String address = rfb.getMyAddress(); sendCheckDelayReply(rect.time, port, address); } else throw new CommonException("Unprocessed encoding: " + rect.toString()); } - - - if (!rfb.isTreeManager()) return; + + if (!rfb.isTreeManager()) { + return; + } synchronized (this) { if (needSendPixelFormat) { needSendPixelFormat = false;
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/jp/ac/u_ryukyu/treevnc/SendCheckDelay.java Sat Oct 11 23:46:22 2014 +0900 @@ -0,0 +1,45 @@ +package jp.ac.u_ryukyu.treevnc; + +import java.io.UnsupportedEncodingException; +import java.nio.ByteBuffer; +import java.util.LinkedList; + +import com.glavsoft.rfb.encoding.EncodingType; + + +public class SendCheckDelay implements Runnable { + + private TreeRFBProto rfb; + + public SendCheckDelay(TreeRFBProto rfb) { + this.rfb = rfb; + } + + public void sendCheckDelay() throws UnsupportedEncodingException { + + LinkedList<ByteBuffer> checkdelay = new LinkedList<ByteBuffer>(); + long time = System.currentTimeMillis(); + checkdelay.add(new CheckDelay(0, 0, 0, 0, time, EncodingType.CHECK_DELAY).getMessage()); + rfb.addSerialNumber(checkdelay); + rfb.multicastqueue.put(checkdelay); + + } + + public void run() { + for (;;) { + System.out.println("run sendCheckDelay"); + long timeout = 50000 / 8; + try { + synchronized (this) { + wait(timeout); + sendCheckDelay(); + } + } catch (InterruptedException e) { + e.printStackTrace(); + } catch (UnsupportedEncodingException e) { + e.printStackTrace(); + } + } + } + +}
--- a/src/main/java/jp/ac/u_ryukyu/treevnc/TreeRFBProto.java Sat Oct 11 14:15:48 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/treevnc/TreeRFBProto.java Sat Oct 11 23:46:22 2014 +0900 @@ -65,6 +65,7 @@ private String vncInterface; private int i; public LinkedList<TreeVNCNode> nodeList; + private SendCheckDelay sendCheckDelay; public TreeRFBProto(boolean isTreeManager) { @@ -182,6 +183,10 @@ int nodeNum = getNodeNum(port, address); Long delay = System.currentTimeMillis() - time; System.out.println("nodeNum" + nodeNum + ", delay = " + delay); + + // checkNodeNum(); + // readSendData(check); + } } else if (b[0] == ClientToServerMessage.SERVER_CHANGE_REQUEST) { ClientToServerMessage sc = new ClientToServerMessage() { @@ -226,13 +231,13 @@ writerRunning.set(1); try { requestThreadNotify(); - + // after this, we discard upward packet. - new Thread(reader, "upward-packet-processing").start(); - + new Thread(reader, "upward-packet-processing").start(); + for (;;) { LinkedList<ByteBuffer> bufs = c.poll(); - + int inputIndex = 0; ByteBuffer header = bufs.get(inputIndex); if (header == null) @@ -567,7 +572,11 @@ header.limit(16); if (header.get(0) == FramebufferUpdate) { int encoding = header.getInt(12); + +// sendCheckDelay.run(); + + /* if(isTreeManager()) { if (i%20 == 0) { LinkedList<ByteBuffer> checkdelay = new LinkedList<ByteBuffer>(); @@ -577,6 +586,7 @@ multicastqueue.put(checkdelay); } i++; } + */ if (encoding == EncodingType.ZRLE.getId() || encoding == EncodingType.ZLIB.getId()) { @@ -704,8 +714,13 @@ startTreeVncCommandListener(); if(isTreeManager() && firstTime) { getCast = new TreeRootFinderListener(v); - Thread thread = new Thread(getCast, "tree-root-find-listener"); - thread.start(); + Thread treeRootFindThread = new Thread(getCast, "tree-root-find-listener"); + treeRootFindThread.start(); + /* + sendCheckDelay = new SendCheckDelay(); + Thread sendCheckDelayThread = new Thread(sendCheckDelay, "send-check-delay"); + sendCheckDelayThread.start(); + */ firstTime = false; } }
--- a/src/main/java/jp/ac/u_ryukyu/treevnc/TreeVncCommandChannelListener.java Sat Oct 11 14:15:48 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/treevnc/TreeVncCommandChannelListener.java Sat Oct 11 23:46:22 2014 +0900 @@ -223,7 +223,7 @@ // In case of "-d" we have no context ProtocolContext context = rfb.context; if (context != null){ - os.write(context.getInitData()); + os.write(context.getInitData()); } else { // Send dummy data os.write(initData);