Mercurial > hg > Members > you > TreeVNC
changeset 22:24112133a0d9
add conf.txt src/treeVnc/ConfFileReader.java
author | Yu Taninari <you@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Fri, 20 Jan 2012 16:06:49 +0900 |
parents | 810c53d66376 |
children | bf3d71746605 |
files | bin/treeVnc/MyRfbProtoClient$1.class bin/treeVnc/MyRfbProtoClient$2.class bin/treeVnc/MyRfbProtoClient$3.class bin/treeVnc/MyRfbProtoClient$4.class bin/treeVnc/MyRfbProtoClient$5$1.class bin/treeVnc/MyRfbProtoClient$5.class bin/treeVnc/MyRfbProtoClient.class bin/treeVnc/MyRfbProtoProxy$1.class bin/treeVnc/MyRfbProtoProxy$2.class bin/treeVnc/MyRfbProtoProxy$3.class bin/treeVnc/MyRfbProtoProxy$4.class bin/treeVnc/MyRfbProtoProxy$5$1.class bin/treeVnc/MyRfbProtoProxy$5.class bin/treeVnc/MyRfbProtoProxy.class conf.txt src/treeVnc/AcceptClient.java src/treeVnc/ConfFileReader.java src/treeVnc/CreateThread.java src/treeVnc/EchoClient.java src/treeVnc/GetBroadCastClient.java src/treeVnc/InterfaceForViewer.java src/treeVnc/MyVncClient.java src/treeVnc/RfbProto.java src/treeVnc/TextBoxClient.java src/treeVnc/TextBoxProxy.java src/treeVnc/TreeVnc.java src/treeVnc/VncCanvas.java src/treeVnc/VncProxyService.java src/treeVnc/WaitReply.java |
diffstat | 29 files changed, 192 insertions(+), 77 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/conf.txt Fri Jan 20 16:06:49 2012 +0900 @@ -0,0 +1,4 @@ +●conf.txtの書き方 +行の先頭にユーザタグ(<user>)を付けて Ipアドレス Port番号 の順番で書きこんで下さい。 +以下の形式が正しい書き方です。 +<user> urasoe.ie.u-ryukyu.ac.jp 5900
--- a/src/treeVnc/AcceptClient.java Sun Jan 15 16:13:09 2012 +0900 +++ b/src/treeVnc/AcceptClient.java Fri Jan 20 16:06:49 2012 +0900 @@ -9,9 +9,10 @@ public class AcceptClient { int counter = 0, parentnum = 0/* 落ちたときの親の番号をカウントするためのもの */; LinkedList<String> ls = new LinkedList<String>(); + boolean addrRegistor = true; + int passNumber=0,numberZone; boolean runflag = false; -// private String name; - boolean addrRegistor = true; + //private String name; int passCheck = 0; int treebranch = 2;// treeの子ノードの数 String newparent,request,myAddress; @@ -21,7 +22,7 @@ public AcceptClient(String name) { -// this.name = name; + //this.name = name; } @@ -31,7 +32,7 @@ // public synchronized void transferParentAddrerss(BufferedReader // is,PrintStream os) { - public synchronized void transferParentAddrerss(BufferedReader is,PrintStream os) { + public void transferParentAddrerss(BufferedReader is,PrintStream os) { // クライアントからのメッセージを待ち、受け取ったメッセージをそのまま返す try { while (true) { @@ -39,10 +40,11 @@ String port = is.readLine(); myAddress = getMyAddress(); if ("1".equals(line)) { - //Parents lost + // reply to Parents lost node replyLeaderNode(os, is, port); + } else if ("2".equals(line)) { - //not Found Parents + // reply to not Found Parents replyNodeInformation(port); listupdate(port, newparent); outputStream(os, newparent, String.valueOf(parentnum), @@ -50,7 +52,7 @@ os.close(); is.close(); } else if ("3".equals(line)) { - //lost time send to not leader children + // At lost time send to not leader children replyNormalChildren(os, is, port); line = null; } else if (line!=null){ @@ -65,8 +67,6 @@ break; } } - } else { - } } } catch (IOException e) { @@ -91,13 +91,13 @@ * @param port * parent value */ - private void listupdate(String port) { + private synchronized void listupdate(String port) { ls.remove(Integer.parseInt(port)); ls.add(Integer.parseInt(port), ls.getLast()); ls.removeLast(); } - private void listupdate(String port,String myaddr) { + private synchronized void listupdate(String port,String myaddr) { ls.remove(Integer.parseInt(port)); ls.add(Integer.parseInt(port), myaddr); ls.removeLast(); @@ -112,12 +112,12 @@ } private void checkParameter(int parent, int counter, String leaderflag) { - System.out.println("p value=" + parentnum); - System.out.println("i value=" + counter); + System.out.println("pの値=" + parentnum); + System.out.println("iの値=" + counter); System.out.println("leaderflag=" + leaderflag + "\n"); } - private void addClientAdress(String line, LinkedList<String> ls) { + private synchronized void addClientAdress(String line, LinkedList<String> ls) { if (line != null) { ls.add(line); } @@ -127,7 +127,7 @@ private void displyLinkedList( LinkedList<String> ls) { int g = 0; for (String bs : ls) { - System.out.println(g + "number" + bs); + System.out.println(g + "番目" + bs); g++; } } @@ -164,10 +164,10 @@ replyNodeInformation(port); counter--; passCheck = 1; - Child report = new Child(); - report.reportLastNode(ls.getLast(), newparent,port, String.valueOf(parentnum), - sendleaderflag, counter); + reportLastNode(ls.getLast(), newparent,port, String.valueOf(parentnum), + sendleaderflag); listupdate(port); + checkWait(Integer.parseInt(checkRepetition)); displyLinkedList(ls); os.println(port); runflag = true; @@ -185,8 +185,20 @@ os.close(); } - private void replyNormalChildren(PrintStream os,BufferedReader is,String port) throws IOException { + private void replyNormalChildren(PrintStream os,BufferedReader is,String port) throws IOException, InterruptedException { String checkRepetition = is.readLine(); + if (Integer.parseInt(checkRepetition)==ls.size()-2) + return; + checkWait(Integer.parseInt(checkRepetition)); + /* + if (Integer.parseInt(checkRepetition) >= ls.size()) { + if ( ls.get(Integer.parseInt(checkRepetition)) == ls.get(1)) + return; + } else { + if(ls.get(Integer.parseInt(checkRepetition)) == ls.getLast()) + return; + } + */ os.println(ls.get(Integer.parseInt(port))); os.println(port); if(ls.size()-1+passCheck == Integer.parseInt(checkRepetition)) @@ -229,16 +241,14 @@ return false; } -} - -class Child { - void reportLastNode(String hiddenchild, String newparent, - String newtreenum, String newpnum, String newleaderflag, int i) - throws IOException { + void reportLastNode(String newchild, String newparent, String newtreenum, + String newpnum, String newleaderflag) throws IOException { try { Socket echoSocket; - System.out.println(hiddenchild + "に接続します"); - echoSocket = new Socket(hiddenchild, 10001 + (i + 1));// i+1は実験中に同じマシーンを使っていたのでportを変えて対応、本番時には取り除く予定。 + System.out.println(newchild + "connect"); + // echoSocket = new Socket(newchild, 10001 + (i + 1));// + // i+1は実験中に同じマシーンを使っていたのでportを変えて対応、本番時には取り除く予定。 + echoSocket = new Socket(newchild, 10001); DataOutputStream os = new DataOutputStream( echoSocket.getOutputStream()); os.writeBytes(newparent + "\n"); @@ -253,4 +263,42 @@ .println("Couldn't get I/O for the connection to: localhost"); } } + + void reportFinishFlag(String nextLastNode) { + Socket echoSocket; + try { + echoSocket = new Socket(nextLastNode, 10001); + DataOutputStream os = new DataOutputStream( + echoSocket.getOutputStream()); + os.writeBytes("lastnode" + "\n"); + } catch (UnknownHostException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + + } + + synchronized void checkWait(int treenum) throws InterruptedException { + while (true) { + if (passNumber == 0) { + passNumber++; + numberZone = ( (treenum-1) / treebranch); + wait(); + break; + } else if (numberZone == ( (treenum-1) / treebranch)) { + if (++passNumber == treebranch) { + notifyAll(); + break; + } else { + passNumber++; + wait(); + } + } else { + wait(); + continue; + } + } + } + } \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/treeVnc/ConfFileReader.java Fri Jan 20 16:06:49 2012 +0900 @@ -0,0 +1,45 @@ +package treeVnc; + +import java.io.*; +import java.util.LinkedList; + + +public class ConfFileReader { + private LinkedList<String> name = new LinkedList<String>(); + private LinkedList<Integer> port = new LinkedList<Integer>(); + + public void fileRead() { + try { + FileReader in = new FileReader("conf.txt"); + BufferedReader br = new BufferedReader(in); + String line; + while ((line = br.readLine()) != null) { + spilitAndWrite(line); + } + br.close(); + in.close(); + } catch (IOException e) { + System.out.println(e); + } + for(String n : name) + System.out.println("name:"+n); + for(int p : port) + System.out.println("port:"+p); + } + + private void spilitAndWrite(String line) { + String[] temp = line.split(" "); + if("<user>".equals(temp[0])) { + name.add(temp[1]); + port.add(Integer.parseInt(temp[2])); + } + } + + public LinkedList<String> getName() { + return name; + } + + public LinkedList<Integer> getPort() { + return port; + } +}
--- a/src/treeVnc/CreateThread.java Sun Jan 15 16:13:09 2012 +0900 +++ b/src/treeVnc/CreateThread.java Fri Jan 20 16:06:49 2012 +0900 @@ -18,7 +18,7 @@ port = 9999; } - public CreateThread(AcceptClient _acc , int port) { + public CreateThread(int port,AcceptClient _acc) { acceptClient = _acc; this.port = port; } @@ -26,6 +26,7 @@ void newEchoClient(final BufferedReader is,final PrintStream os) { Runnable echoSender = new Runnable() { public void run() { + // AcceptClient acceptClient = new AcceptClient(); // acceptClient new acceptClient.transferParentAddrerss(is,os); }
--- a/src/treeVnc/EchoClient.java Sun Jan 15 16:13:09 2012 +0900 +++ b/src/treeVnc/EchoClient.java Fri Jan 20 16:06:49 2012 +0900 @@ -230,7 +230,7 @@ System.out.println("Server: " + responseLine); } if ((parent = is.readLine()) != null) { - System.out.println("parent: " + parent); + System.out.println("parent:test " + parent); } if ((checkRepetition = is.readLine()) != null) { System.out.println("checkRepetition: " + checkRepetition);
--- a/src/treeVnc/GetBroadCastClient.java Sun Jan 15 16:13:09 2012 +0900 +++ b/src/treeVnc/GetBroadCastClient.java Fri Jan 20 16:06:49 2012 +0900 @@ -37,7 +37,7 @@ void socketClose() { try { text.unVisible(); - server.close(); + //server.close(); after the modify is.close(); } catch (IOException e) { e.printStackTrace();
--- a/src/treeVnc/InterfaceForViewer.java Sun Jan 15 16:13:09 2012 +0900 +++ b/src/treeVnc/InterfaceForViewer.java Fri Jan 20 16:06:49 2012 +0900 @@ -28,4 +28,5 @@ public void close(); public Image getScreenImage(); public void writeScreenData(byte[] b, String imageFormat); + }
--- a/src/treeVnc/MyVncClient.java Sun Jan 15 16:13:09 2012 +0900 +++ b/src/treeVnc/MyVncClient.java Fri Jan 20 16:06:49 2012 +0900 @@ -2,7 +2,6 @@ import java.awt.*; import java.awt.event.*; -import java.awt.image.BufferedImage; import java.io.*; import java.net.*; import java.util.Random; @@ -21,13 +20,13 @@ private Socket clientSocket = null; private String parent, treenum; private String leaderflag; - private boolean runflag = false; + //private boolean runflag = false; private boolean first = true; private EchoClient echoValue; private int echoPort; private String pHost; - //private TextBox getHost; + private TextBoxClient getHost; private GetBroadCastClient getBcast; private Thread runBcast; private BroadCastClient bCast; @@ -66,17 +65,24 @@ } if(mainArgs.length == 0) getBcast.setStopFlag(true); - + else { + getHost = new TextBoxClient(); + getHost.ipRegister(); + } + + if (mainArgs.length > 0) - pHost = mainArgs[0]; + pHost = getHost.getAddressOption(); + //pHost = mainArgs[0]; else { pHost = getBcast.text.getAddress(); } //pHost = "cls080.ie.u-ryukyu.ac.jp"; - if (mainArgs.length > 1) - port = Integer.parseInt(mainArgs[1]); + if (mainArgs.length > 0) + port = Integer.parseInt(getHost.getPortOption()); + //port = Integer.parseInt(mainArgs[1]); else { port = Integer.parseInt(getBcast.text.getPort()); getBcast.socketClose(); @@ -87,10 +93,6 @@ start(); } - // - // init() - // - public void init() { readParameters(); @@ -170,9 +172,6 @@ createCanvas(0, 0); - // rfb.readPngData(); - // vc.drawFirstImage(); - } catch (IOException e) { try { rfb.sock.close(); @@ -185,7 +184,7 @@ Random rnd = new Random(); long ran = rnd.nextInt(3000) + 3000; System.out.println(ran); - // 親がいない場合の処理はここに書く!!!! + /** * this while reconnection */ @@ -214,13 +213,6 @@ } echoValue.openport(); - /* - if(echoValue.notfoundParent()) { - break; - } - */ - // runflag = echo.losthost(); - if (echoValue.losthost()) { break; @@ -228,39 +220,31 @@ counter++; } - - // System.exit(0); } catch (Exception e) { System.out.println(e); System.exit(0); } - gbc.weightx = 1.0; gbc.weighty = 1.0; - + if (inSeparateFrame) { - // Create a panel which itself is resizeable and can hold // non-resizeable VncCanvas component at the top left corner. Panel canvasPanel = new Panel(); canvasPanel.setLayout(new FlowLayout(FlowLayout.LEFT, 0, 0)); canvasPanel.add(vc); - // Create a ScrollPane which will hold a panel with VncCanvas // inside. desktopScrollPane = new ScrollPane(ScrollPane.SCROLLBARS_AS_NEEDED); gbc.fill = GridBagConstraints.BOTH; gridbag.setConstraints(desktopScrollPane, gbc); desktopScrollPane.add(canvasPanel); - // Finally, add our ScrollPane to the Frame window. vncFrame.add(desktopScrollPane); vncFrame.setTitle(rfb.desktopName); vncFrame.pack(); vc.resizeDesktopFrame(); - } else { - // Just add the VncCanvas component to the Applet. gridbag.setConstraints(vc, gbc); add(vc); @@ -297,6 +281,7 @@ if (echoValue.losthost()) { break; } + } } else { @@ -1254,5 +1239,16 @@ e.printStackTrace(); } } + + private boolean serverConfirm(String name,int port) { + try{ + new Socket(name,port); + return true; + } + catch (IOException e){ + return false; + } + + } }
--- a/src/treeVnc/RfbProto.java Sun Jan 15 16:13:09 2012 +0900 +++ b/src/treeVnc/RfbProto.java Fri Jan 20 16:06:49 2012 +0900 @@ -992,10 +992,12 @@ int mask2 = 2; int mask3 = 4; + /* if (viewer.options.reverseMouseButtons2And3) { mask2 = 4; mask3 = 2; } + */ // Note: For some reason, AWT does not set BUTTON1_MASK on left // button presses. Here we think that it was the left button if
--- a/src/treeVnc/TextBoxClient.java Sun Jan 15 16:13:09 2012 +0900 +++ b/src/treeVnc/TextBoxClient.java Fri Jan 20 16:06:49 2012 +0900 @@ -27,18 +27,20 @@ private String hostAddress; private String port; private CheckboxGroup ch = new CheckboxGroup(); + + public TextBoxClient() { + setTitle("Informatin Connection Address"); + setResizable(false); + setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + } + public void ipRegister() { setSize(); setText(); visible(); } - public TextBoxClient() { - setTitle("Informatin Connection Address"); - setResizable(false); - setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); - } private void setSize() { Dimension d = Toolkit.getDefaultToolkit().getScreenSize(); @@ -102,6 +104,17 @@ label.setFont(new Font("Arial", Font.PLAIN, 20)); pane.add(label); } + + public String getAddressOption() { + while (!(flag)) { + try { + Thread.sleep(500); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + return t1.getText(); + } public String getAddress() { int i = 0; @@ -121,7 +134,11 @@ return hostAddress; // return t1.getText(); } - + + public String getPortOption() { + return t2.getText(); + } + public String getPort() { return port; // return t2.getText();
--- a/src/treeVnc/TextBoxProxy.java Sun Jan 15 16:13:09 2012 +0900 +++ b/src/treeVnc/TextBoxProxy.java Fri Jan 20 16:06:49 2012 +0900 @@ -76,11 +76,11 @@ panel = new JPanel(); t1 = new TextField("localhost", 30); t2 = new TextField("5900", 5); - pw = new JPasswordField("Password",30); +// pw = new JPasswordField("Password",30); button = new JButton("Connect"); panel.add(t1); panel.add(t2); - panel.add(pw); +// panel.add(pw); panel.add(button); button.addActionListener(this); label = new JLabel(); @@ -103,10 +103,12 @@ return t2.getText(); } + public String getPassword() { return String.valueOf(pw.getPassword()); } + public void actionPerformed(ActionEvent e) { if(e.getSource()==button) { flag = true;
--- a/src/treeVnc/TreeVnc.java Sun Jan 15 16:13:09 2012 +0900 +++ b/src/treeVnc/TreeVnc.java Fri Jan 20 16:06:49 2012 +0900 @@ -13,7 +13,7 @@ * (InterruptedException e) { e.printStackTrace(); } } * System.out.println("test"); */ - if (argv.length == 0) { + if (argv.length == 0 || "-c".equals(argv[0])) { System.out.println("client"); MyVncClient client = new MyVncClient(); client.treeVncClient(argv);
--- a/src/treeVnc/VncCanvas.java Sun Jan 15 16:13:09 2012 +0900 +++ b/src/treeVnc/VncCanvas.java Fri Jan 20 16:06:49 2012 +0900 @@ -572,7 +572,7 @@ throw new Exception("Unknown RFB message type " + msgType); } bufSize = rfbc.getNumBytesRead() - bufSize; - System.out.println("bufSize="+bufSize); +// System.out.println("bufSize="+bufSize); // rfb.bufResetSend((int)bufSize); if(rfbc.createBimgFlag){
--- a/src/treeVnc/VncProxyService.java Sun Jan 15 16:13:09 2012 +0900 +++ b/src/treeVnc/VncProxyService.java Fri Jan 20 16:06:49 2012 +0900 @@ -339,7 +339,7 @@ // acc = new AcceptClient(); else acc = new AcceptClient(mainArgs[0]); - geth = new CreateThread(acc, echoPort); + geth = new CreateThread(echoPort,acc); Thread thread = new Thread(geth); thread.start(); @@ -480,6 +480,7 @@ * * authPanel.moveFocusToDefaultField(); vncContainer.remove(authPanel); */ + showConnectionStatus("ask password..."); String pw; if (mainArgs.length != 0)
--- a/src/treeVnc/WaitReply.java Sun Jan 15 16:13:09 2012 +0900 +++ b/src/treeVnc/WaitReply.java Fri Jan 20 16:06:49 2012 +0900 @@ -31,12 +31,10 @@ while (true) { try { - echoServer = new ServerSocket(10001 + Integer.parseInt(treenum)); - } catch (IOException e) { - System.out.println(e); - } - try { + //echoServer = new ServerSocket(10001 + Integer.parseInt(treenum)); + echoServer = new ServerSocket(10001); clientSocket = echoServer.accept(); + if (clientSocket != null) { client.close(); passflag = true;