Mercurial > hg > Applications > TreeVNC
changeset 107:660b296d4f75
send change screen command throw the tree.
author | oc |
---|---|
date | Fri, 23 May 2014 17:56:42 +0900 |
parents | 01c0fd20c0b4 |
children | 1bceae0f5bd3 |
files | src/main/java/com/glavsoft/rfb/client/ClientToServerMessage.java src/main/java/jp/ac/u_ryukyu/treevnc/MostRecentMultiCast.java src/main/java/jp/ac/u_ryukyu/treevnc/MyRfbProto.java src/main/java/jp/ac/u_ryukyu/treevnc/ScreenChangeRequest.java src/main/java/jp/ac/u_ryukyu/treevnc/server/VncProxyService.java src/viewer_swing/java/com/glavsoft/viewer/swing/SwingViewerWindow.java |
diffstat | 6 files changed, 87 insertions(+), 66 deletions(-) [+] |
line wrap: on
line diff
--- a/src/main/java/com/glavsoft/rfb/client/ClientToServerMessage.java Fri May 23 11:25:43 2014 +0900 +++ b/src/main/java/com/glavsoft/rfb/client/ClientToServerMessage.java Fri May 23 17:56:42 2014 +0900 @@ -34,6 +34,7 @@ byte KEY_EVENT = 4; byte POINTER_EVENT = 5; byte CLIENT_CUT_TEXT = 6; + byte SERVER_CHANGE_REQUEST = (byte) 240; // TreeVNC extension void send(Writer writer) throws TransportException; }
--- a/src/main/java/jp/ac/u_ryukyu/treevnc/MostRecentMultiCast.java Fri May 23 11:25:43 2014 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,27 +0,0 @@ -package jp.ac.u_ryukyu.treevnc; - -import java.util.LinkedList; - - -public class MostRecentMultiCast<T> extends MulticastQueue<T> { - - LinkedList<Node<T>> alive; - int count = 0; - MostRecentMultiCast(int limit) { - count = limit; - this.alive = new LinkedList<Node<T>>(); - } - - @Override - public synchronized void put(T item) - { - Node<T> next = new Node<T>(item); - tail.set(next); - tail = next; - alive.addLast(next); - if (alive.size()>count) { - Node<T> old = alive.getFirst(); - old.clear(); - } - } -}
--- a/src/main/java/jp/ac/u_ryukyu/treevnc/MyRfbProto.java Fri May 23 11:25:43 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/treevnc/MyRfbProto.java Fri May 23 17:56:42 2014 +0900 @@ -1,6 +1,5 @@ package jp.ac.u_ryukyu.treevnc; -import java.io.DataOutputStream; import java.io.IOException; import java.net.Socket; import java.nio.ByteBuffer; @@ -12,6 +11,7 @@ import jp.ac.u_ryukyu.treevnc.server.VncProxyService; import com.glavsoft.exceptions.TransportException; +import com.glavsoft.rfb.client.ClientToServerMessage; import com.glavsoft.rfb.encoding.EncodingType; import com.glavsoft.rfb.protocol.Protocol; import com.glavsoft.rfb.protocol.ProtocolContext; @@ -34,12 +34,17 @@ public int acceptPort; protected boolean readyReconnect = false; private boolean cuiVersion; - private long counter = 0; // packet serial number - + private long counter = 0; // packet serial number + private VncProxyService viewer = null; + public MyRfbProto() { rThread = new RequestScreenThread(this); } + + public void setViewer(VncProxyService viewer) { + this.viewer = viewer; + } public boolean isRoot() { return false; @@ -97,9 +102,11 @@ }; new Thread(timer, "timer-discard-multicastqueue").start(); /** - * discard all incoming from clients + * send all incoming from clients to parent. */ final Runnable reader = new Runnable() { + + public void run() { byte b[] = new byte[4096]; for (;;) { @@ -107,6 +114,24 @@ int c = is.readByte(b); if (c <= 0) throw new IOException(); + if (isRoot()) { + if (b[0] == ClientToServerMessage.SERVER_CHANGE_REQUEST) { + if (permitChangeScreen()) { + int length = Integer.parseInt(new String(b, 4, 4)); + if (length == 0) + continue; + String newHostName = new String(b, 8, length); + // please remove these numbers. + if (viewer != null) { + viewer.changeVNCServer(newHostName, 3200, 1980); + } + } else { + continue; + } + } + } else { + context.getWriter().write(b); + } // System.out.println("client read "+c); } catch (Exception e) { try { @@ -122,6 +147,11 @@ } } } + + private boolean permitChangeScreen() { + // TODO Auto-generated method stub + return false; + } }; /** * send packets to a client @@ -231,14 +261,8 @@ return rfbMinor; } - public void screenChangeRequest() throws IOException { - Socket echoSocket = new Socket(proxyAddr, 10002); - DataOutputStream os = new DataOutputStream(echoSocket.getOutputStream()); - os.writeBytes(echo.getMyAddress()+"\n"); - //os.writeBytes(String.valueOf(echo.client.getFrameWidth())+"\n"); temp comment out for rebuild - //os.writeBytes(String.valueOf(echo.client.getFrameHeight())+"\n"); temp comment out for rebuild - os.close(); - echoSocket.close(); + public void screenChangeRequest() throws TransportException { + new ScreenChangeRequest(echo.getMyAddress().getBytes()).send(context.getWriter()); } private void sendProxyFlag(Writer writer) throws TransportException { @@ -294,7 +318,6 @@ } 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}; - protected VncProxyService waiter; private void sendInitData(Writer os) throws TransportException { // In case of "-d" we have no context if (context != null){
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/jp/ac/u_ryukyu/treevnc/ScreenChangeRequest.java Fri May 23 17:56:42 2014 +0900 @@ -0,0 +1,38 @@ +package jp.ac.u_ryukyu.treevnc; + +import com.glavsoft.exceptions.TransportException; +import com.glavsoft.rfb.client.ClientToServerMessage; +import com.glavsoft.transport.Writer; + + /** + * ClientCutText + * The client has new ISO 8859-1 (Latin-1) text in its cut buffer. Ends of lines are repre- + * sented by the linefeed / newline character (value 10) alone. No carriage-return (value + * 13) is needed. There is currently no way to transfer text outside the Latin-1 character + * set. + * 1 - U8 - 6 + * 3 - - padding + * 4 - U32 - length + * length - U8 array - text + */ + public class ScreenChangeRequest implements ClientToServerMessage { + private final byte [] bytes; + + public ScreenChangeRequest(byte[] bytes) { + this.bytes = bytes; + } + + @Override + public void send(Writer writer) throws TransportException { + writer.write(SERVER_CHANGE_REQUEST); + writer.writeByte(0); writer.writeInt16(0); // padding + writer.write(bytes.length); + writer.write(bytes); // TODO: [dime] convert 'text' String to byte arrya using right charset + writer.flush(); + } + + @Override + public String toString() { + return "ClientCutTextMessage: [length: " + bytes.length +", text: ...]"; + } + } \ No newline at end of file
--- a/src/main/java/jp/ac/u_ryukyu/treevnc/server/VncProxyService.java Fri May 23 11:25:43 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/treevnc/server/VncProxyService.java Fri May 23 17:56:42 2014 +0900 @@ -78,6 +78,7 @@ private void initProxy1(String hostName) { myRfb = new MyRfbProtoProxy(); + myRfb.setViewer(this); clients = new AcceptClient(); isApplet = false; setIsTreeVNC(true); @@ -182,21 +183,11 @@ Long delay = System.currentTimeMillis()-Long.parseLong(is.readLine()); DataOutputStream os = new DataOutputStream(clientSocket.getOutputStream()); os.writeBytes(String.valueOf(delay)+"\n"); - } else { - System.out.println(newHostName); - if (permitChangeScreen()) { - // please remove these numbers. - changeVNCServer(newHostName, 3200, 1980); - } else { - continue; - } + } clientSocket.close(); } - } } catch (IOException e) { continue; // log - } catch (InterruptedException e) { - continue; } } } @@ -204,11 +195,6 @@ th.start(); } - private boolean permitChangeScreen() { - - return true; - } - protected void socketClose() { }
--- a/src/viewer_swing/java/com/glavsoft/viewer/swing/SwingViewerWindow.java Fri May 23 11:25:43 2014 +0900 +++ b/src/viewer_swing/java/com/glavsoft/viewer/swing/SwingViewerWindow.java Fri May 23 17:56:42 2014 +0900 @@ -818,20 +818,20 @@ } }); kbdButtons.add(altButton); - + JButton screenButton = buttonsBar.createButton("share", "Share my screen", new ActionListener() { @Override - public void actionPerformed(ActionEvent e) { - try { - viewer.setCuiVersion(true); - viewer.getRfb().screenChangeRequest(); - } catch (IOException e1) { - e1.printStackTrace(); - } - } + public void actionPerformed(ActionEvent e) { + try { + viewer.setCuiVersion(true); + viewer.getRfb().screenChangeRequest(); + } catch (IOException e1) { + e1.printStackTrace(); + } + } }); kbdButtons.add(screenButton); - + ModifierButtonEventListener modifierButtonListener = new ModifierButtonEventListener(); modifierButtonListener.addButton(KeyEvent.VK_CONTROL, ctrlButton);