Mercurial > hg > Applications > TreeVNC
changeset 66:84ad879891e9
dont move
author | Taninari YU <you@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Sat, 01 Feb 2014 06:43:27 +0900 |
parents | ffd7537cebfc |
children | 2908e4b95b0a |
files | src/main/java/com/glavsoft/rfb/encoding/decoder/FramebufferUpdateRectangle.java 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/MyRfbProto.java src/main/java/jp/ac/u_ryukyu/treevnc/client/MyRfbProtoClient.java src/main/java/jp/ac/u_ryukyu/treevnc/server/MyRfbProtoProxy.java src/main/java/jp/ac/u_ryukyu/treevnc/server/VncProxyService.java src/viewer_swing/java/com/glavsoft/viewer/ConnectionPresenter.java src/viewer_swing/java/com/glavsoft/viewer/swing/SwingViewerWindow.java |
diffstat | 9 files changed, 123 insertions(+), 36 deletions(-) [+] |
line wrap: on
line diff
--- a/src/main/java/com/glavsoft/rfb/encoding/decoder/FramebufferUpdateRectangle.java Mon Jan 27 16:35:20 2014 +0900 +++ b/src/main/java/com/glavsoft/rfb/encoding/decoder/FramebufferUpdateRectangle.java Sat Feb 01 06:43:27 2014 +0900 @@ -60,7 +60,6 @@ height = reader.readUInt16(); int encoding = reader.readInt32(); encodingType = EncodingType.byId(encoding); - } public EncodingType getEncodingType() {
--- a/src/main/java/com/glavsoft/rfb/encoding/decoder/ZRLEESender.java Mon Jan 27 16:35:20 2014 +0900 +++ b/src/main/java/com/glavsoft/rfb/encoding/decoder/ZRLEESender.java Sat Feb 01 06:43:27 2014 +0900 @@ -9,38 +9,39 @@ import com.glavsoft.transport.Reader; public class ZRLEESender extends Decoder { - + private MyRfbProto rfb; public ZRLEESender(MyRfbProto rfb) { this.rfb = rfb; } - - public ZRLEESender(MyRfbProtoClient rfb) { + + public ZRLEESender() { } - + @Override public void decode(Reader reader, Renderer renderer, FramebufferUpdateRectangle rect) throws TransportException { - int dataLen = getZrleLength(rect,reader); + int dataLen = getZrleLength(rect, reader); reader.reset(); rfb.readSendData(dataLen, reader); - - if(rfb instanceof MyRfbProtoClient) { + + if (rfb instanceof MyRfbProtoClient) { + //reader.readBytes(8); reader.readByte();// message - reader.readByte();// padding + reader.readByte();// padding reader.readUInt16();// numberOfRectangle rect.fill(reader);// fill Decoder decoder = new ZRLEDecoder(); - int zippedLength = (int) reader.readUInt32(); - if(!rfb.getCuiVersion()) - decoder.decode(reader,renderer,rect); - else - reader.readBytes(zippedLength);System.out.println("path"); + if (!rfb.getCuiVersion()) + decoder.decode(reader, renderer, rect); + else { + reader.readBytes((int) reader.readUInt32()); + } } } - private int getZrleLength(FramebufferUpdateRectangle rect,Reader reader) + private int getZrleLength(FramebufferUpdateRectangle rect, Reader reader) throws TransportException { int zrleLength = 0; if (rect.getEncodingType() == EncodingType.ZRLE @@ -50,4 +51,13 @@ } 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 Mon Jan 27 16:35:20 2014 +0900 +++ b/src/main/java/com/glavsoft/rfb/protocol/ReceiverTask.java Sat Feb 01 06:43:27 2014 +0900 @@ -38,6 +38,7 @@ import com.glavsoft.rfb.encoding.decoder.DecodersContainer; import com.glavsoft.rfb.encoding.decoder.FramebufferUpdateRectangle; import com.glavsoft.rfb.encoding.decoder.RichCursorDecoder; +import com.glavsoft.rfb.encoding.decoder.ZRLEESender; import com.glavsoft.transport.Reader; import java.io.PrintWriter; @@ -53,6 +54,7 @@ private static final byte SET_COLOR_MAP_ENTRIES = 1; private static final byte BELL = 2; private static final byte SERVER_CUT_TEXT = 3; + private static final byte Check_Delay = 11; private static Logger logger = Logger.getLogger("com.glavsoft.rfb.protocol.ReceiverTask"); @@ -68,6 +70,7 @@ protected boolean needSendPixelFormat; private MyRfbProto rfb; private boolean cuiVersion; + private long checkCounter = 0; public ReceiverTask(Reader reader, IRepaintController repaintController, ClipboardController clipboardController, @@ -108,7 +111,12 @@ isRunning = true; while (isRunning) { try { - reader.mark(20); +// if(rfb instanceof MyRfbProtoClient) { +// reader.mark(28); +// getLost(reader); +// } else { + reader.mark(20); +// } byte messageId = reader.readByte(); switch (messageId) { case FRAMEBUFFER_UPDATE: @@ -128,6 +136,14 @@ logger.fine("Server message: CutText (3)"); serverCutText(); break; + case Check_Delay: + ZRLEESender sender = new ZRLEESender(rfb); + sender.readCheckDelay(reader); + /* + reader.readBytes(15); + System.out.println("delay_time="+(System.currentTimeMillis() - reader.readInt64())); + */ + break; default: logger.severe("Unsupported server message. Id = " + messageId); } @@ -207,8 +223,6 @@ decoder.decode(reader, renderer, rect); if(!(rfb.getCuiVersion())) repaintController.repaintBitmap(rect); - else - System.out.println("cuiversion"); } else if (rect.getEncodingType() == EncodingType.RICH_CURSOR) { RichCursorDecoder.getInstance().decode(reader, renderer, rect); if(repaintController!=null) @@ -255,5 +269,16 @@ private void connectionFinished() { rfb.setReadyReconnect(true); } - + + private void getLost(Reader reader) { + try { + long num = reader.readInt64(); + if(num != ++checkCounter) { + System.out.println("LostData" + (num - checkCounter)); + checkCounter = num; + } + } catch (TransportException e) { + e.printStackTrace(); + } + } }
--- a/src/main/java/jp/ac/u_ryukyu/treevnc/MyRfbProto.java Mon Jan 27 16:35:20 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/treevnc/MyRfbProto.java Sat Feb 01 06:43:27 2014 +0900 @@ -153,7 +153,6 @@ continue; else if (header.get(0) == CheckDelay) { writeToClient(os, bufs, inputIndex); - //System.out.println("*********checkdelay****************"); continue; } else if (header.get(0) == FramebufferUpdate) { //System.out.println("client "+ myId); @@ -389,5 +388,13 @@ public void setCuiVersion(boolean flag) { cuiVersion = flag; } + + public void readCheckDelay(Reader reader) throws TransportException { + + } + + public String getProxyAddr() { + return proxyAddr; + } }
--- a/src/main/java/jp/ac/u_ryukyu/treevnc/client/MyRfbProtoClient.java Mon Jan 27 16:35:20 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/treevnc/client/MyRfbProtoClient.java Sat Feb 01 06:43:27 2014 +0900 @@ -1,12 +1,16 @@ package jp.ac.u_ryukyu.treevnc.client; +import java.io.BufferedReader; import java.io.DataInputStream; +import java.io.DataOutputStream; import java.io.IOException; import java.io.InputStream; +import java.io.InputStreamReader; import java.io.OutputStream; import java.net.BindException; import java.net.ServerSocket; import java.net.Socket; +import java.net.UnknownHostException; import java.nio.ByteBuffer; import java.util.LinkedList; import java.util.zip.DataFormatException; @@ -305,7 +309,10 @@ throws TransportException { LinkedList<ByteBuffer> bufs = new LinkedList<ByteBuffer>(); ByteBuffer header = ByteBuffer.allocate(16); - reader.mark(dataLen); +// ByteBuffer serial = ByteBuffer.allocate(8); + reader.mark(dataLen); // +8 is serialnum +// reader.readBytes(serial.array(),0,8); +// serial.limit(8); reader.readBytes(header.array(), 0, 16); header.limit(16); if (header.get(0) == FramebufferUpdate) { @@ -350,6 +357,7 @@ return; } } +// bufs.add(serial); bufs.add(header); if (dataLen > 16) { ByteBuffer b = ByteBuffer.allocate(dataLen - 16); @@ -386,6 +394,29 @@ } } - - + @Override + public void readCheckDelay(Reader reader) throws TransportException { + ByteBuffer buf = ByteBuffer.allocate(24); + reader.readBytes(buf.array(), 0, 24); + + LinkedList<ByteBuffer> sendData = new LinkedList<ByteBuffer>(); + sendData.add(buf); + Socket echoSocket; + try { + echoSocket = new Socket(getProxyAddr(), 10002); + BufferedReader is = new BufferedReader(new InputStreamReader(echoSocket.getInputStream())); + DataOutputStream os = new DataOutputStream(echoSocket.getOutputStream()); + os.writeBytes("checkdelay\n"); + os.writeBytes(String.valueOf(buf.getLong(16))+"\n"); + System.out.println("delay"+ is.readLine()); + } catch (UnknownHostException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + buf.position(0); + + multicastqueue.put(sendData); + + } }
--- a/src/main/java/jp/ac/u_ryukyu/treevnc/server/MyRfbProtoProxy.java Mon Jan 27 16:35:20 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/treevnc/server/MyRfbProtoProxy.java Sat Feb 01 06:43:27 2014 +0900 @@ -65,6 +65,8 @@ private int rangeY = 256; // screenRange YPosition private int rangeWidth = 512; // screenRange Width private int rangeHeight = 256; // screenRange Height + private int i = 0; //chekc_delay use in to readandsend. + private int counter = 0; // add serialnum. public MyRfbProtoProxy() { rThread = new RequestScreenThread(this); @@ -266,7 +268,6 @@ * not context dependent, so no recompression is necessary. * @throws TransportException */ - public void readSendData(int dataLen, Reader is) throws TransportException { LinkedList<ByteBuffer> bufs = new LinkedList<ByteBuffer>(); ByteBuffer header = ByteBuffer.allocate(16); @@ -313,13 +314,23 @@ blen.flip(); bufs.addFirst(blen); bufs.addFirst(header); + /* - if(header.getShort(4)>1920) { + ByteBuffer serialNum = ByteBuffer.allocate(8); + serialNum.putLong(counter++); + serialNum.flip(); + bufs.addFirst(serialNum); + */ + /* + if(i++%50 == 0) { LinkedList<ByteBuffer> check = new LinkedList<ByteBuffer>(); - ByteBuffer test = ByteBuffer.allocate(4); + ByteBuffer test = ByteBuffer.allocate(8); ByteBuffer header2 = ByteBuffer.allocate(16); + header2.limit(16); header2.put((byte)11); - test.putInt(100); + header2.putInt(12, EncodingType.ZRLEE.getId()); + header2.position(0); + test.putLong(System.currentTimeMillis()); test.flip(); check.addFirst(test); check.addFirst(header2); @@ -612,5 +623,6 @@ buf.putShort(8, (short)512); buf.putShort(10, (short)256); } + }
--- a/src/main/java/jp/ac/u_ryukyu/treevnc/server/VncProxyService.java Mon Jan 27 16:35:20 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/treevnc/server/VncProxyService.java Sat Feb 01 06:43:27 2014 +0900 @@ -199,10 +199,13 @@ ServerSocket echoServer = new ServerSocket(10002); while (true) { clientSocket = echoServer.accept(); - BufferedReader is = new BufferedReader( - new InputStreamReader( - clientSocket.getInputStream())); + BufferedReader is = new BufferedReader(new InputStreamReader(clientSocket.getInputStream())); String newHostName = is.readLine(); + if("checkdelay".equals(newHostName)) { + Long delay = System.currentTimeMillis()-Long.parseLong(is.readLine()); + DataOutputStream os = new DataOutputStream(clientSocket.getOutputStream()); + os.writeBytes(String.valueOf(delay)+"\n"); + } else { //int width = Integer.parseInt(is.readLine()); //int height = Integer.parseInt(is.readLine()); // String screenSize = is.readLine(); @@ -213,6 +216,7 @@ continue; } clientSocket.close(); + } } } catch (IOException e) { continue; // log
--- a/src/viewer_swing/java/com/glavsoft/viewer/ConnectionPresenter.java Mon Jan 27 16:35:20 2014 +0900 +++ b/src/viewer_swing/java/com/glavsoft/viewer/ConnectionPresenter.java Sat Feb 01 06:43:27 2014 +0900 @@ -129,10 +129,10 @@ private void connect() { final ConnectionParams connectionParams = (ConnectionParams) getModel(CONNECTION_PARAMS_MODEL); // TODO check connectionWorkerFactory is init -// if(!cuiVersion) + if(!cuiVersion) networkConnectionWorker = connectionWorkerFactory.createNetworkConnectionWorker(); -// else -// networkConnectionWorker = new SwingNetworkConnectionWorker(null); + else + networkConnectionWorker = new SwingNetworkConnectionWorker(null); networkConnectionWorker.setConnectionParams(connectionParams); networkConnectionWorker.setPresenter(this); networkConnectionWorker.setHasSshSupport(hasSshSupport);
--- a/src/viewer_swing/java/com/glavsoft/viewer/swing/SwingViewerWindow.java Mon Jan 27 16:35:20 2014 +0900 +++ b/src/viewer_swing/java/com/glavsoft/viewer/swing/SwingViewerWindow.java Sat Feb 01 06:43:27 2014 +0900 @@ -811,9 +811,8 @@ }); kbdButtons.add(altButton); - JButton screenButton = buttonsBar.createButton("display", "change screen", new ActionListener() { - @Override + @Override public void actionPerformed(ActionEvent e) { try { viewer.getRfb().screenChangeRequest(); @@ -823,7 +822,7 @@ } }); kbdButtons.add(screenButton); - + ModifierButtonEventListener modifierButtonListener = new ModifierButtonEventListener(); modifierButtonListener.addButton(KeyEvent.VK_CONTROL, ctrlButton);