Mercurial > hg > Applications > TreeVNC
diff src/main/java/jp/ac/u_ryukyu/treevnc/MyRfbProto.java @ 157:7cea8789387b
thread base command listening loop
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Fri, 13 Jun 2014 23:12:28 +0900 |
parents | e68dfd1972ac |
children | b9052986bbb3 |
line wrap: on
line diff
--- a/src/main/java/jp/ac/u_ryukyu/treevnc/MyRfbProto.java Fri Jun 13 19:18:47 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/treevnc/MyRfbProto.java Fri Jun 13 23:12:28 2014 +0900 @@ -21,7 +21,6 @@ import com.glavsoft.rfb.encoding.EncodingType; import com.glavsoft.rfb.protocol.Protocol; import com.glavsoft.rfb.protocol.ProtocolContext; -import com.glavsoft.rfb.protocol.state.HandshakeState; import com.glavsoft.transport.Reader; import com.glavsoft.transport.Writer; import com.glavsoft.viewer.ViewerInterface; @@ -32,7 +31,6 @@ final static int CheckDelay = 11; protected final static int FramebufferUpdate = 0; protected ProtocolContext context; - protected final static String versionMsg_3_856 = "RFB 003.856\n"; private int clients = 0; public MulticastQueue<LinkedList<ByteBuffer>> multicastqueue = new MulticastQueue<LinkedList<ByteBuffer>>(); private RequestScreenThread rThread; @@ -41,48 +39,25 @@ private boolean cuiVersion; private long counter = 0; // packet serial number TreeVncProtocol treeProtocol; - public TreeVncCommand treeVncCommand; public ServerSocket servSock; private boolean permitChangeScreen = true; private static final int INFLATE_BUFSIZE = 1024 * 100; private Inflater inflater = new Inflater(); private Deflater deflater = new Deflater(); - private VncProxyService viewer; + VncProxyService viewer; public MyRfbProto() { rThread = new RequestScreenThread(this); - treeVncCommand = new TreeVncCommand(null,this,null); } public void setVncProxy(VncProxyService viewer) { this.viewer = viewer; - treeVncCommand.setViewer(viewer); } abstract public boolean isRoot() ; - public boolean initialConnection(final Writer os, final Reader is, Socket connection) - throws IOException, TransportException { - /** - * initial connection of RFB protocol - */ - sendRfbVersion(os); - byte[] b; - if ((b = readVersionMsg(is, os))!=null) { - String myHostAddress = connection.getLocalAddress().getHostAddress(); - treeVncCommand.treeVncCommand(b,is,os,myHostAddress); - return true; - } - sendSecurityType(os); - readSecType(is); - sendSecResult(os); - readClientInit(is); - sendInitData(os); - return false; - } - /** * handle new client accept * it also handle TreeVNC Command @@ -93,25 +68,8 @@ * @throws IOException * @throws TransportException */ - public void newClient(TreeVncCommandCannelListener acceptThread, final Socket newCli,final Writer os, final Reader is) { + public void newClient(final Socket newCli,final Writer os, final Reader is) { - try { - if (initialConnection(os, is, newCli)) { - // TreeVNC command is processed - newCli.close(); - return; - } - } catch (Exception e) { - try { - System.out.println("new client faild :" + e.getMessage()); - newCli.close(); - return; - } catch (IOException e1) { - System.out.println("new client close faild"); - return; - } - } - final int myId = clients; final MulticastQueue.Client<LinkedList<ByteBuffer>> c = multicastqueue.newClient(); final AtomicInteger writerRunning = new AtomicInteger(); @@ -271,6 +229,7 @@ new Thread(sender, "writer-to-lower-node").start(); } + public boolean permitChangeScreen() { @@ -286,77 +245,6 @@ rThread.reStart(); } - private void sendRfbVersion(Writer writer) throws IOException, TransportException { - writer.write(versionMsg_3_856.getBytes()); - } - - private byte[] readVersionMsg(Reader reader, Writer writer) throws IOException, TransportException { - - byte[] b = new byte[HandshakeState.PROTOCOL_STRING_LENGTH ]; - - reader.readBytes(b); - - if ((b[0]&0xff)>=220) return b; // TreeVNC extention command. - if ((b[0] != 'R') || (b[1] != 'F') || (b[2] != 'B') || (b[3] != ' ') - || (b[4] < '0') || (b[4] > '9') || (b[5] < '0') || (b[5] > '9') - || (b[6] < '0') || (b[6] > '9') || (b[7] != '.') - || (b[8] < '0') || (b[8] > '9') || (b[9] < '0') || (b[9] > '9') - || (b[10] < '0') || (b[10] > '9') || (b[11] != '\n')) { - throw new IOException("this is not an RFB server"); - } - - int rfbMajor = (b[4] - '0') * 100 + (b[5] - '0') * 10 + (b[6] - '0'); -// int rfbMinor = (b[8] - '0') * 100 + (b[9] - '0') * 10 + (b[10] - '0'); - - if (rfbMajor < 3) { - throw new IOException( - "RFB server does not support protocol version 3"); - } - - return null; - } - - - private void readSecType(Reader reader) throws TransportException { - byte[] b = new byte[1]; - reader.read(b); - } - - private void sendSecurityType(Writer os) throws TransportException { - // number-of-security-types - os.writeInt(1); - // security-types - // 1:None - os.writeInt(1); - - /* - * os.write(4); os.write(30); os.write(31); os.write(32); os.write(35); - * os.flush(); - */ - } - - private void sendSecResult(Writer os) throws TransportException { - ByteBuffer b = ByteBuffer.allocate(4); - b.order(ByteOrder.BIG_ENDIAN); - b.putInt(0); - os.write(b.array()); - } - - private void readClientInit(Reader in) throws TransportException { - byte[] b = new byte[0]; - in.readBytes(b); - } - - byte initData[] = {7, -128, 4, 56, 32, 24, 0, 1, 0, -1, 0, -1, 0, -1, 16, 8, 0, 0, 0, 0, 0, 0, 0, 7, 102, 105, 114, 101, 102, 108, 121}; - private void sendInitData(Writer os) throws TransportException { - // In case of "-d" we have no context - if (context != null){ - os.write(context.getInitData()); - } else { - // Send dummy data - os.write(initData); - } - } public void setProtocolContext(Protocol workingProtocol) { context = workingProtocol; @@ -406,7 +294,6 @@ public void setEcho(TreeVncProtocol _echo) { treeProtocol = _echo; - treeVncCommand.setVncProtocol(_echo); } public void setViewer(ViewerInterface v) {