# HG changeset patch # User e085711 # Date 1314690151 -32400 # Node ID 7d25b08f583537cae3c26be7625fa7183af3c756 # Parent 83acdeca0539da146826f897b7600df58080bb68 modify CuiMyVncClient diff -r 83acdeca0539 -r 7d25b08f5835 src/myVncClient/CuiMyVncClient.java --- a/src/myVncClient/CuiMyVncClient.java Tue Aug 30 06:59:57 2011 +0900 +++ b/src/myVncClient/CuiMyVncClient.java Tue Aug 30 16:42:31 2011 +0900 @@ -4,6 +4,7 @@ import java.awt.event.*; import java.io.*; import java.net.*; +import java.nio.ByteBuffer; import java.util.Random; import myVncClient.AcceptThread; @@ -13,14 +14,18 @@ public static void main(String[] argv) { CuiMyVncClient v = new CuiMyVncClient(); + v.echovalue = null; v.runClient(argv, v); } private void runClient(String[] argv, CuiMyVncClient v) { mainArgs = argv; + + host = mainArgs[0]; + port = Integer.parseInt(mainArgs[1]); - v.init(null); + v.init(); v.start_threads(); } @@ -77,8 +82,9 @@ boolean runflag = false; boolean first = true; + EchoClient echovalue; EchoClient echo; - + void checkArgs(String[] argv) { if (argv.length > 3) { username = argv[3]; @@ -95,7 +101,7 @@ // init() // - public void init(EchoClient value) { + public void init() { Random rnd = new Random(); long ran = rnd.nextInt(5000); @@ -104,9 +110,9 @@ } catch (InterruptedException e) { e.printStackTrace(); } - // readParameters(); - - readParameters(value); + + readParameters(); + //readParameters(value); options = new OptionsNoFrame(this); recordingSync = new Object(); @@ -177,7 +183,7 @@ * if my last node case reconnectoion stop */ - echo = new EchoClient(echo, this); + echovalue = new EchoClient(echo, this); try { Thread.sleep(ran); } catch (InterruptedException e1) { @@ -185,13 +191,13 @@ } if (counter >= 3) { - echo.openport(); - echo.notfoundParent(); + echovalue.openport(); + echovalue.notfoundParent(); } - echo.openport(); + echovalue.openport(); // runflag = echo.losthost(); - if (echo.losthost()) { + if (echovalue.losthost()) { break; } counter++; @@ -216,10 +222,10 @@ if (leaderflag != null) { while (true) { - echo = new EchoClient(echo, this); - echo.openport(); + echovalue = new EchoClient(echovalue, this); + echovalue.openport(); // runflag = echo.losthost(); - if (echo.losthost()) { + if (echovalue.losthost()) { break; } } @@ -300,6 +306,19 @@ showConnectionStatus("Using RFB protocol version " + rfb.clientMajor + "." + rfb.clientMinor); + if(rfb.serverMinor == 998) { + byte[] b = new byte[4]; + b = rfb.readEchoPort(); + int echoPort = castByteInt(b); + String h = host; + getParentname(echovalue, echoPort); + if(h.equals(host)) { + rfb.changeParent(host, port); + rfb.readVersionMsg(); + } + } + + int secType = rfb.negotiateSecurity(); int authType; if (secType == RfbProto.SecTypeTight) { @@ -648,8 +667,8 @@ // those expected in the html applet tag source. // - void readParameters(EchoClient value) { - /* + void readParameters() { + /* * host = readParameter("HOST", !inAnApplet); * * if (host == null) { host = getCodeBase().getHost(); if @@ -657,48 +676,7 @@ * * port = readIntParameter("PORT", 5550); */ - if (value == null) { - if (clientSocket == null) { - String pHost; - if (mainArgs.length > 0) - pHost = mainArgs[0]; - else - pHost = "cls080.ie.u-ryukyu.ac.jp"; - echo = new EchoClient(pHost, this); - echo.openport(); - - value = echo.hostn("1"); - } else { - echo = new EchoClient(); - value = echo.Interruption(clientSocket); - } - } - // proxyからの返信で接続先を決定する - host = value.responseLine; - parent = value.parent; - if (value.treenum != null) { - treenum = value.treenum; - } else { - treenum = echo.treenum; - } - if (value.leaderflag != null) { - leaderflag = value.leaderflag; - } else { - leaderflag = echo.leaderflag; - } - System.out.println("Parent =" + parent); - System.out.println("mynumber =" + treenum); - System.out.println("connect host =" + host); - System.out.println("leaderflag(boolean) = " + leaderflag); - - echo = value; - - /* - * if (host == null) { host = getCodeBase().getHost(); if - * (host.equals("")) { fatalError("HOST parameter not specified"); } } - */ - port = 5999; // Read "ENCPASSWORD" or "PASSWORD" parameter if specified. // readPasswordParameters(); @@ -989,5 +967,61 @@ vncFrame.setVisible(false); vncFrame.dispose(); } + void getParentname(EchoClient value, int echoPort) { + if (value == null) { + if (clientSocket == null) { + String pHost; + if (mainArgs.length > 0) + pHost = mainArgs[0]; + else + pHost = "cls080.ie.u-ryukyu.ac.jp"; +// echo = new EchoClient(pHost, this); + echo = new EchoClient(pHost, this, echoPort); + echo.openport(); + + value = echo.hostn("1"); + } else { + echo = new EchoClient(); + value = echo.Interruption(clientSocket); + } + } + + } + + int castByteInt(byte[] b) { + ByteBuffer bb = ByteBuffer.wrap(b); + int value = bb.getInt(); + return value; + } + + + + public static void main(Socket _clientSocket) { + MyVncClient v = new MyVncClient(); + // v.clientSocket = _clientSocket; + // v.mainArgs = argv; + v.inAnApplet = false; + v.inSeparateFrame = true; + + v.echovalue = null; + + v.init(); + v.start_threads(); + v.start(); + } + + public static void main(EchoClient value) { + MyVncClient v = new MyVncClient(); + v.inAnApplet = false; + v.inSeparateFrame = true; + + v.echovalue = value; + + v.init(); + v.start_threads(); + v.start(); + + } + } diff -r 83acdeca0539 -r 7d25b08f5835 src/myVncClient/EchoClient.java --- a/src/myVncClient/EchoClient.java Tue Aug 30 06:59:57 2011 +0900 +++ b/src/myVncClient/EchoClient.java Tue Aug 30 16:42:31 2011 +0900 @@ -28,40 +28,44 @@ } // VncViewerから引数をもらってきてproxy役を認識する - public EchoClient(String _name,MyVncClient client) { + public EchoClient(String name,MyVncClient client) { this.client = client; - name = _name; + this.name = name; } - public EchoClient(String _name,MyVncClient client, int echoPort) { + public EchoClient(String name,MyVncClient client, int echoPort) { this.client = client; - name = _name; + this.name = name; this.echoPort = echoPort; } - public EchoClient(EchoClient echo,MyVncClient client) { this.client = client; - name = echo.name; + this.name = echo.name; leaderflag = echo.leaderflag; parent = echo.parent; treenum = echo.treenum; } - public EchoClient(String _name,CuiMyVncClient client) { + public EchoClient(String name,CuiMyVncClient client) { this.client = client; - name = _name; + this.name = name; } + public EchoClient(String name,CuiMyVncClient client, int echoPort) { + this.client = client; + this.name = name; + this.echoPort = echoPort; + } + public EchoClient(EchoClient echo,CuiMyVncClient client) { this.client = client; - name = echo.name; + this.name = echo.name; leaderflag = echo.leaderflag; parent = echo.parent; treenum = echo.treenum; } - // void hostn(String args){ void openport() { //  ソケットや入出力用のストリームの宣言 @@ -171,7 +175,7 @@ * System.out.println("treenum: " + value.treenum); } */ Thread.sleep(1000); - client.init(this); + client.init(); client.start_threads(); client.start(); // MyVncClient.main(this); @@ -235,7 +239,7 @@ if ((leaderflag = is.readLine()) != null) { System.out.println("parent: " + leaderflag); } - client.init(this); + client.init(); client.start_threads(); client.start(); os.close(); diff -r 83acdeca0539 -r 7d25b08f5835 src/myVncClient/InterfaceForViewer.java --- a/src/myVncClient/InterfaceForViewer.java Tue Aug 30 06:59:57 2011 +0900 +++ b/src/myVncClient/InterfaceForViewer.java Tue Aug 30 16:42:31 2011 +0900 @@ -5,7 +5,7 @@ public interface InterfaceForViewer extends java.lang.Runnable{ - public void init(EchoClient value); + public void init(); public void start_threads(); public void start(); diff -r 83acdeca0539 -r 7d25b08f5835 src/myVncClient/MyVncClient.java --- a/src/myVncClient/MyVncClient.java Tue Aug 30 06:59:57 2011 +0900 +++ b/src/myVncClient/MyVncClient.java Tue Aug 30 16:42:31 2011 +0900 @@ -22,7 +22,8 @@ private String leaderflag; boolean runflag = false; boolean first = true; - + + EchoClient echo; EchoClient echovalue; // // main() is called when run as a java program from the command line. @@ -43,7 +44,7 @@ host = mainArgs[0]; port = Integer.parseInt(mainArgs[1]); - init(null); + init(); start_threads(); start(); } @@ -52,10 +53,9 @@ // init() // - public void init(EchoClient value) { + public void init() { readParameters(); -// readParameters(); refApplet = this; @@ -1170,7 +1170,7 @@ v.echovalue = null; - v.init(null); + v.init(); v.start_threads(); v.start(); } @@ -1182,7 +1182,7 @@ v.echovalue = value; - v.init(value); + v.init(); v.start_threads(); v.start(); diff -r 83acdeca0539 -r 7d25b08f5835 src/myVncClient/VncViewer.java --- a/src/myVncClient/VncViewer.java Tue Aug 30 06:59:57 2011 +0900 +++ b/src/myVncClient/VncViewer.java Tue Aug 30 16:42:31 2011 +0900 @@ -32,7 +32,6 @@ MyRfbProto rfb; Thread rfbThread; Thread accThread; - EchoClient echo; Frame vncFrame; Container vncContainer; diff -r 83acdeca0539 -r 7d25b08f5835 src/myVncClient/WaitReply.java --- a/src/myVncClient/WaitReply.java Tue Aug 30 06:59:57 2011 +0900 +++ b/src/myVncClient/WaitReply.java Tue Aug 30 16:42:31 2011 +0900 @@ -42,7 +42,7 @@ // client.clientSocket = clientSocket; client.setClientSocket(clientSocket); - client.init(null); + client.init(); client.start_threads(); client.start(); //MyVncClient.main(clientSocket);