Mercurial > hg > Applications > TreeVNC
changeset 233:26b7c0a6d91b
fix indent.
author | oc |
---|---|
date | Fri, 10 Oct 2014 23:43:06 +0900 |
parents | 6ee4cdca104c |
children | 8479ad028ec7 |
files | src/main/java/com/glavsoft/rfb/protocol/Protocol.java src/main/java/com/glavsoft/rfb/protocol/ReceiverTask.java src/main/java/com/glavsoft/transport/Reader.java src/main/java/jp/ac/u_ryukyu/treevnc/TreeRFBProto.java |
diffstat | 4 files changed, 399 insertions(+), 399 deletions(-) [+] |
line wrap: on
line diff
--- a/src/main/java/com/glavsoft/rfb/protocol/Protocol.java Fri Oct 10 23:39:44 2014 +0900 +++ b/src/main/java/com/glavsoft/rfb/protocol/Protocol.java Fri Oct 10 23:43:06 2014 +0900 @@ -43,143 +43,143 @@ import jp.ac.u_ryukyu.treevnc.TreeRFBProto; public class Protocol implements ProtocolContext, IChangeSettingsListener { - private ProtocolState state; - private final Logger logger; - private final IPasswordRetriever passwordRetriever; - private final ProtocolSettings settings; - private int fbWidth; - private int fbHeight; - private PixelFormat pixelFormat; - private final Reader reader; - private final Writer writer; - private String remoteDesktopName; - private MessageQueue messageQueue; - private final DecodersContainer decoders; - private SenderTask senderTask; - private ReceiverTask receiverTask; - private IRfbSessionListener rfbSessionListener; - private IRepaintController repaintController; - private PixelFormat serverPixelFormat; - private Thread senderThread; - private Thread receiverThread; - private boolean isTight; - private String protocolVersion; - private byte[] initData; - private boolean isRetina = false; + private ProtocolState state; + private final Logger logger; + private final IPasswordRetriever passwordRetriever; + private final ProtocolSettings settings; + private int fbWidth; + private int fbHeight; + private PixelFormat pixelFormat; + private final Reader reader; + private final Writer writer; + private String remoteDesktopName; + private MessageQueue messageQueue; + private final DecodersContainer decoders; + private SenderTask senderTask; + private ReceiverTask receiverTask; + private IRfbSessionListener rfbSessionListener; + private IRepaintController repaintController; + private PixelFormat serverPixelFormat; + private Thread senderThread; + private Thread receiverThread; + private boolean isTight; + private String protocolVersion; + private byte[] initData; + private boolean isRetina = false; public Protocol(Reader reader, Writer writer, - IPasswordRetriever passwordRetriever, ProtocolSettings settings) { - this.reader = reader; - this.writer = writer; - this.passwordRetriever = passwordRetriever; - this.settings = settings; - decoders = new DecodersContainer(); - decoders.instantiateDecodersWhenNeeded(settings.encodings); - state = new HandshakeState(this); + IPasswordRetriever passwordRetriever, ProtocolSettings settings) { + this.reader = reader; + this.writer = writer; + this.passwordRetriever = passwordRetriever; + this.settings = settings; + decoders = new DecodersContainer(); + decoders.instantiateDecodersWhenNeeded(settings.encodings); + state = new HandshakeState(this); logger = Logger.getLogger(getClass().getName()); } - + - @Override - public void changeStateTo(ProtocolState state) { - this.state = state; - } + @Override + public void changeStateTo(ProtocolState state) { + this.state = state; + } - public void handshake() throws UnsupportedProtocolVersionException, UnsupportedSecurityTypeException, - AuthenticationFailedException, TransportException, FatalException { - while (state.next()) { - // continue; - } - this.messageQueue = new MessageQueue(); - } - - @Override - public PixelFormat getPixelFormat() { - return pixelFormat; - } + public void handshake() throws UnsupportedProtocolVersionException, UnsupportedSecurityTypeException, + AuthenticationFailedException, TransportException, FatalException { + while (state.next()) { + // continue; + } + this.messageQueue = new MessageQueue(); + } - @Override - public void setPixelFormat(PixelFormat pixelFormat) { - this.pixelFormat = pixelFormat; - if (repaintController != null) { - repaintController.setPixelFormat(pixelFormat); - } - } - - @Override - public String getRemoteDesktopName() { - return remoteDesktopName; - } - - @Override - public void setRemoteDesktopName(String name) { - remoteDesktopName = name; - } + @Override + public PixelFormat getPixelFormat() { + return pixelFormat; + } - @Override - public int getFbWidth() { - return fbWidth; - } + @Override + public void setPixelFormat(PixelFormat pixelFormat) { + this.pixelFormat = pixelFormat; + if (repaintController != null) { + repaintController.setPixelFormat(pixelFormat); + } + } - @Override - public void setFbWidth(int fbWidth) { - if(!isRetina) - this.fbWidth = fbWidth; - } - - @Override - public int getFbHeight() { - return fbHeight; - } + @Override + public String getRemoteDesktopName() { + return remoteDesktopName; + } - @Override - public byte[] getInitData() { - return initData; - } - - @Override - public void setInitData(byte[] initData) { - this.initData = initData; - } - - @Override - public void setFbHeight(int fbHeight) { - if(!isRetina) - this.fbHeight = fbHeight; - } + @Override + public void setRemoteDesktopName(String name) { + remoteDesktopName = name; + } - @Override - public IPasswordRetriever getPasswordRetriever() { - return passwordRetriever; - } + @Override + public int getFbWidth() { + return fbWidth; + } - @Override - public ProtocolSettings getSettings() { - return settings; - } + @Override + public void setFbWidth(int fbWidth) { + if(!isRetina) + this.fbWidth = fbWidth; + } @Override - public Writer getWriter() { - return writer; - } + public int getFbHeight() { + return fbHeight; + } + + @Override + public byte[] getInitData() { + return initData; + } - @Override - public Reader getReader() { - return reader; - } + @Override + public void setInitData(byte[] initData) { + this.initData = initData; + } + + @Override + public void setFbHeight(int fbHeight) { + if(!isRetina) + this.fbHeight = fbHeight; + } + + @Override + public IPasswordRetriever getPasswordRetriever() { + return passwordRetriever; + } - /** - * Following the server initialisation message it's up to the client to send - * whichever protocol messages it wants. Typically it will send a - * SetPixelFormat message and a SetEncodings message, followed by a - * FramebufferUpdateRequest. From then on the server will send - * FramebufferUpdate messages in response to the client's - * FramebufferUpdateRequest messages. The client should send - * FramebufferUpdateRequest messages with incremental set to true when it has - * finished processing one FramebufferUpdate and is ready to process another. - * With a fast client, the rate at which FramebufferUpdateRequests are sent - * should be regulated to avoid hogging the network. - */ + @Override + public ProtocolSettings getSettings() { + return settings; + } + + @Override + public Writer getWriter() { + return writer; + } + + @Override + public Reader getReader() { + return reader; + } + + /** + * Following the server initialisation message it's up to the client to send + * whichever protocol messages it wants. Typically it will send a + * SetPixelFormat message and a SetEncodings message, followed by a + * FramebufferUpdateRequest. From then on the server will send + * FramebufferUpdate messages in response to the client's + * FramebufferUpdateRequest messages. The client should send + * FramebufferUpdateRequest messages with incremental set to true when it has + * finished processing one FramebufferUpdate and is ready to process another. + * With a fast client, the rate at which FramebufferUpdateRequests are sent + * should be regulated to avoid hogging the network. + */ public void startNormalHandling(IRfbSessionListener rfbSessionListener, IRepaintController repaintController, ClipboardController clipboardController, TreeRFBProto rfb) @@ -190,32 +190,32 @@ decoders, this, rfb); startNormalHandling1(rfbSessionListener, repaintController, clipboardController); } - + public void startNormalHandling1(IRfbSessionListener rfbSessionListener, - IRepaintController repaintController, ClipboardController clipboardController) { - this.rfbSessionListener = rfbSessionListener; - this.repaintController = repaintController; -// if (settings.getColorDepth() == 0) { -// settings.setColorDepth(pixelFormat.depth); // the same the server sent when not initialized yet -// } - serverPixelFormat = pixelFormat; + IRepaintController repaintController, ClipboardController clipboardController) { + this.rfbSessionListener = rfbSessionListener; + this.repaintController = repaintController; + // if (settings.getColorDepth() == 0) { + // settings.setColorDepth(pixelFormat.depth); // the same the server sent when not initialized yet + // } + serverPixelFormat = pixelFormat; correctServerPixelFormat(); - setPixelFormat(createPixelFormat(settings)); - sendMessage(new SetPixelFormatMessage(pixelFormat)); - logger.fine("sent: " + pixelFormat); + setPixelFormat(createPixelFormat(settings)); + sendMessage(new SetPixelFormatMessage(pixelFormat)); + logger.fine("sent: " + pixelFormat); - sendSupportedEncodingsMessage(settings); - settings.addListener(this); // to support pixel format (color depth), and encodings changes - settings.addListener(repaintController); - sendRefreshMessage(); - senderTask = new SenderTask(messageQueue, writer, this); - senderThread = new Thread(senderTask, "RfbSenderTask"); - senderThread.start(); - decoders.resetDecoders(); + sendSupportedEncodingsMessage(settings); + settings.addListener(this); // to support pixel format (color depth), and encodings changes + settings.addListener(repaintController); + sendRefreshMessage(); + senderTask = new SenderTask(messageQueue, writer, this); + senderThread = new Thread(senderTask, "RfbSenderTask"); + senderThread.start(); + decoders.resetDecoders(); - receiverThread = new Thread(receiverTask, "RfbReceiverTask"); - receiverThread.start(); - } + receiverThread = new Thread(receiverTask, "RfbReceiverTask"); + receiverThread.start(); + } private void correctServerPixelFormat() { // correct true color flag - we don't support color maps, so always set it up @@ -233,89 +233,89 @@ } @Override - public void sendMessage(ClientToServerMessage message) { - messageQueue.put(message); - } + public void sendMessage(ClientToServerMessage message) { + messageQueue.put(message); + } - private void sendSupportedEncodingsMessage(ProtocolSettings settings) { - decoders.instantiateDecodersWhenNeeded(settings.encodings); - SetEncodingsMessage encodingsMessage = new SetEncodingsMessage(settings.encodings); - sendMessage(encodingsMessage); - logger.fine("sent: " + encodingsMessage.toString()); - } + private void sendSupportedEncodingsMessage(ProtocolSettings settings) { + decoders.instantiateDecodersWhenNeeded(settings.encodings); + SetEncodingsMessage encodingsMessage = new SetEncodingsMessage(settings.encodings); + sendMessage(encodingsMessage); + logger.fine("sent: " + encodingsMessage.toString()); + } - /** - * create pixel format by bpp - */ - private PixelFormat createPixelFormat(ProtocolSettings settings) { - int serverBigEndianFlag = serverPixelFormat.bigEndianFlag; - switch (settings.getColorDepth()) { - case ProtocolSettings.COLOR_DEPTH_24: - return PixelFormat.create24bitColorDepthPixelFormat(serverBigEndianFlag); - case ProtocolSettings.COLOR_DEPTH_16: - return PixelFormat.create16bitColorDepthPixelFormat(serverBigEndianFlag); - case ProtocolSettings.COLOR_DEPTH_8: - return PixelFormat.create8bitColorDepthBGRPixelFormat(serverBigEndianFlag); - case ProtocolSettings.COLOR_DEPTH_6: - return PixelFormat.create6bitColorDepthPixelFormat(serverBigEndianFlag); - case ProtocolSettings.COLOR_DEPTH_3: - return PixelFormat.create3bppPixelFormat(serverBigEndianFlag); - case ProtocolSettings.COLOR_DEPTH_SERVER_SETTINGS: - return serverPixelFormat; - default: - // unsupported bpp, use default - return PixelFormat.create24bitColorDepthPixelFormat(serverBigEndianFlag); - } - } + /** + * create pixel format by bpp + */ + private PixelFormat createPixelFormat(ProtocolSettings settings) { + int serverBigEndianFlag = serverPixelFormat.bigEndianFlag; + switch (settings.getColorDepth()) { + case ProtocolSettings.COLOR_DEPTH_24: + return PixelFormat.create24bitColorDepthPixelFormat(serverBigEndianFlag); + case ProtocolSettings.COLOR_DEPTH_16: + return PixelFormat.create16bitColorDepthPixelFormat(serverBigEndianFlag); + case ProtocolSettings.COLOR_DEPTH_8: + return PixelFormat.create8bitColorDepthBGRPixelFormat(serverBigEndianFlag); + case ProtocolSettings.COLOR_DEPTH_6: + return PixelFormat.create6bitColorDepthPixelFormat(serverBigEndianFlag); + case ProtocolSettings.COLOR_DEPTH_3: + return PixelFormat.create3bppPixelFormat(serverBigEndianFlag); + case ProtocolSettings.COLOR_DEPTH_SERVER_SETTINGS: + return serverPixelFormat; + default: + // unsupported bpp, use default + return PixelFormat.create24bitColorDepthPixelFormat(serverBigEndianFlag); + } + } - @Override - public void settingsChanged(SettingsChangedEvent e) { - ProtocolSettings settings = (ProtocolSettings) e.getSource(); - if (settings.isChangedEncodings()) { - sendSupportedEncodingsMessage(settings); - } - if (settings.isChangedColorDepth() && receiverTask != null) { - receiverTask.queueUpdatePixelFormat(createPixelFormat(settings)); - } - } + @Override + public void settingsChanged(SettingsChangedEvent e) { + ProtocolSettings settings = (ProtocolSettings) e.getSource(); + if (settings.isChangedEncodings()) { + sendSupportedEncodingsMessage(settings); + } + if (settings.isChangedColorDepth() && receiverTask != null) { + receiverTask.queueUpdatePixelFormat(createPixelFormat(settings)); + } + } - @Override - public void sendRefreshMessage() { - sendMessage(new FramebufferUpdateRequestMessage(0, 0, fbWidth, fbHeight, false)); - logger.fine("sent: full FB Refresh"); - } + @Override + public void sendRefreshMessage() { + sendMessage(new FramebufferUpdateRequestMessage(0, 0, fbWidth, fbHeight, false)); + logger.fine("sent: full FB Refresh"); + } - @Override - public void cleanUpSession(String message) { - cleanUpSession(); - if (message!=null) - rfbSessionListener.rfbSessionStopped(message); - } + @Override + public void cleanUpSession(String message) { + cleanUpSession(); + if (message!=null) + rfbSessionListener.rfbSessionStopped(message); + } - public synchronized void cleanUpSession() { - if (senderTask != null) { - senderTask.stopTask(); - try { - senderThread.join(1000); - } catch (InterruptedException e) { - // nop - } - senderTask = null; - } - stopReceiverTask(); - } + public synchronized void cleanUpSession() { + if (senderTask != null) { + senderTask.stopTask(); + try { + senderThread.join(1000); + } catch (InterruptedException e) { + // nop + } + senderTask = null; + } + stopReceiverTask(); + } - @Override + @Override public void stopReceiverTask() { if (receiverTask != null) { - receiverTask.stopTask(); - try { - receiverThread.join(); - } catch (InterruptedException e) { - // nop - } - receiverTask = null; - } + receiverTask.stopTask(); + try { + receiverThread.join(); + } catch (InterruptedException e) { + // nop + } + receiverTask = null; + } } @Override @@ -339,7 +339,7 @@ } - + @Override public void resetDecoder() {
--- a/src/main/java/com/glavsoft/rfb/protocol/ReceiverTask.java Fri Oct 10 23:39:44 2014 +0900 +++ b/src/main/java/com/glavsoft/rfb/protocol/ReceiverTask.java Fri Oct 10 23:43:06 2014 +0900 @@ -217,11 +217,11 @@ public void framebufferUpdateMessage() throws CommonException, UnsupportedEncodingException { reader.readByte(); // padding int numberOfRectangles = reader.readUInt16(); - + 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) { @@ -268,13 +268,13 @@ reader.reset(); rfb.readSendData(length + 52, 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()); } - + if (!rfb.isTreeManager()) return; synchronized (this) { if (needSendPixelFormat) { @@ -292,11 +292,11 @@ 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) {
--- a/src/main/java/com/glavsoft/transport/Reader.java Fri Oct 10 23:39:44 2014 +0900 +++ b/src/main/java/com/glavsoft/transport/Reader.java Fri Oct 10 23:43:06 2014 +0900 @@ -31,184 +31,184 @@ import java.nio.charset.Charset; public class Reader { - final static Charset ISO_8859_1 = Charset.forName("ISO-8859-1"); - final static Charset UTF8 = Charset.forName("UTF-8"); - private final DataInputStream is; + final static Charset ISO_8859_1 = Charset.forName("ISO-8859-1"); + final static Charset UTF8 = Charset.forName("UTF-8"); + private final DataInputStream is; - public Reader(InputStream is) { - this.is = new DataInputStream(new BufferedInputStream(is)); - } + public Reader(InputStream is) { + this.is = new DataInputStream(new BufferedInputStream(is)); + } - public byte readByte() throws TransportException { - try { - byte readByte = is.readByte(); - return readByte; - } catch (EOFException e) { - throw new ClosedConnectionException(e); - } catch (IOException e) { - throw new TransportException("Cannot read byte", e); - } - } + public byte readByte() throws TransportException { + try { + byte readByte = is.readByte(); + return readByte; + } catch (EOFException e) { + throw new ClosedConnectionException(e); + } catch (IOException e) { + throw new TransportException("Cannot read byte", e); + } + } - public int readUInt8() throws TransportException { - return readByte() & 0x0ff; - } + public int readUInt8() throws TransportException { + return readByte() & 0x0ff; + } - public int readUInt16() throws TransportException { - return readInt16() & 0x0ffff; - } + public int readUInt16() throws TransportException { + return readInt16() & 0x0ffff; + } - public short readInt16() throws TransportException { - try { - short readShort = is.readShort(); - return readShort; - } catch (EOFException e) { - throw new ClosedConnectionException(e); - } catch (IOException e) { - throw new TransportException("Cannot read int16", e); - } - } + public short readInt16() throws TransportException { + try { + short readShort = is.readShort(); + return readShort; + } catch (EOFException e) { + throw new ClosedConnectionException(e); + } catch (IOException e) { + throw new TransportException("Cannot read int16", e); + } + } - public long readUInt32() throws TransportException { - return readInt32() & 0xffffffffL; - } + public long readUInt32() throws TransportException { + return readInt32() & 0xffffffffL; + } - public int readInt32() throws TransportException { - try { - int readInt = is.readInt(); - return readInt; - } catch (EOFException e) { - throw new ClosedConnectionException(e); - } catch (IOException e) { - throw new TransportException("Cannot read int32", e); - } - } + public int readInt32() throws TransportException { + try { + int readInt = is.readInt(); + return readInt; + } catch (EOFException e) { + throw new ClosedConnectionException(e); + } catch (IOException e) { + throw new TransportException("Cannot read int32", e); + } + } - public long readInt64() throws TransportException { - try { - return is.readLong(); - } catch (EOFException e) { - throw new ClosedConnectionException(e); - } catch (IOException e) { - throw new TransportException("Cannot read int32", e); - } - } + public long readInt64() throws TransportException { + try { + return is.readLong(); + } catch (EOFException e) { + throw new ClosedConnectionException(e); + } catch (IOException e) { + throw new TransportException("Cannot read int32", e); + } + } - /** - * Read string by it length. - * Use this method only when sure no character accept ASCII will be read. - * Use readBytes and character encoding conversion instead. - * - * @return String read - */ - public String readString(int length) throws TransportException { - return new String(readBytes(length)); - } + /** + * Read string by it length. + * Use this method only when sure no character accept ASCII will be read. + * Use readBytes and character encoding conversion instead. + * + * @return String read + */ + public String readString(int length) throws TransportException { + return new String(readBytes(length)); + } - /** - * Read 32-bit string length and then string themself by it length - * Use this method only when sure no character accept ASCII will be read. - * Use readBytes and character encoding conversion instead or {@link #readUtf8String} method - * when utf-8 encoding needed. - * - * @return String read - * @throws TransportException - */ - public String readString() throws TransportException { - // unset most significant (sign) bit 'cause InputStream#readFully reads - // [int] length bytes from stream. Change when really need read string more - // than 2147483647 bytes length - int length = readInt32() & Integer.MAX_VALUE; - return readString(length); - } + /** + * Read 32-bit string length and then string themself by it length + * Use this method only when sure no character accept ASCII will be read. + * Use readBytes and character encoding conversion instead or {@link #readUtf8String} method + * when utf-8 encoding needed. + * + * @return String read + * @throws TransportException + */ + public String readString() throws TransportException { + // unset most significant (sign) bit 'cause InputStream#readFully reads + // [int] length bytes from stream. Change when really need read string more + // than 2147483647 bytes length + int length = readInt32() & Integer.MAX_VALUE; + return readString(length); + } - /** - * Read 32-bit string length and then string themself by it length - * Assume UTF-8 character encoding used - * - * @return String read - * @throws TransportException - */ - public String readUtf8String() throws TransportException { - // unset most significant (sign) bit 'cause InputStream#readFully reads - // [int] length bytes from stream. Change when really need read string more - // than 2147483647 bytes length - int length = readInt32() & Integer.MAX_VALUE; - return new String(readBytes(length)); - } + /** + * Read 32-bit string length and then string themself by it length + * Assume UTF-8 character encoding used + * + * @return String read + * @throws TransportException + */ + public String readUtf8String() throws TransportException { + // unset most significant (sign) bit 'cause InputStream#readFully reads + // [int] length bytes from stream. Change when really need read string more + // than 2147483647 bytes length + int length = readInt32() & Integer.MAX_VALUE; + return new String(readBytes(length)); + } - public byte[] readBytes(int length) throws TransportException { - byte b[] = new byte[length]; - return readBytes(b, 0, length); - } + public byte[] readBytes(int length) throws TransportException { + byte b[] = new byte[length]; + return readBytes(b, 0, length); + } - public byte[] readBytes(byte[] b, int offset, int length) throws TransportException { - try { - is.readFully(b, offset, length); - return b; - } catch (EOFException e) { - throw new ClosedConnectionException(e); - } catch (IOException e) { - throw new TransportException("Cannot read " + length - + " bytes array", e); - } - } + public byte[] readBytes(byte[] b, int offset, int length) throws TransportException { + try { + is.readFully(b, offset, length); + return b; + } catch (EOFException e) { + throw new ClosedConnectionException(e); + } catch (IOException e) { + throw new TransportException("Cannot read " + length + + " bytes array", e); + } + } - public byte[] readBytes(byte[] b) throws TransportException { - byte[] result = readBytes(b, 0, b.length); - return result; - } + public byte[] readBytes(byte[] b) throws TransportException { + byte[] result = readBytes(b, 0, b.length); + return result; + } - public void reset() throws TransportException { - try { - is.reset(); - } catch (IOException e) { - throw new TransportException("Cannot reset", e); - } - } + public void reset() throws TransportException { + try { + is.reset(); + } catch (IOException e) { + throw new TransportException("Cannot reset", e); + } + } - public void mark(int readLimit) { - is.mark(readLimit); - } + public void mark(int readLimit) { + is.mark(readLimit); + } - public int readByte(byte[] b) throws IOException { - int result = 0; - result = is.read(b); - return result; - } + public int readByte(byte[] b) throws IOException { + int result = 0; + result = is.read(b); + return result; + } - public void close() throws TransportException { - try { - is.close(); - } catch (IOException e) { - throw new TransportException("Cannot close", e); - } - } + public void close() throws TransportException { + try { + is.close(); + } catch (IOException e) { + throw new TransportException("Cannot close", e); + } + } - public void read(byte[] b) throws TransportException { - try { - is.read(b); - } catch (IOException e) { - throw new TransportException("Cannot read", e); - } - } + public void read(byte[] b) throws TransportException { + try { + is.read(b); + } catch (IOException e) { + throw new TransportException("Cannot read", e); + } + } - public int skypBytes(int n) throws TransportException { - try { - int r = is.skipBytes(n); - return r; - } catch (IOException e) { - throw new TransportException("Cannot skipBytes", e); - } - } + public int skypBytes(int n) throws TransportException { + try { + int r = is.skipBytes(n); + return r; + } catch (IOException e) { + throw new TransportException("Cannot skipBytes", e); + } + } - public void skip(int length) throws TransportException { - try { - is.skipBytes(length); - } catch (EOFException e) { - throw new ClosedConnectionException(e); - } catch (IOException e) { - throw new TransportException("Cannot skip " + length + " bytes", e); - } - } + public void skip(int length) throws TransportException { + try { + is.skipBytes(length); + } catch (EOFException e) { + throw new ClosedConnectionException(e); + } catch (IOException e) { + throw new TransportException("Cannot skip " + length + " bytes", e); + } + } }
--- a/src/main/java/jp/ac/u_ryukyu/treevnc/TreeRFBProto.java Fri Oct 10 23:39:44 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/treevnc/TreeRFBProto.java Fri Oct 10 23:43:06 2014 +0900 @@ -171,7 +171,7 @@ } else if (b[0] == ClientToServerMessage.CHECK_DELAY_REPLY) { ByteBuffer buf = ByteBuffer.wrap(b); buf.order(ByteOrder.BIG_ENDIAN); -// getNodeNum(port, hostname, localhostname); + // getNodeNum(port, hostname, localhostname); Long time = buf.getLong(2); Long delay = System.currentTimeMillis() - time; System.out.println("delay = " + delay); @@ -564,8 +564,8 @@ header.limit(16); if (header.get(0) == FramebufferUpdate) { int encoding = header.getInt(12); - - + + if (i%20 == 0) { LinkedList<ByteBuffer> checkdelay = new LinkedList<ByteBuffer>(); long time = System.currentTimeMillis(); @@ -575,9 +575,9 @@ checkdelay.add(new UpdateRectangleMessage(0, 0, 0, 0, time, port, localhost, EncodingType.CHECK_DELAY).getMessage()); this.addSerialNumber(checkdelay); multicastqueue.put(checkdelay); - } i++; - - + } i++; + + if (encoding == EncodingType.ZRLE.getId() || encoding == EncodingType.ZLIB.getId()) { // recompress into ZREE @@ -617,8 +617,8 @@ } return; } - - + + // ZRLEE is already compressed bufs.add(header); if (dataLen > 16) { @@ -629,11 +629,11 @@ } this.addSerialNumber(bufs); multicastqueue.put(bufs); - - + + - - + + return; } // It may be compressed. We can inflate here to avoid repeating clients @@ -756,15 +756,15 @@ public int getNodeNum(int port, String hostname, String localhostname) { int nodeNum = 0; - - + + for (Iterator<TreeVNCNode> i = nodeList.iterator(); i.hasNext();) { TreeVNCNode tvn = (TreeVNCNode)i.next(); System.out.println("port = " + tvn.port + ", hostname = " + tvn.hostname + ", localhostname = " + tvn.localhostname + ", nodeNumber" + tvn.treeNum); } - + return nodeNum; - + } }