Mercurial > hg > Members > riono > TreeVNC_ja_comment
changeset 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 |
files | src/main/java/jp/ac/u_ryukyu/treevnc/CreateConnectionParam.java src/main/java/jp/ac/u_ryukyu/treevnc/MyRfbProto.java src/main/java/jp/ac/u_ryukyu/treevnc/client/GetHostClient.java src/main/java/jp/ac/u_ryukyu/treevnc/client/TreeVncRootSelectionPanel.java src/main/java/jp/ac/u_ryukyu/treevnc/server/VncProxyService.java src/viewer_swing/java/com/glavsoft/viewer/CuiViewer.java src/viewer_swing/java/com/glavsoft/viewer/Viewer.java src/viewer_swing/java/com/glavsoft/viewer/swing/ConnectionParams.java |
diffstat | 8 files changed, 110 insertions(+), 63 deletions(-) [+] |
line wrap: on
line diff
--- a/src/main/java/jp/ac/u_ryukyu/treevnc/CreateConnectionParam.java Fri Jun 06 21:12:45 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/treevnc/CreateConnectionParam.java Sat Jun 07 00:03:13 2014 +0900 @@ -1,39 +1,25 @@ package jp.ac.u_ryukyu.treevnc; -import java.util.logging.Logger; import com.glavsoft.viewer.ViewerImpl; +import com.glavsoft.viewer.swing.ConnectionParams; + import jp.ac.u_ryukyu.treevnc.client.TreeVncProtocol; import jp.ac.u_ryukyu.treevnc.client.GetHostClient; - - public class CreateConnectionParam { private String hostName; - private int portNumber = 5999; + private int portNumber = ConnectionParams.DEFAULT_VNC_ROOT; private MyRfbProto rfb; - private final Logger logger; public CreateConnectionParam(MyRfbProto rfb) { this.rfb = rfb; - logger = Logger.getLogger(getClass().getName()); } - public void findTreeVncRoot() { - GetHostClient getBcast = new GetHostClient(rfb.acceptPort); + public void findTreeVncRoot() throws InterruptedException { + GetHostClient getBcast = new GetHostClient(rfb.acceptPort,this); getBcast.getHost(); - portNumber = 0; - do { - try { - Thread runBcast = new Thread(getBcast, "TreeVNC-root-finder"); - runBcast.start(); - hostName = getBcast.textAddress(); // wait for root reply to our broadcast - portNumber = Integer.parseInt(getBcast.textPort()); - } catch (Exception e) { - logger.info("can't get parent address or port"); - } - getBcast.interrupt(); - } while ( portNumber == 0); - + // wait for RootSelection + wait(); } public void createConnectionParam(ViewerImpl v) { @@ -43,15 +29,24 @@ echo.getParentName(); v.setConnectionParam(echo.getParentsAddress(), portNumber); } - + public void runAcceptThread() { Thread accThread = new Thread(new AcceptThread(rfb, portNumber)); accThread.start(); } - - public void setHostName(String _hostName) { - hostName = _hostName; - portNumber = 5999; + + public void setHostName(String _hostName, int port) { + hostName = _hostName; + portNumber = port; + } + + public void setHostName(String hostAndPort) { + int i = hostAndPort.indexOf(':'); + if (i>0) { + portNumber = Integer.parseInt(hostAndPort.substring(i+1)); + hostName = hostAndPort.substring(0,i); + } else + hostName = hostAndPort; } }
--- 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();
--- a/src/main/java/jp/ac/u_ryukyu/treevnc/client/GetHostClient.java Fri Jun 06 21:12:45 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/treevnc/client/GetHostClient.java Sat Jun 07 00:03:13 2014 +0900 @@ -3,7 +3,6 @@ import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; -import java.net.BindException; import java.net.DatagramPacket; import java.net.InetAddress; import java.net.MulticastSocket; @@ -15,6 +14,7 @@ import com.glavsoft.rfb.protocol.ProtocolContext; import com.glavsoft.viewer.swing.ConnectionParams; +import jp.ac.u_ryukyu.treevnc.CreateConnectionParam; import jp.ac.u_ryukyu.treevnc.server.GetBroadCastProxy; public class GetHostClient implements Runnable { @@ -33,10 +33,13 @@ /** * To find vnc root, a client sends a multicast packet. + * @param createConnectionParam * @param _str */ - public GetHostClient(int _port) { + public GetHostClient(int _port, CreateConnectionParam createConnectionParam) { + CreateConnectionParam cp = createConnectionParam; port = _port; + rootSelectionPanel.setCp(cp); } public void createSocket() { @@ -49,27 +52,15 @@ } } - /** - * send find root message. - * - */ - public void sendData() { - String s = str + Integer.toString(port); - buf = s.getBytes(); - DatagramPacket sendPacket = new DatagramPacket(buf, s.length(), mAddr, ConnectionParams.DEFAULT_VNC_ROOT_FINDER); - try { - soc.send(sendPacket); - } catch (IOException e) { - e.printStackTrace(); - } - } - public void getHost() { createSocket(); findRoot(); - // sendData(); } + /** + * send find root message. + * + */ public void findRoot() { ByteBuffer buf = ByteBuffer.allocate(12); buf.order(ByteOrder.BIG_ENDIAN);
--- a/src/main/java/jp/ac/u_ryukyu/treevnc/client/TreeVncRootSelectionPanel.java Fri Jun 06 21:12:45 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/treevnc/client/TreeVncRootSelectionPanel.java Sat Jun 07 00:03:13 2014 +0900 @@ -1,10 +1,15 @@ package jp.ac.u_ryukyu.treevnc.client; import javax.swing.*; + +import com.glavsoft.viewer.swing.ConnectionParams; + import java.awt.*; import java.awt.event.*; import java.util.ArrayList; +import jp.ac.u_ryukyu.treevnc.CreateConnectionParam; + public class TreeVncRootSelectionPanel extends JFrame implements ActionListener, ItemListener { @@ -29,6 +34,7 @@ private String port; private CheckboxGroup ch = new CheckboxGroup(); private Container contentPane = getContentPane(); + private CreateConnectionParam cp; public TreeVncRootSelectionPanel() { setTitle("TreeVNC Root Address"); @@ -63,7 +69,7 @@ private void setText() { t1 = new TextField("Address", 30); - t2 = new TextField("5999", 5); + t2 = new TextField(Integer.toString(ConnectionParams.DEFAULT_VNC_ROOT), 5); panel.add(t1); panel.add(t2); //panel.add(button); @@ -133,6 +139,8 @@ System.out.println(check[t].getLabel()); setStatus(check[t].getLabel()); unVisible(); + cp.setHostName(hostAddress,Integer.parseInt(port)); + cp.notify(); } } } @@ -178,4 +186,8 @@ public void itemStateChanged(ItemEvent e) { } + + public void setCp(CreateConnectionParam cp) { + this.cp = cp; + } }
--- a/src/main/java/jp/ac/u_ryukyu/treevnc/server/VncProxyService.java Fri Jun 06 21:12:45 2014 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/treevnc/server/VncProxyService.java Sat Jun 07 00:03:13 2014 +0900 @@ -110,7 +110,7 @@ public void createConnectionAndStart() { Thread thread; - opendPort = myRfb.selectPort(5999); + opendPort = myRfb.selectPort(ConnectionParams.DEFAULT_VNC_ROOT); acceptThread = new AcceptThread(myRfb, opendPort); thread = new Thread(acceptThread, "TreeVNC-accept"); thread.start();
--- a/src/viewer_swing/java/com/glavsoft/viewer/CuiViewer.java Fri Jun 06 21:12:45 2014 +0900 +++ b/src/viewer_swing/java/com/glavsoft/viewer/CuiViewer.java Sat Jun 07 00:03:13 2014 +0900 @@ -5,7 +5,9 @@ import com.glavsoft.viewer.swing.ConnectionParams; import com.glavsoft.viewer.swing.ParametersHandler; import com.glavsoft.viewer.swing.SwingConnectionWorkerFactory; + import javax.swing.*; + import java.awt.*; import java.awt.event.WindowEvent; import java.awt.event.WindowListener; @@ -202,8 +204,6 @@ } public void setOpenPort(int parseInt) { - // TODO Auto-generated method stub - } public void setTeminationType(boolean b) { @@ -215,7 +215,10 @@ MyRfbProtoClient rfb = new MyRfbProtoClient(); CreateConnectionParam cp = new CreateConnectionParam(rfb); cp.runAcceptThread(); - cp.findTreeVncRoot(); + try { + cp.findTreeVncRoot(); + } catch (InterruptedException e) { + } cp.createConnectionParam(viewer); rfb.setViewer(viewer); viewer.myRfb = rfb; @@ -255,4 +258,8 @@ public void setCuiVersion(boolean flag) { // nop } + + @Override + public void createRootSelectionPanel() { + } }
--- a/src/viewer_swing/java/com/glavsoft/viewer/Viewer.java Fri Jun 06 21:12:45 2014 +0900 +++ b/src/viewer_swing/java/com/glavsoft/viewer/Viewer.java Sat Jun 07 00:03:13 2014 +0900 @@ -275,13 +275,9 @@ public void setSocket(Socket soc) { setConnectionParam(soc.getInetAddress().getHostAddress(),soc.getPort()); - //Thread accThread = new Thread(new AcceptThread(myRfb, soc.getPort())); - //accThread.start(); } public void setOpenPort(int parseInt) { - // TODO Auto-generated method stub - } public void setTeminationType(boolean b) { @@ -295,7 +291,10 @@ MyRfbProtoClient rfb = new MyRfbProtoClient(); CreateConnectionParam cp = new CreateConnectionParam(rfb); cp.runAcceptThread(); - cp.findTreeVncRoot(); + try { + cp.findTreeVncRoot(); + } catch (InterruptedException e) { + } cp.createConnectionParam(this); isTreeVNC = true; rfb.setViewer(this); @@ -304,6 +303,9 @@ SwingUtilities.invokeLater(this); } + /** + * start view with specific TreeVNC root + */ public void startViewer(String hostName,boolean cui) { MyRfbProtoClient rfb = new MyRfbProtoClient(); rfb.setCuiVersion(cui); @@ -340,4 +342,8 @@ public void setCuiVersion(boolean flag) { myRfb.setCuiVersion(flag); } + + @Override + public void createRootSelectionPanel() { + } }
--- a/src/viewer_swing/java/com/glavsoft/viewer/swing/ConnectionParams.java Fri Jun 06 21:12:45 2014 +0900 +++ b/src/viewer_swing/java/com/glavsoft/viewer/swing/ConnectionParams.java Sat Jun 07 00:03:13 2014 +0900 @@ -33,7 +33,8 @@ public class ConnectionParams implements Model { public static final int DEFAULT_SSH_PORT = 22; public static final int DEFAULT_RFB_PORT = 5900; - public static final int DEFAULT_VNC_ROOT_FINDER = DEFAULT_RFB_PORT; + public static final int DEFAULT_VNC_ROOT = 5950; + public static final int DEFAULT_VNC_ROOT_FINDER = DEFAULT_RFB_PORT; public String hostName; private int portNumber;