Mercurial > hg > Applications > TreeVNC
changeset 600:fb26a48b440d
blocking donw
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Mon, 17 Feb 2020 01:03:25 +0900 |
parents | 3b8de13a9c16 |
children | 62a86ceb89d5 |
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/BroadcastRFBListener.java |
diffstat | 3 files changed, 35 insertions(+), 20 deletions(-) [+] |
line wrap: on
line diff
--- a/src/main/java/com/glavsoft/rfb/encoding/decoder/ZRLEESender.java Sun Feb 16 18:26:03 2020 +0900 +++ b/src/main/java/com/glavsoft/rfb/encoding/decoder/ZRLEESender.java Mon Feb 17 01:03:25 2020 +0900 @@ -56,13 +56,8 @@ return; } } - if (rfb.multicastBlocking) { - ZRLEDecoder decoder = new ZRLEDecoder(); - decoder.multicastDecode(reader, renderer, rect, rfb); - } else { - byte[] bytes = new byte[rect.width * rect.height * renderer.getBytesPerPixel()]; - rfb.readSendData(dataLen, reader, bytes, rect); - } + byte[] bytes = new byte[rect.width * rect.height * renderer.getBytesPerPixel()]; + rfb.readSendData(dataLen, reader, bytes, rect); } private int getZrleLength(FramebufferUpdateRectangle rect, Reader reader)
--- a/src/main/java/com/glavsoft/rfb/protocol/ReceiverTask.java Sun Feb 16 18:26:03 2020 +0900 +++ b/src/main/java/com/glavsoft/rfb/protocol/ReceiverTask.java Mon Feb 17 01:03:25 2020 +0900 @@ -250,7 +250,7 @@ numberOfRectangles = reader.readUInt16(); this.numberOfRectangles = numberOfRectangles; if(numberOfRectangles > 3) { - System.out.println("numberofrectangle : " + numberOfRectangles); + // System.out.println("numberofrectangle : " + numberOfRectangles); if (rfb.getViewer().getUseMulticast()){ return; // Discard invalid packet } @@ -288,14 +288,11 @@ int width = reader.readUInt16(); int height = reader.readUInt16(); long flag = reader.readUInt32(); - - FramebufferUpdateRectangle screen = new FramebufferUpdateRectangle(x, y, width, height); screen.port = (int) id; screen.time = flag; screens.add(screen); System.out.println("screen " + id + ":" + "x=" + x + " y=" + y + "width=" + width + "height=" + height); - } return; } else if (rect.getEncodingType() == EncodingType.DESKTOP_SIZE) { @@ -379,7 +376,7 @@ Reader in = new Reader(new ByteArrayInputStream(c1.array())); try { if (getMessageId(in) != FRAMEBUFFER_UPDATE) { - ; + return; } in.readByte(); int numberOfRectangeles = in.readInt16(); @@ -426,6 +423,31 @@ } } + public void handleMulticastFrameBufferUpdate(ByteBuffer c1) { + FramebufferUpdateRectangle rect = new FramebufferUpdateRectangle(); + Reader in = new Reader(new ByteArrayInputStream(c1.array())); + try { + if (getMessageId(in) != FRAMEBUFFER_UPDATE) { + return; + } + in.readByte(); + int numberOfRectangeles = in.readInt16(); + ZRLEDecoder zdecoder = new ZRLEDecoder(); + Decoder decoder = zdecoder; + while (numberOfRectangeles-- > 0) { + rect.fill(in); + if (rect.getEncodingType() == EncodingType.ZRLEE) { + System.out.println(); + decoder.decode(in,renderer,rect); + if (rfb.getCuiVersion()) continue; + repaintController.repaintBitmap(rect); + } + } + } catch (Exception e) { + e.printStackTrace(); + } + } + private void compareBytes(ByteBuffer buf, byte[] bytes, int flushOffset, int flushEnd) { int span = flushEnd - flushOffset; int pos = buf.position();
--- a/src/main/java/jp/ac/u_ryukyu/treevnc/BroadcastRFBListener.java Sun Feb 16 18:26:03 2020 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/treevnc/BroadcastRFBListener.java Mon Feb 17 01:03:25 2020 +0900 @@ -51,8 +51,9 @@ } /** - * To find TreeVNC root, a client sends me a multicast, reply our address to him. - * It contains a port to receive, so multiple TREEVNC clients can run on a PC. + * Accept multicast framebufferupdate + * we should accept only from acceptable server + * some kind of signature */ private void rfbBroadcastLoop() { while (!stopFlag) { @@ -60,14 +61,11 @@ byte[] buf = new byte[BufSize]; DatagramPacket recvPacket = new DatagramPacket(buf, BufSize); soc.receive(recvPacket); - String hostname = recvPacket.getAddress().getHostAddress(); + // String hostname = recvPacket.getAddress().getHostAddress(); byte[] reply = recvPacket.getData(); - int len = recvPacket.getLength(); - boolean isTreeRoot = rfb.isTreeManager(); if (receiverTask != null) { - Reader reader = new Reader(new ByteArrayInputStream(reply)); - if (receiverTask.getMessageId(reader) == FRAMEBUFFER_UPDATE) { - receiverTask.framebufferUpdateMessage(reader); + if (reply[0] == FRAMEBUFFER_UPDATE) { + receiverTask.handleMulticastFrameBufferUpdate(ByteBuffer.wrap(reply)); } } } catch (Exception e) {