# HG changeset patch # User Yu Taninari # Date 1341827253 -32400 # Node ID dca3bd61b830edb07bfacf958267d27e5306588b # Parent 75b54fd9e73aac13205d477fa5b4314150018e57 before change MyVncClient.java diff -r 75b54fd9e73a -r dca3bd61b830 src/main/java/ac/ryukyu/treevnc/client/EchoClient.java --- a/src/main/java/ac/ryukyu/treevnc/client/EchoClient.java Tue Jul 03 13:34:43 2012 +0900 +++ b/src/main/java/ac/ryukyu/treevnc/client/EchoClient.java Mon Jul 09 18:47:33 2012 +0900 @@ -43,18 +43,18 @@ // VncViewerから引数をもらってきてproxy役を認識する public EchoClient(String name, MyVncClient client) { - this.client = client; + this.client = (InterfaceForViewer) client; this.name = name; } public EchoClient(String name, MyVncClient client, int echoPort) { - this.client = client; + this.client = (InterfaceForViewer) client; this.name = name; this.echoPort = echoPort; } public EchoClient(EchoClient echo, MyVncClient client) { - this.client = client; + this.client = (InterfaceForViewer) client; this.name = echo.name; leaderflag = echo.leaderflag; parent = echo.parent; diff -r 75b54fd9e73a -r dca3bd61b830 src/main/java/ac/ryukyu/treevnc/client/GetDataClient.java --- a/src/main/java/ac/ryukyu/treevnc/client/GetDataClient.java Tue Jul 03 13:34:43 2012 +0900 +++ b/src/main/java/ac/ryukyu/treevnc/client/GetDataClient.java Mon Jul 09 18:47:33 2012 +0900 @@ -1,19 +1,18 @@ package ac.ryukyu.treevnc.client; import java.io.BufferedReader; -//import java.io.ByteArrayInputStream; -//import java.io.DataInputStream; import java.io.IOException; import java.io.InputStreamReader; import java.net.ServerSocket; import java.net.Socket; + public class GetDataClient implements Runnable { private ServerSocket server = null; BufferedReader is; private int port = 8182; private boolean stopFlag = false; - TextBoxClient text = new TextBoxClient(); + public TextBoxClient text = new TextBoxClient(); private void getData() { try { @@ -23,9 +22,11 @@ is = new BufferedReader(new InputStreamReader( socket.getInputStream())); String line = is.readLine(); +// text = new TextBoxClient(); if(line!=null){ text.checkBox(line); } + // TextBoxClient text = new TextBoxClient(); text.setButton(); text.visible(); } @@ -34,6 +35,15 @@ } } + + public String textAddress() { + return text.getAddress(); + } + + public String textPort() { + return text.getPort(); + } + void socketClose() { try { text.unVisible(); diff -r 75b54fd9e73a -r dca3bd61b830 src/main/java/ac/ryukyu/treevnc/client/GetHostClient.java --- a/src/main/java/ac/ryukyu/treevnc/client/GetHostClient.java Tue Jul 03 13:34:43 2012 +0900 +++ b/src/main/java/ac/ryukyu/treevnc/client/GetHostClient.java Mon Jul 09 18:47:33 2012 +0900 @@ -18,7 +18,7 @@ str = _str; } - void createSocket() { + public void createSocket() { try { mAddr = InetAddress.getByName(MCASTADDR); soc = new MulticastSocket(); @@ -28,7 +28,7 @@ } } - void sendData() { + public void sendData() { buf = str.getBytes(); // System.out.println("strlen"+str.length()); // System.out.println("str"+str); diff -r 75b54fd9e73a -r dca3bd61b830 src/main/java/ac/ryukyu/treevnc/client/MyVncClient.java --- a/src/main/java/ac/ryukyu/treevnc/client/MyVncClient.java Tue Jul 03 13:34:43 2012 +0900 +++ b/src/main/java/ac/ryukyu/treevnc/client/MyVncClient.java Mon Jul 09 18:47:33 2012 +0900 @@ -15,6 +15,8 @@ import com.glavsoft.exceptions.TransportException; import com.glavsoft.exceptions.UnsupportedProtocolVersionException; import com.glavsoft.exceptions.UnsupportedSecurityTypeException; +import com.glavsoft.rfb.IChangeSettingsListener; +import com.glavsoft.rfb.IRfbSessionListener; import com.glavsoft.rfb.protocol.Protocol; import com.glavsoft.rfb.protocol.ProtocolSettings; import com.glavsoft.transport.Reader; @@ -31,8 +33,8 @@ import ac.ryukyu.treevnc.InterfaceForViewer; -public class MyVncClient extends Viewer implements InterfaceForViewer, - java.lang.Runnable, WindowListener { +public class MyVncClient extends Viewer implements Runnable, + IRfbSessionListener, WindowListener, IChangeSettingsListener { /** * @@ -93,7 +95,7 @@ if (mainArgs.length != 0) { for (int i = 0; i < argv.length; i++) { if ("-c".equals(argv[i])) { - // later write + // write later } } } else { @@ -108,7 +110,9 @@ System.exit(0); } MyVncClient myClient = new MyVncClient(parser); - SwingUtilities.invokeLater(myClient); + //SwingUtilities.invokeLater(myClient); + Thread th = new Thread(myClient); + th.start(); } private void getHostData() { @@ -119,19 +123,22 @@ runBcast = new Thread(getBcast); runBcast.start(); getBcast.setStopFlag(true); - connectionParams.hostName = getBcast.text.getAddress(); + connectionParams.hostName = getBcast.textAddress(); if("notFound".equals(pHost)) { getHost = new TextBoxClient(); getHost.ipRegister(); connectionParams.hostName = getHost.getAddressOption(); - connectionParams.portNumber = Integer.parseInt(getHost.getPortOption()); + //connectionParams.portNumber = Integer.parseInt(getHost.getPortOption()); + connectionParams.portNumber = 5900; } else { - connectionParams.portNumber = Integer.parseInt(getBcast.text.getPort()); + //connectionParams.portNumber = Integer.parseInt(getBcast.textPort()); + connectionParams.portNumber = 5900; } } @Override public void run() { + // getHostData(); ConnectionManager connectionManager = new ConnectionManager(this, isApplet); if (forceReconnection) { connectionManager.showReconnectDialog("Connection lost", reconnectionReason); @@ -139,6 +146,7 @@ } tryAgain = true; while (tryAgain) { + // workingSocket = connectionManager.connectToTreeHost(connectionParams, settings); workingSocket = connectionManager.connectToHost(connectionParams, settings); if (null == workingSocket) { closeApp(); @@ -196,41 +204,7 @@ - @Override - public void setEchoValue(EchoClient value) { - // TODO Auto-generated method stub - } - - @Override - public String readParameter(String name, boolean required) { - // TODO Auto-generated method stub - return null; - } - - @Override - public void getParentName() { - // TODO Auto-generated method stub - - } - - @Override - public void disconnect() { - // TODO Auto-generated method stub - - } - - @Override - public void fatalError(String str) { - // TODO Auto-generated method stub - - } - - @Override - public void fatalError(String str, Exception e) { - // TODO Auto-generated method stub - - } @Override public void destroy() { @@ -239,75 +213,29 @@ } @Override - public void enableInput(boolean enable) { - // TODO Auto-generated method stub - - } - - @Override - public void setClientSocket(Socket sock) { - // TODO Auto-generated method stub - - } - - @Override - public void close() { - // TODO Auto-generated method stub - - } - - @Override - public Image getScreenImage() { - // TODO Auto-generated method stub - return null; - } - - @Override - public void writeScreenData(byte[] b, String imageFormat) { - // TODO Auto-generated method stub - - } - - @Override - public void windowActivated(WindowEvent e) { - // TODO Auto-generated method stub - + public void windowClosing(WindowEvent e) { + if (e != null && e.getComponent() != null) { + e.getWindow().setVisible(false); + } + closeApp(); } @Override - public void windowClosed(WindowEvent e) { - // TODO Auto-generated method stub - - } + public void windowActivated(WindowEvent e) { /*nop*/ } @Override - public void windowClosing(WindowEvent e) { - // TODO Auto-generated method stub - - } + public void windowClosed(WindowEvent e) { /*nop*/ } @Override - public void windowDeactivated(WindowEvent e) { - // TODO Auto-generated method stub - - } + public void windowDeactivated(WindowEvent e) { /*nop*/ } @Override - public void windowDeiconified(WindowEvent e) { - // TODO Auto-generated method stub - - } + public void windowDeiconified(WindowEvent e) { /*nop*/ } @Override - public void windowIconified(WindowEvent e) { - // TODO Auto-generated method stub - - } + public void windowIconified(WindowEvent e) { /*nop*/ } @Override - public void windowOpened(WindowEvent e) { - // TODO Auto-generated method stub - - } + public void windowOpened(WindowEvent e) { /*nop*/ } } diff -r 75b54fd9e73a -r dca3bd61b830 src/main/java/ac/ryukyu/treevnc/client/TextBoxClient.java --- a/src/main/java/ac/ryukyu/treevnc/client/TextBoxClient.java Tue Jul 03 13:34:43 2012 +0900 +++ b/src/main/java/ac/ryukyu/treevnc/client/TextBoxClient.java Mon Jul 09 18:47:33 2012 +0900 @@ -38,6 +38,7 @@ public void ipRegister() { setSize(); setText(); + setButton(); visible(); } @@ -47,7 +48,7 @@ height = (d.getHeight() / 2); } - void visible() { + public void visible() { Point point = new Point(); point.setLocation(width - 250, height - 80); setLocation(point.getLocation()); @@ -59,20 +60,20 @@ setVisible(false); } - private void setText() { + private void setText() { t1 = new TextField("Address", 30); t2 = new TextField("5999", 5); panel.add(t1); panel.add(t2); - panel.add(button); - button.addActionListener(this); + //panel.add(button); + //button.addActionListener(this); label = new JLabel(); Container contentPane = getContentPane(); contentPane.add(panel, BorderLayout.CENTER); contentPane.add(label, BorderLayout.SOUTH); } - void checkBox(String str) { + public void checkBox(String str) { // CheckboxGroup ch = new CheckboxGroup(); if (counter == 0) check[counter] = new Checkbox(str, true, ch); @@ -147,6 +148,7 @@ } public void actionPerformed(ActionEvent e) { + System.out.println("Action"); flag = true; for (int t = 0; t < counter; t++) { if (check[t].getState()) { diff -r 75b54fd9e73a -r dca3bd61b830 src/viewer_swing/java/com/glavsoft/viewer/ConnectionManager.java --- a/src/viewer_swing/java/com/glavsoft/viewer/ConnectionManager.java Tue Jul 03 13:34:43 2012 +0900 +++ b/src/viewer_swing/java/com/glavsoft/viewer/ConnectionManager.java Mon Jul 09 18:47:33 2012 +0900 @@ -24,6 +24,10 @@ package com.glavsoft.viewer; +import ac.ryukyu.treevnc.client.GetDataClient; +import ac.ryukyu.treevnc.client.GetHostClient; +import ac.ryukyu.treevnc.client.TextBoxClient; + import com.glavsoft.rfb.protocol.ProtocolSettings; import com.glavsoft.viewer.swing.ParametersHandler; import com.glavsoft.viewer.swing.Utils; @@ -74,6 +78,46 @@ forceConnectionDialog = !isApplet; } } + + public Socket connectToTreeHost(final ParametersHandler.ConnectionParams connectionParams, ProtocolSettings settings) { + Socket socket = null; + boolean wasError = false; + GetHostClient bCast = new GetHostClient("who"); + bCast.createSocket(); + bCast.sendData(); + GetDataClient getBcast = new GetDataClient(); + Thread runBcast = new Thread(getBcast); + runBcast.start(); + getBcast.setStopFlag(true); + connectionParams.hostName = getBcast.textAddress(); + if("notFound".equals(connectionParams.hostName)) { + getBcast.text.ipRegister(); + connectionParams.hostName = getBcast.textAddress(); + //connectionParams.portNumber = Integer.parseInt(getHost.getPortOption()); + connectionParams.portNumber = 5900; + } else { + //connectionParams.portNumber = Integer.parseInt(getBcast.textPort()); + connectionParams.portNumber = 5900; + } + Viewer.logger.info("Connecting to host " + connectionParams.hostName + ":" + connectionParams.portNumber); + try { + socket = new Socket(connectionParams.hostName, connectionParams.portNumber); + wasError = false; + } catch (UnknownHostException e) { + Viewer.logger.severe("Unknown host: " + connectionParams.hostName); + showConnectionErrorDialog("Unknown host: '" + connectionParams.hostName + "'"); + wasError = true; + } catch (IOException e) { + Viewer.logger.severe("Couldn't connect to: " + + connectionParams.hostName + ":" + connectionParams.portNumber + + ": " + e.getMessage()); + showConnectionErrorDialog("Couldn't connect to: '" + connectionParams.hostName + + "'\n" + e.getMessage()); + wasError = true; + } + return socket; + } + public Socket connectToHost(final ParametersHandler.ConnectionParams connectionParams, ProtocolSettings settings) { Socket socket = null;