Mercurial > hg > Applications > TreeVNC
diff src/main/java/jp/ac/u_ryukyu/treevnc/MyRfbProto.java @ 130:1f6bfaa3281b
root selection panel
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Sat, 07 Jun 2014 00:03:13 +0900 |
parents | a6dc674546f2 |
children | 95f53663295c |
line wrap: on
line diff
--- a/src/main/java/jp/ac/u_ryukyu/treevnc/MyRfbProto.java Fri Jun 06 21:12:45 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/treevnc/MyRfbProto.java Sat Jun 07 00:03:13 2014 +0900 @@ -82,13 +82,31 @@ return false; } + /** + * handle TreeVNC Command + * @param b 12byte header ( command 4byte, length 4byte, port 4byte, option String ) + * @param is + * @param os + */ private void treeVncCommand(byte[] b, Reader is, Writer os) { ByteBuffer buf = ByteBuffer.wrap(b); - int command = buf.get()&0xff; - + int command = buf.get()&0xff; + buf.position(buf.position()+3); + int length = buf.getInt(); + int port = buf.getInt(); + String hostname = null; + if (length>12) { + byte namebuf[] = new byte[length-12]; + try { + is.readBytes(namebuf); + } catch (TransportException e) { + return; + } + hostname = new String(namebuf); + } switch (command) { case ProtocolContext.FIND_ROOT_REPLY : - handleFindRootReply(buf); + handleFindRootReply(port,hostname); break; case ProtocolContext.FIND_ROOT : case ProtocolContext.WHERE_TO_CONNECT : @@ -97,18 +115,35 @@ } } - private void handleFindRootReply(ByteBuffer buf) { - String hostname; - int port; + /** + * Accept FIND_ROOT_REPLY + * add replying TreeVNC root to RootSelection Panel + * @param port + * @param hostname + */ + private void handleFindRootReply(int port, String hostname) { viewer.addHostToSelectionPanel(port, hostname); - } + /** + * handle new client accept + * it also handle TreeVNC Command + * @param acceptThread + * @param newCli + * @param os + * @param is + * @throws IOException + * @throws TransportException + */ public void newClient(AcceptThread acceptThread, final Socket newCli, final Writer os, final Reader is) throws IOException, TransportException { - if (initialConnection(os, is)) return; // + if (initialConnection(os, is)) { + // TreeVNC command is processed + newCli.close(); + return; + } final int myId = clients; final MulticastQueue.Client<LinkedList<ByteBuffer>> c = multicastqueue.newClient();