Mercurial > hg > Members > you > TreeVNC
changeset 9:56251926d766
update
author | one |
---|---|
date | Tue, 20 Dec 2011 18:09:34 +0900 |
parents | d39930ff8758 |
children | 7be14292da1b |
files | .classpath bin/myVncProxy/Child.class bin/myVncProxy/MyRfbProto.class bin/myVncProxy/VncProxyService.class src/myVncClient/BroadCast.java src/myVncClient/EchoClient.java src/myVncClient/GetBroadCast.java src/myVncClient/MyVncClient.java src/myVncClient/TextBox.java src/myVncProxy/AcceptClient.java src/myVncProxy/VncProxyService.java src/treeVnc/SelectType.java src/treeVnc/TreeVnc.java |
diffstat | 13 files changed, 153 insertions(+), 106 deletions(-) [+] |
line wrap: on
line diff
--- a/.classpath Mon Dec 12 12:50:08 2011 +0900 +++ b/.classpath Tue Dec 20 18:09:34 2011 +0900 @@ -2,5 +2,6 @@ <classpath> <classpathentry kind="src" path="src"/> <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> + <classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/> <classpathentry kind="output" path="bin"/> </classpath>
--- a/src/myVncClient/BroadCast.java Mon Dec 12 12:50:08 2011 +0900 +++ b/src/myVncClient/BroadCast.java Tue Dec 20 18:09:34 2011 +0900 @@ -6,7 +6,7 @@ import java.net.MulticastSocket; import java.net.UnknownHostException; -public class BroadCast implements Runnable { +public class BroadCast { final int BUFSIZE = 1024; final String MCASTADDR = "224.0.0.1"; final int PORT = 8183; @@ -41,7 +41,7 @@ e.printStackTrace(); } } - +/* @Override public void run() { createSocket(); @@ -54,4 +54,5 @@ } } } + */ }
--- a/src/myVncClient/EchoClient.java Mon Dec 12 12:50:08 2011 +0900 +++ b/src/myVncClient/EchoClient.java Tue Dec 20 18:09:34 2011 +0900 @@ -150,7 +150,7 @@ //if(!(checkRepetition.equals("skip")) || "1".equals(leaderflag)) { if(!(waitReply.checkPath())) { Thread.sleep(1000); - reConnectionMain(); + reConnectionMain(echoSocket); streamClose(); } //Thread.sleep(1000); @@ -182,7 +182,7 @@ try { sendDataProxy("2", parent,null); getProxyData(is); - reConnectionMain(); + reConnectionMain(echoSocket); streamClose(); } catch (UnknownHostException e) { System.err.println("Trying to connect to unknown host: " + e); @@ -238,7 +238,9 @@ return checkRepetition; } - void reConnectionMain() { + void reConnectionMain(Socket echoSocket) { + client.close(); + client.setClientSocket(echoSocket); client.init(); client.setEchoValue(this); client.getParentName();
--- a/src/myVncClient/GetBroadCast.java Mon Dec 12 12:50:08 2011 +0900 +++ b/src/myVncClient/GetBroadCast.java Tue Dec 20 18:09:34 2011 +0900 @@ -39,6 +39,7 @@ void socketClose() { try { + text.unVisible(); server.close(); is.close(); } catch (IOException e) {
--- a/src/myVncClient/MyVncClient.java Mon Dec 12 12:50:08 2011 +0900 +++ b/src/myVncClient/MyVncClient.java Tue Dec 20 18:09:34 2011 +0900 @@ -16,13 +16,13 @@ * */ private static final long serialVersionUID = 1L; - boolean inAnApplet = true; - boolean inSeparateFrame = false; - Socket clientSocket = null; - String parent, treenum; + private boolean inAnApplet = true; + private boolean inSeparateFrame = false; + private Socket clientSocket = null; + private String parent, treenum; private String leaderflag; - boolean runflag = false; - boolean first = true; + private boolean runflag = false; + private boolean first = true; private EchoClient echoValue; private int echoPort; @@ -45,6 +45,7 @@ private void runClient(String[] argv) { mainArgs = argv; + System.out.println(mainArgs.length); inAnApplet = false; inSeparateFrame = true; if(mainArgs.length == 0) { @@ -205,16 +206,24 @@ e1.printStackTrace(); } - if (counter >= 6) { + if (counter >= 3) { echoValue.openport(); echoValue.notfoundParent(); } echoValue.openport(); + /* + if(echoValue.notfoundParent()) { + break; + } + */ // runflag = echo.losthost(); + + if (echoValue.losthost()) { break; } + counter++; }
--- a/src/myVncClient/TextBox.java Mon Dec 12 12:50:08 2011 +0900 +++ b/src/myVncClient/TextBox.java Tue Dec 20 18:09:34 2011 +0900 @@ -5,23 +5,24 @@ import java.awt.event.*; import java.util.ArrayList; -public class TextBox extends JFrame implements ActionListener { +public class TextBox extends JFrame implements ActionListener, ItemListener { private JPanel panel = new JPanel(); private JButton button = new JButton("Connect"); private TextField t1; private TextField t2; - private double width; - private double height; + private double width = 750; + private double height = 500; private JLabel label; private boolean flag; ArrayList<String> temp = new ArrayList<String>(); - private int counter=0; + private int counter = 0; + //private JCheckBox[] check = new JCheckBox[20]; private Checkbox[] check = new Checkbox[20]; - private boolean firstFlag=true; + private boolean firstFlag = true; private String hostAddress; private String port; - + private CheckboxGroup ch = new CheckboxGroup(); public void ipRegister() { setSize(); @@ -29,13 +30,11 @@ visible(); } - public TextBox() { setTitle("Informatin Connection Address"); setResizable(false); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } - private void setSize() { Dimension d = Toolkit.getDefaultToolkit().getScreenSize(); @@ -51,6 +50,10 @@ setVisible(true); } + public void unVisible() { + setVisible(false); + } + private void setText() { t1 = new TextField("Address", 30); t2 = new TextField("5999", 5); @@ -63,81 +66,108 @@ contentPane.add(panel, BorderLayout.CENTER); contentPane.add(label, BorderLayout.SOUTH); } - - void checkBox(String str) { - CheckboxGroup ch = new CheckboxGroup(); - check[counter] = new Checkbox(str,ch,false); - check[counter].setBackground(new Color(0,153,255)); - panel.add(check[counter]); - panel.setLayout(new GridLayout(counter+2, 0)); - counter++; - } - - void setButton(){ - panel.add(button); - panel.setBackground(Color.blue); - button.addActionListener(this); - Container contentPane = getContentPane(); - contentPane.add(panel, BorderLayout.CENTER); - } - - String splitString(String str) { - String[] split = str.split("\\*");; - String comper; - if(split.length>4) { - split[4] = null; - } - comper = split[1]+split[3]; - if(firstFlag) { - temp.add(comper); - firstFlag = false; - return "port:"+split[0]+":host:"+split[1]+":proxy:"+split[3]; - } - for(int t=0;t<temp.size();t++){ - if(!(comper.equals(temp.get(t)))){ - if(t == temp.size()-1){ - temp.add(comper); - return "port:"+split[0]+":host:"+split[1]+":proxy:"+split[3]; - } - } else { - break; - } - } - return null; - } + + void checkBox(String str) { + //CheckboxGroup ch = new CheckboxGroup(); + if (counter == 0) + check[counter] = new Checkbox(str,true,ch); + else + check[counter] = new Checkbox(str,false,ch); + //check[counter].setBackground(new Color(0, 153, 255)); + check[counter].addItemListener(this); + panel.add(check[counter]); + panel.setLayout(new GridLayout(counter + 2, 0)); + panel.setLocation((int) width - 250, (int) height - 80); + counter++; + } - + void setButton() { + panel.add(button); + //panel.setBackground(Color.blue); + button.addActionListener(this); + Container contentPane = getContentPane(); + contentPane.add(panel, BorderLayout.CENTER); + } + + + private void reportWindow() { + setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + Container pane = getContentPane(); + JLabel label = new JLabel("Not found Proxy. If you use Client-mode you must set-up Proxy"); + label.setPreferredSize(new Dimension(580,50)); + label.setFont(new Font("Arial", Font.PLAIN, 20)); + pane.add(label); + } + public String getAddress() { - while(!(flag)) { + int i = 0; + while (!(flag)) { + if (i >= 20) { + reportWindow(); + visible(); + break; + } try { Thread.sleep(500); } catch (InterruptedException e) { e.printStackTrace(); } + i++; } return hostAddress; - //return t1.getText(); + // return t1.getText(); } - + public String getPort() { return port; - //return t2.getText(); + // return t2.getText(); } public void actionPerformed(ActionEvent e) { flag = true; - for(int t=0;t<counter;t++) { - if(check[t].getState()){ + for (int t = 0; t < counter; t++) { + if (check[t].getState()) { System.out.println(check[t].getLabel()); setStatus(check[t].getLabel()); } } } + private void setStatus(String str) { - String[] temp = str.split(":"); - port = temp[0]; - System.out.println("port="+port); - hostAddress = temp[3]; + String[] temp = str.split(":"); + port = temp[0]; + System.out.println("port=" + port); + hostAddress = temp[3]; + } + + + String splitString(String str) { + String[] split = str.split("\\*"); + String comper; + if (split.length > 4) { + split[4] = null; + } + comper = split[1] + split[3]; + if (firstFlag) { + temp.add(comper); + firstFlag = false; + return "port:" + split[0] + ":host:" + split[1] + ":proxy:" + split[3]; + } + for (int t = 0; t < temp.size(); t++) { + if (!(comper.equals(temp.get(t)))) { + if (t == temp.size() - 1) { + temp.add(comper); + return "port:" + split[0] + ":host:" + split[1] + ":proxy:" + split[3]; + } + } else { + break; + } + } + return null; + } + + @Override + public void itemStateChanged(ItemEvent e) { } }
--- a/src/myVncProxy/AcceptClient.java Mon Dec 12 12:50:08 2011 +0900 +++ b/src/myVncProxy/AcceptClient.java Tue Dec 20 18:09:34 2011 +0900 @@ -230,7 +230,6 @@ } class Child { - void reportLastNode(String hiddenchild, String newparent, String newtreenum, String newpnum, String newleaderflag, int i) throws IOException { @@ -238,15 +237,12 @@ Socket echoSocket; System.out.println(hiddenchild + "に接続します"); echoSocket = new Socket(hiddenchild, 10001 + (i + 1));// i+1は実験中に同じマシーンを使っていたのでportを変えて対応、本番時には取り除く予定。 - DataOutputStream os = new DataOutputStream( echoSocket.getOutputStream()); - os.writeBytes(newparent + "\n"); os.writeBytes(newpnum + "\n"); os.writeBytes(newtreenum + "\n"); os.writeBytes(newleaderflag + "\n"); - os.close(); } catch (UnknownHostException e) { System.err.println("Don't know about host: localhost"); @@ -254,6 +250,5 @@ System.err .println("Couldn't get I/O for the connection to: localhost"); } - } } \ No newline at end of file
--- a/src/myVncProxy/VncProxyService.java Mon Dec 12 12:50:08 2011 +0900 +++ b/src/myVncProxy/VncProxyService.java Tue Dec 20 18:09:34 2011 +0900 @@ -192,14 +192,15 @@ v.init(); v.start_threads(); - //Thread.sleep(10000); - //rfb.is = v.rfb.is; - //rfb.os = v.rfb.os; - //rfb.initData = v.rfb.initData; + Thread.sleep(10000); + //rfb = v.rfb; + rfb.is = v.rfb.is; + rfb.os = v.rfb.os; + rfb.initData = v.rfb.initData; -// changeConnection(); + //changeConnection(); // doProtocolInitialisation(); - /* + //readParameters(); options = new OptionsNoFrame(this); recordingSync = new Object(); @@ -229,7 +230,7 @@ //acceptThread.changeRfb(rfb); //vc.rfb = rfb; //rfbThread.start(); -*/ + } /*
--- a/src/treeVnc/SelectType.java Mon Dec 12 12:50:08 2011 +0900 +++ b/src/treeVnc/SelectType.java Tue Dec 20 18:09:34 2011 +0900 @@ -54,7 +54,7 @@ setVisible(false); } - void setButton(){ + private void setButton(){ panel.add(button); panel.setBackground(Color.blue); button.addActionListener(this); @@ -63,7 +63,7 @@ } - void checkBox() { + private void checkBox() { CheckboxGroup ch = new CheckboxGroup(); check[0] = new Checkbox("Client",ch,false); check[0].setBackground(new Color(0,153,255));
--- a/src/treeVnc/TreeVnc.java Mon Dec 12 12:50:08 2011 +0900 +++ b/src/treeVnc/TreeVnc.java Tue Dec 20 18:09:34 2011 +0900 @@ -3,28 +3,35 @@ import myVncClient.MyVncClient; import myVncProxy.VncProxyService; -; public class TreeVnc { public static void main(String[] argv) { - SelectType select = new SelectType(); - select.selectType(); - - while (select.wait) { - try { - Thread.sleep(1000); - } catch (InterruptedException e) { - e.printStackTrace(); - } + /* + * SelectType select = new SelectType(); select.selectType(); + * + * while (select.wait) { try { Thread.sleep(1000); } catch + * (InterruptedException e) { e.printStackTrace(); } } + * System.out.println("test"); + */ + if (argv.length == 0) { + System.out.println("client"); + MyVncClient client = new MyVncClient(); + client.treeVncClient(argv); + } else if(argv.length == 1) { + if ("-p".equals(argv[0])) { + System.out.println("proxy"); + String[] temp = new String[0]; + VncProxyService proxy = new VncProxyService(); + proxy.treeVncProxy(temp); + } else { + System.out.println("use : java -jar TreeVnc.jar (IpAddress) 5900"); } - System.out.println("test"); - - if (select.type) { - MyVncClient client = new MyVncClient(); - client.treeVncClient(argv); - } else { - VncProxyService proxy = new VncProxyService(); - proxy.treeVncProxy(argv); - } + } else if(argv.length==2) { + System.out.println("proxy"); + VncProxyService proxy = new VncProxyService(); + proxy.treeVncProxy(argv); + } else{ + System.out.println("use : java -jar TreeVnc.jar (IpAddress) 5900"); + } } }