# HG changeset patch # User oc # Date 1412597431 -32400 # Node ID f4ea9ff0474131d691b33c65bc901841b5b4e598 # Parent 5eb8aa65f387d43829e00b52b92c3401a180b079 reply checkdelay diff -r 5eb8aa65f387 -r f4ea9ff04741 src/main/java/com/glavsoft/rfb/client/ClientToServerMessage.java --- a/src/main/java/com/glavsoft/rfb/client/ClientToServerMessage.java Mon Oct 06 18:17:37 2014 +0900 +++ b/src/main/java/com/glavsoft/rfb/client/ClientToServerMessage.java Mon Oct 06 21:10:31 2014 +0900 @@ -35,6 +35,7 @@ byte POINTER_EVENT = 5; byte CLIENT_CUT_TEXT = 6; byte SERVER_CHANGE_REQUEST = (byte) 240; // TreeVNC extension + byte CHECK_DELAY_REPLY = 7; void send(Writer writer) throws TransportException; } diff -r 5eb8aa65f387 -r f4ea9ff04741 src/main/java/com/glavsoft/rfb/encoding/decoder/FramebufferUpdateRectangle.java --- a/src/main/java/com/glavsoft/rfb/encoding/decoder/FramebufferUpdateRectangle.java Mon Oct 06 18:17:37 2014 +0900 +++ b/src/main/java/com/glavsoft/rfb/encoding/decoder/FramebufferUpdateRectangle.java Mon Oct 06 21:10:31 2014 +0900 @@ -64,7 +64,7 @@ encodingType = EncodingType.byId(encoding); if (encoding == 17) { time = reader.readInt64(); - System.out.println("time = " + time); +// System.out.println("time = " + time); } } diff -r 5eb8aa65f387 -r f4ea9ff04741 src/main/java/com/glavsoft/rfb/protocol/ReceiverTask.java --- a/src/main/java/com/glavsoft/rfb/protocol/ReceiverTask.java Mon Oct 06 18:17:37 2014 +0900 +++ b/src/main/java/com/glavsoft/rfb/protocol/ReceiverTask.java Mon Oct 06 21:10:31 2014 +0900 @@ -48,6 +48,7 @@ import java.util.LinkedList; import java.util.logging.Logger; +import jp.ac.u_ryukyu.treevnc.CheckDelayReply; import jp.ac.u_ryukyu.treevnc.TreeRFBProto; import jp.ac.u_ryukyu.treevnc.TreeVncProtocol; import jp.ac.u_ryukyu.treevnc.UpdateRectangleMessage; @@ -268,7 +269,8 @@ int length = reader.readInt32(); reader.reset(); rfb.readSendData(length + 24, reader, null); - System.out.println("rect.time=" + rect.time); +// System.out.println("rect.time=" + rect.time); + sendCheckDelayReply(rect.time); } else throw new CommonException("Unprocessed encoding: " + rect.toString()); } @@ -289,9 +291,13 @@ } } + private void sendCheckDelayReply(long time) { + context.sendMessage(new CheckDelayReply(time)); + + } + private void readCheckDelay(Reader reader) { - System.out.println("read check delay."); - // データを読み込む処理 +// System.out.println("read check delay."); } public synchronized void queueUpdatePixelFormat(PixelFormat pf) { diff -r 5eb8aa65f387 -r f4ea9ff04741 src/main/java/jp/ac/u_ryukyu/treevnc/CheckDelayReply.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/jp/ac/u_ryukyu/treevnc/CheckDelayReply.java Mon Oct 06 21:10:31 2014 +0900 @@ -0,0 +1,29 @@ +package jp.ac.u_ryukyu.treevnc; + +import java.nio.ByteBuffer; +import java.nio.ByteOrder; + +import com.glavsoft.exceptions.TransportException; +import com.glavsoft.rfb.client.ClientToServerMessage; +import com.glavsoft.transport.Writer; + +public class CheckDelayReply implements ClientToServerMessage { + + private long time; + + public CheckDelayReply(long time) { + this.time = time; + } + + @Override + public void send(Writer writer) throws TransportException { + ByteBuffer out = ByteBuffer.allocate(10); + out.order(ByteOrder.BIG_ENDIAN); + out.put(CHECK_DELAY_REPLY); + out.put((byte)0); + out.putLong(time); + writer.write(out.array(), 0, out.position()); + writer.flush(); + } + +} diff -r 5eb8aa65f387 -r f4ea9ff04741 src/main/java/jp/ac/u_ryukyu/treevnc/TreeRFBProto.java --- a/src/main/java/jp/ac/u_ryukyu/treevnc/TreeRFBProto.java Mon Oct 06 18:17:37 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/treevnc/TreeRFBProto.java Mon Oct 06 21:10:31 2014 +0900 @@ -140,7 +140,6 @@ * handle command from lower node */ final Runnable reader = new Runnable() { - public void run() { for (;;) { try { @@ -161,11 +160,17 @@ System.out.println("Root server change request :" + newHostName); // please remove these numbers. if (viewer != null) { - changeVNCServer(viewer, newHostName, 3200, 1980, id); + changeVNCServer(viewer, newHostName, 3200, 1980, id); } } else { continue; } + } else if (b[0] == ClientToServerMessage.CHECK_DELAY_REPLY) { + ByteBuffer buf = ByteBuffer.wrap(b); + buf.order(ByteOrder.BIG_ENDIAN); + Long time = buf.getLong(2); + Long delay = System.currentTimeMillis() - time; + System.out.println("delay = " + delay); } } else if (b[0] == ClientToServerMessage.SERVER_CHANGE_REQUEST) { ClientToServerMessage sc = new ClientToServerMessage() { @@ -176,6 +181,18 @@ } }; context.sendMessage(sc); + } else if (b[0] == ClientToServerMessage.CHECK_DELAY_REPLY) { + ClientToServerMessage checkDelayReply = new ClientToServerMessage() { + @Override + public void send(Writer writer) + throws TransportException { + writer.write(b,0,c); + } + }; + ByteBuffer buf = ByteBuffer.wrap(b); + buf.order(ByteOrder.BIG_ENDIAN); + Long time = buf.getLong(2); + context.sendMessage(checkDelayReply); } // System.out.println("client read "+c); } catch (Exception e) { @@ -544,7 +561,7 @@ int encoding = header.getInt(12); - if (i%20 == 0) { + if (i == 1) { LinkedList checkdelay = new LinkedList(); long time = System.currentTimeMillis(); checkdelay.add(new UpdateRectangleMessage(0, 0, 0, 0, time, EncodingType.CHECK_DELAY).getMessage());