Mercurial > hg > Members > nobuyasu > tightVNCClient
diff src/myVncClient/CuiMyVncClient.java @ 69:1f05b73b15df
modify MyVncClient.java and CuiMyVNcClient.java
author | e085711 |
---|---|
date | Sun, 07 Aug 2011 04:22:07 +0900 |
parents | 5e7110277cf0 |
children | affdcbdc90ea |
line wrap: on
line diff
--- a/src/myVncClient/CuiMyVncClient.java Sat Aug 06 23:34:37 2011 +0900 +++ b/src/myVncClient/CuiMyVncClient.java Sun Aug 07 04:22:07 2011 +0900 @@ -9,7 +9,7 @@ import myVncClient.AcceptThread; import myVncClient.OptionsNoFrame; -public class CuiMyVncClient implements InterfaceForViewer, java.lang.Runnable { +public class CuiMyVncClient implements InterfaceForViewer { public static void main(String[] argv) { CuiMyVncClient v = new CuiMyVncClient(); @@ -75,6 +75,7 @@ String parent, treenum; private String leaderflag; boolean runflag = false; + boolean first = true; EchoClient echo; @@ -95,7 +96,13 @@ // public void init(EchoClient value) { - + Random rnd = new Random(); + long ran = rnd.nextInt(5000); + try { + Thread.sleep(ran); + } catch (InterruptedException e1) { + e1.printStackTrace(); + } // readParameters(); readParameters(value); @@ -133,7 +140,12 @@ public void run() { try { - connectAndAuthenticate(); + if (first) { + connectAndAuthenticate(); + first = false; + }else { + reConnectAndAuthenticate(); + } accThread = new Thread(new AcceptThread(rfb, 5999)); accThread.start(); doProtocolInitialisation(); @@ -153,10 +165,11 @@ */ int counter = 0; - // window を消してnullを突っ込んでGCで削除させる。 + /* - * vncFrame.setVisible(false); vncFrame = null; - */ + vncFrame.setVisible(false); + vncFrame.dispose(); +*/ while (true) { /** * if my last node case reconnectoion stop @@ -177,19 +190,18 @@ echo.openport(); // runflag = echo.losthost(); if (echo.losthost()) { - break; + return; } counter++; } // System.exit(0); - } catch (Exception e) { + }catch (Exception e) { System.out.println(e); System.exit(0); } - - try { - + try{ + processNormalProtocol();// main loop } catch (NoRouteToHostException e) { @@ -316,6 +328,54 @@ } } + + + void reConnectAndAuthenticate() throws Exception { + showConnectionStatus("Initializing..."); + + showConnectionStatus("Connecting to " + host + ", port " + port + "..."); + + rfb.changeParent(host, port); + + showConnectionStatus("Connected to server"); + + rfb.readVersionMsg(); + showConnectionStatus("RFB server supports protocol version " + + rfb.serverMajor + "." + rfb.serverMinor); + + rfb.writeVersionMsg(); + showConnectionStatus("Using RFB protocol version " + rfb.clientMajor + + "." + rfb.clientMinor); + + int secType = rfb.negotiateSecurity(); + int authType; + if (secType == RfbProto.SecTypeTight) { + showConnectionStatus("Enabling TightVNC protocol extensions"); + rfb.setupTunneling(); + authType = rfb.negotiateAuthenticationTight(); + } else { + authType = secType; + } + + switch (authType) { + case RfbProto.AuthNone: + showConnectionStatus("No authentication needed"); + rfb.authenticateNone(); + break; + case RfbProto.AuthVNC: + showConnectionStatus("Performing standard VNC authentication"); + if (passwordParam != null) { + rfb.authenticateVNC(passwordParam); + } else { + String pw = askPassword(); + rfb.authenticateVNC(pw); + } + break; + default: + throw new Exception("Unknown authentication scheme " + authType); + } + } + // // Show a message describing the connection status. // To hide the connection status label, use (msg == null).