# HG changeset patch # User Shinji KONO # Date 1465652578 -32400 # Node ID aad75cd6d9e2a452447c551cbb6d9f84b03409c3 # Parent ff7fa81f36163d30c50c5d1d5a3c271aaaa473e8 Multicast joins both ipv4 and ipv6 now. diff -r ff7fa81f3616 -r aad75cd6d9e2 .idea/gradle.xml --- a/.idea/gradle.xml Fri Jun 10 19:58:59 2016 +0900 +++ b/.idea/gradle.xml Sat Jun 11 22:42:58 2016 +0900 @@ -12,11 +12,6 @@ - diff -r ff7fa81f3616 -r aad75cd6d9e2 .idea/workspace.xml --- a/.idea/workspace.xml Fri Jun 10 19:58:59 2016 +0900 +++ b/.idea/workspace.xml Sat Jun 11 22:42:58 2016 +0900 @@ -2,9 +2,14 @@ + + + + + + + - - @@ -42,21 +47,11 @@ - - - - - - - - - - - - + + @@ -64,84 +59,101 @@ - - + + - + + + + + + + + + + + + + + + + + + + + - - + + - + - + - - + + - - - - - - - - - - - - + - - + + - + + + + + + + + + + + + + + + + + + + + - - + + - + - - + + - - - - - - - - - - - + @@ -453,6 +465,11 @@ @@ -463,11 +480,14 @@ + + + - @@ -490,13 +510,8 @@ - - - - - @@ -655,8 +670,113 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -669,6 +789,14 @@ + + + + + + + + @@ -734,15 +862,6 @@ @@ -764,15 +883,6 @@ @@ -835,61 +945,11 @@ - - - - - - - - - - - - - - - - - - - - + - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + @@ -1077,18 +1110,96 @@ - + + + + + + + + + + + - + + + + + + + + + + + + + + + + + + + + + + + + + + - + + + + + + + + + + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -1097,7 +1208,40 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -1105,17 +1249,20 @@ - - + - - - - - + + + + + + + + + @@ -1127,11 +1274,38 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + - @@ -1139,33 +1313,121 @@ + + + + + + + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - \ No newline at end of file diff -r ff7fa81f3616 -r aad75cd6d9e2 src/main/java/com/glavsoft/rfb/protocol/state/InitState.java --- a/src/main/java/com/glavsoft/rfb/protocol/state/InitState.java Fri Jun 10 19:58:59 2016 +0900 +++ b/src/main/java/com/glavsoft/rfb/protocol/state/InitState.java Sat Jun 11 22:42:58 2016 +0900 @@ -24,15 +24,10 @@ package com.glavsoft.rfb.protocol.state; -import com.glavsoft.exceptions.AuthenticationFailedException; -import com.glavsoft.exceptions.FatalException; -import com.glavsoft.exceptions.TransportException; -import com.glavsoft.exceptions.UnsupportedProtocolVersionException; -import com.glavsoft.exceptions.UnsupportedSecurityTypeException; +import com.glavsoft.exceptions.*; import com.glavsoft.rfb.encoding.ServerInitMessage; import com.glavsoft.rfb.protocol.ProtocolContext; import com.glavsoft.rfb.protocol.ProtocolSettings; -import jp.ac.u_ryukyu.treevnc.TreeRFBProto; /** * ClientInit @@ -79,7 +74,7 @@ context.setPixelFormat(serverInitMessage.getPixelFormat()); context.setFbWidth(serverInitMessage.getFrameBufferWidth()); context.setFbHeight(serverInitMessage.getFrameBufferHeight()); - System.out.println("serverInit : width : " + context.getFbWidth() + " height : " + context.getFbHeight()); + // System.out.println("serverInit : width : " + context.getFbWidth() + " height : " + context.getFbHeight()); context.setRemoteDesktopName(serverInitMessage.getName()); context.setInitData(serverInitMessage.getInitData()); } diff -r ff7fa81f3616 -r aad75cd6d9e2 src/main/java/jp/ac/u_ryukyu/treevnc/FindRoot.java --- a/src/main/java/jp/ac/u_ryukyu/treevnc/FindRoot.java Fri Jun 10 19:58:59 2016 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/treevnc/FindRoot.java Sat Jun 11 22:42:58 2016 +0900 @@ -1,24 +1,19 @@ package jp.ac.u_ryukyu.treevnc; +import com.glavsoft.rfb.protocol.ProtocolContext.TreeCommand; +import com.glavsoft.viewer.swing.ConnectionParams; + import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; -import java.net.DatagramPacket; -import java.net.InetAddress; -import java.net.MulticastSocket; -import java.net.ServerSocket; -import java.net.Socket; +import java.net.*; import java.nio.ByteBuffer; import java.nio.ByteOrder; -import com.glavsoft.rfb.protocol.ProtocolContext.TreeCommand; -import com.glavsoft.viewer.swing.ConnectionParams; - public class FindRoot implements Runnable { final int BUFSIZE = 1024; - private InetAddress mAddr; private MulticastSocket soc; - + private InetAddress mAddr; private ServerSocket server = null; private BufferedReader is; private int port; @@ -32,23 +27,20 @@ * @param createConnectionParam */ public FindRoot(int _port, CreateConnectionParam createConnectionParam) { - CreateConnectionParam cp = createConnectionParam; - port = _port; - rootSelectionPanel.setCp(cp); - createSocket(); - } + port = _port; + CreateConnectionParam cp = createConnectionParam; + rootSelectionPanel.setCp(cp); + try { + soc = TreeRootFinderListener.createMulticastSocket(); + soc.setTimeToLive(1); + mAddr = InetAddress.getByName(TreeRootFinderListener.McastAddr); + System.out.println("FindRoot socket on " + TreeRootFinderListener.McastAddr + " " + mAddr + " port " + _port); + } catch (IOException e) { + System.out.println("cannot create FindRoot socket. " + e); + return; + } + } - public void createSocket() { - try { - mAddr = InetAddress.getByName(TreeRootFinderListener.McastAddr); - soc = new MulticastSocket(); - soc.joinGroup(mAddr); - soc.setTimeToLive(1); - } catch (IOException e) { - System.out.println("cannot create FindRoot socket."); - e.printStackTrace(); - } - } /** * send find root message. diff -r ff7fa81f3616 -r aad75cd6d9e2 src/main/java/jp/ac/u_ryukyu/treevnc/TreeRFBProto.java --- a/src/main/java/jp/ac/u_ryukyu/treevnc/TreeRFBProto.java Fri Jun 10 19:58:59 2016 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/treevnc/TreeRFBProto.java Sat Jun 11 22:42:58 2016 +0900 @@ -1,5 +1,17 @@ package jp.ac.u_ryukyu.treevnc; +import com.glavsoft.exceptions.TransportException; +import com.glavsoft.rfb.client.ClientToServerMessage; +import com.glavsoft.rfb.encoding.EncodingType; +import com.glavsoft.rfb.encoding.decoder.FramebufferUpdateRectangle; +import com.glavsoft.rfb.protocol.Protocol; +import com.glavsoft.rfb.protocol.ProtocolContext; +import com.glavsoft.transport.Reader; +import com.glavsoft.transport.Writer; +import com.glavsoft.viewer.ConnectionPresenter; +import com.glavsoft.viewer.ViewerInterface; +import com.glavsoft.viewer.swing.ConnectionParams; + import java.io.IOException; import java.io.OutputStream; import java.io.UnsupportedEncodingException; @@ -14,18 +26,6 @@ import java.util.zip.Deflater; import java.util.zip.Inflater; -import com.glavsoft.exceptions.TransportException; -import com.glavsoft.rfb.client.ClientToServerMessage; -import com.glavsoft.rfb.encoding.EncodingType; -import com.glavsoft.rfb.encoding.decoder.FramebufferUpdateRectangle; -import com.glavsoft.rfb.protocol.Protocol; -import com.glavsoft.rfb.protocol.ProtocolContext; -import com.glavsoft.transport.Reader; -import com.glavsoft.transport.Writer; -import com.glavsoft.viewer.ConnectionPresenter; -import com.glavsoft.viewer.ViewerInterface; -import com.glavsoft.viewer.swing.ConnectionParams; - public class TreeRFBProto { @@ -149,19 +149,18 @@ c.poll(); // discard, should be timeout count++; if (flag == 0) { - System.out.println("Discarding " + myId - + " count=" + count); + // System.out.println("Discarding " + myId + " count=" + count); flag = 1; } wait(10); // if this is too short, writer cannot // take the poll, if this is too // long, memory will overflow... } - if (flag == 1) - System.out.println("Resuming " + myId + " count=" + count); + // if (flag == 1) + // System.out.println("Resuming " + myId + " count=" + count); if (state != 1) { System.out.println("Client died " + myId); - System.out.println("task stop"); + // System.out.println("task stop"); String rootHostName = null; int rootHostPort = 0; String myHostName = null; @@ -182,7 +181,7 @@ } } catch (InterruptedException e) { e.printStackTrace(); - System.out.println("timer thread interrupt."); + System.out.println("timer thread interrupted."); } } } @@ -453,7 +452,6 @@ public void addHostToSelectionPanel(int port, String hostname, String myHostName) { if (rootSelectionPanel != null) { rootSelectionPanel.checkBox(Integer.toString(port) + ":" + hostname + ":" + myHostName); - rootSelectionPanel.setButton(); rootSelectionPanel.visible(); } } diff -r ff7fa81f3616 -r aad75cd6d9e2 src/main/java/jp/ac/u_ryukyu/treevnc/TreeRootFinderListener.java --- a/src/main/java/jp/ac/u_ryukyu/treevnc/TreeRootFinderListener.java Fri Jun 10 19:58:59 2016 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/treevnc/TreeRootFinderListener.java Sat Jun 11 22:42:58 2016 +0900 @@ -1,16 +1,15 @@ package jp.ac.u_ryukyu.treevnc; -import java.io.IOException; -import java.net.*; -import java.lang.SecurityManager; - import com.glavsoft.rfb.protocol.ProtocolContext.TreeCommand; import com.glavsoft.viewer.ViewerInterface; import com.glavsoft.viewer.swing.ConnectionParams; +import java.io.IOException; +import java.net.*; + public class TreeRootFinderListener implements Runnable { public static final String Ipv4McastAddr = "224.0.0.1"; - public static final String Ipv6McastAddr = "FF02::1"; + public static final String Ipv6McastAddr = "ff02::1"; public static String McastAddr = Ipv4McastAddr; static final int BufSize = 1024; @@ -22,21 +21,31 @@ public TreeRootFinderListener(ViewerInterface vncProxyService) { vps = vncProxyService; } - - /** + + public static MulticastSocket createMulticastSocket() throws IOException { + MulticastSocket soc = new MulticastSocket(ConnectionParams.DEFAULT_VNC_ROOT_FINDER); + try { + soc.joinGroup(InetAddress.getByName(McastAddr)); + } catch (SocketException e) { + System.out.println("join to " + Ipv4McastAddr + " failed."); + } + try { + soc.joinGroup(InetAddress.getByName(Ipv6McastAddr)); + } catch (SocketException e) { + System.out.println("join to " + Ipv6McastAddr + " failed."); + } + return soc; + } + + /** * 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. */ private void replyToRootSearchMulticast() { byte[] buf = new byte[BufSize]; try { - soc = new MulticastSocket(ConnectionParams.DEFAULT_VNC_ROOT_FINDER); - try { - soc.joinGroup(InetAddress.getByName(McastAddr)); - } catch (SocketException e) { - McastAddr = Ipv6McastAddr; - soc.joinGroup(InetAddress.getByName(Ipv6McastAddr)); - } + soc = createMulticastSocket(); + System.out.println("FindRoot listening on "+ InetAddress.getByName(McastAddr)); DatagramPacket recvPacket = new DatagramPacket(buf, BufSize); while (!stopFlag) { @@ -67,8 +76,8 @@ System.out.println("tree-root-find-listener :" + e.getMessage()); } } - - public int parse_code( byte[] bs,int offset,int len ) + + public int parse_code( byte[] bs,int offset,int len ) { int intval = 0; for( int i = offset; i < len ; i++ ) { diff -r ff7fa81f3616 -r aad75cd6d9e2 src/main/java/jp/ac/u_ryukyu/treevnc/TreeVncRootSelectionPanel.java --- a/src/main/java/jp/ac/u_ryukyu/treevnc/TreeVncRootSelectionPanel.java Fri Jun 10 19:58:59 2016 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/treevnc/TreeVncRootSelectionPanel.java Sat Jun 11 22:42:58 2016 +0900 @@ -1,12 +1,13 @@ package jp.ac.u_ryukyu.treevnc; -import javax.swing.*; - import com.glavsoft.viewer.swing.ConnectionParams; +import javax.swing.*; import java.awt.*; -import java.awt.event.*; -import java.io.IOException; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.event.ItemEvent; +import java.awt.event.ItemListener; public class TreeVncRootSelectionPanel extends JFrame implements ActionListener, ItemListener { @@ -24,7 +25,6 @@ private double width = 750; private double height = 500; private JLabel label; - private boolean flag; private int counter = 0; // private JCheckBox[] check = new JCheckBox[20]; private Checkbox[] check = new Checkbox[20]; @@ -87,6 +87,10 @@ contentPane.add(label, BorderLayout.SOUTH); } + /** + * add tree vnc server selection + * @param str + */ public void checkBox(String str) { if (counter == 0) check[counter] = new Checkbox(str, true, ch); @@ -105,16 +109,6 @@ contentPane.add(panel, BorderLayout.CENTER); } - public String getAddressOption() { - while (!(flag)) { - try { - Thread.sleep(500); - } catch (InterruptedException e) { - e.printStackTrace(); - } - } - return t1.getText(); - } public String getPortOption() { return t2.getText(); @@ -126,7 +120,6 @@ public void actionPerformed(ActionEvent e) { if (advancedMenu.getSelectedIndex() == 0) { - flag = true; for (int t = 0; t < counter; t++) { int ipv4AddressLength = 3; int ipv6AddressLength = 17; @@ -134,7 +127,7 @@ String hostAddress = null; String rootAddress = null; if (check[t].getState()) { - System.out.println(check[t].getLabel()); + // System.out.println("Root Seletion Panel get the address : "+e+" "+check[t].getLabel()); String str = check[t].getLabel(); String[] temp = str.split(":"); if (temp.length == ipv4AddressLength) { diff -r ff7fa81f3616 -r aad75cd6d9e2 src/viewer_swing/java/com/glavsoft/viewer/swing/SwingViewerWindow.java --- a/src/viewer_swing/java/com/glavsoft/viewer/swing/SwingViewerWindow.java Fri Jun 10 19:58:59 2016 +0900 +++ b/src/viewer_swing/java/com/glavsoft/viewer/swing/SwingViewerWindow.java Sat Jun 11 22:42:58 2016 +0900 @@ -31,14 +31,19 @@ import com.glavsoft.rfb.protocol.ProtocolContext; import com.glavsoft.rfb.protocol.ProtocolSettings; import com.glavsoft.utils.Keymap; -import com.glavsoft.viewer.*; +import com.glavsoft.viewer.ConnectionPresenter; +import com.glavsoft.viewer.UiSettings; +import com.glavsoft.viewer.Viewer; +import com.glavsoft.viewer.ViewerInterface; import com.glavsoft.viewer.swing.gui.OptionsDialog; +import jp.ac.u_ryukyu.treevnc.ScreenChangeRequest; +import jp.ac.u_ryukyu.treevnc.ScreenChangeSelectionPanel; +import jp.ac.u_ryukyu.treevnc.TreeRFBProto; import javax.swing.*; import javax.swing.border.BevelBorder; import javax.swing.border.Border; import javax.swing.border.EmptyBorder; - import java.awt.*; import java.awt.event.*; import java.lang.reflect.Field; @@ -52,8 +57,6 @@ import java.util.concurrent.TimeUnit; import java.util.logging.Logger; -import jp.ac.u_ryukyu.treevnc.*; - public class SwingViewerWindow implements IChangeSettingsListener { public static final int FS_SCROLLING_ACTIVE_BORDER = 20; private JToggleButton zoomFitButton; @@ -1014,25 +1017,29 @@ final int thatScreenY = (int) presenter.getY(); final int thatScreenWidth = presenter.getFrameSizeWidth(); final int thatScreenHeight = presenter.getFrameSizeHeight(); - System.out.println("thatScreenX:"+thatScreenX); - System.out.println("thatScreenY:"+thatScreenY); - System.out.println("thatScreenWidth:"+thatScreenWidth); - System.out.println("thatScreenHeight:"+thatScreenHeight); - System.out.println("getMaximum:"+scroller.getHorizontalScrollBar().getMaximum()); - System.out.println("getMinmum:"+scroller.getHorizontalScrollBar().getMinimum()); - // uiSettings.zoomToFit(2*thatScreenWidth, 2*thatScreenHeight, thisScreenWidth, thisScreenHeight); + if (false) { + System.out.println("thatScreenX:" + thatScreenX); + System.out.println("thatScreenY:" + thatScreenY); + System.out.println("thatScreenWidth:" + thatScreenWidth); + System.out.println("thatScreenHeight:" + thatScreenHeight); + System.out.println("getMaximum:" + scroller.getHorizontalScrollBar().getMaximum()); + System.out.println("getMinmum:" + scroller.getHorizontalScrollBar().getMinimum()); + // uiSettings.zoomToFit(2*thatScreenWidth, 2*thatScreenHeight, thisScreenWidth, thisScreenHeight); + } int singleWidth = viewer.getRfb().getSingleWidth() * viewer.getRfb().getRetinaScale(); int singleHeight = viewer.getRfb().getSingleHeight() * viewer.getRfb().getRetinaScale(); - System.out.println("singleeight:"+singleHeight); + if (false) + System.out.println("singleeight:"+singleHeight); //frame.setSize(thisScreenWidth, thisScreenHeight); uiSettings.fitScreen(thisScreenWidth, thisScreenHeight, singleWidth, singleHeight); - final Rectangle visible = new Rectangle(thatScreenX,thatScreenY,thatScreenWidth,thatScreenHeight); + // final Rectangle visible = new Rectangle(thatScreenX,thatScreenY,thatScreenWidth,thatScreenHeight); SwingUtilities.invokeLater(new Runnable(){ public void run() { + // we want to shift thaScreenX, to do so, * 1.5 is required. scroller.getHorizontalScrollBar().setValue((int)(thatScreenX*1.5)); scroller.getVerticalScrollBar().setValue((int)(thatScreenY*1.5)); - //scroller.scrollRectToVisible(visible); + // scroller.scrollRectToVisible(visible); this does not work } }); }