Mercurial > hg > Members > nobuyasu > tightVNCClient
changeset 32:6ddc79804a08
modify MyVncClient.java
author | e085711 |
---|---|
date | Thu, 07 Jul 2011 14:24:55 +0900 |
parents | bf1126d1e721 |
children | 241f95cf0c0c |
files | src/myVncClient/MyVncClient.java |
diffstat | 1 files changed, 96 insertions(+), 105 deletions(-) [+] |
line wrap: on
line diff
--- a/src/myVncClient/MyVncClient.java Wed Jul 06 15:07:31 2011 +0900 +++ b/src/myVncClient/MyVncClient.java Thu Jul 07 14:24:55 2011 +0900 @@ -7,14 +7,15 @@ import myVncClient.acceptThread; -public class MyVncClient extends VncViewer implements - java.lang.Runnable, WindowListener { +public class MyVncClient extends VncViewer implements java.lang.Runnable, + WindowListener { boolean inAnApplet = true; boolean inSeparateFrame = false; - static Socket clientSocket = null; - String parent,treenum; - Revalue value; //include trenumber, parentstnumber,etc + static Socket clientSocket = null; + String parent, treenum; + Revalue value; // include trenumber, parentstnumber,etc + // // main() is called when run as a java program from the command line. // It simply runs the applet inside a newly-created frame. @@ -27,18 +28,17 @@ v.inSeparateFrame = true; v.init(null); + v.start(); } - - // // init() // public void init(Revalue value) { -// readParameters(); + // readParameters(); readParameters(value); refApplet = this; @@ -69,13 +69,8 @@ if (inSeparateFrame) vncFrame.addWindowListener(this); - - rfbThread = new Thread(this); rfbThread.start(); - accThread = new Thread(new acceptThread(rfb)); - accThread.start(); - } public void update(Graphics g) { @@ -100,35 +95,31 @@ vncContainer.add(buttonPanel); } -/*****************************************************************************/ -// vncFrame.pack(); -// vncFrame.setVisible(true); + try { -// rfb = new MyRfbProto(host, port, this); -// rfb.readServerInit(); - connectAndAuthenticate(); + accThread = new Thread(new acceptThread(rfb)); + accThread.start(); + doProtocolInitialisation(); createCanvas(0, 0); - // read & draw Png Data -// rfb.readPngData(); -// vc.drawFirstImage(); + // rfb.readPngData(); + // vc.drawFirstImage(); - } catch (IOException e) { System.out.println("Socket error"); System.exit(0); - } catch (Exception e){ - + } catch (Exception e) { + } gbc.weightx = 1.0; gbc.weighty = 1.0; - if (inSeparateFrame) { + if (inSeparateFrame) { // Create a panel which itself is resizeable and can hold // non-resizeable VncCanvas component at the top left corner. @@ -157,9 +148,7 @@ validate(); } -/*****************************************************************************/ - try { if (showControls) buttonPanel.enableButtons(); @@ -177,49 +166,49 @@ + ":" + port, e); } catch (EOFException e) { - //insert - //リーダーの子ノードがproxyに対して親が落ちたことを報告をする - if ("1".equals(echoClient.value.leaderflag)){ - echo = new echoClient(); - echo.openport(); - echo.losthost(); - } else if ("0".equals(echoClient.value.leaderflag)){ - try { - Thread.sleep(1000); - } catch (InterruptedException e1) { - // TODO Auto-generated catch block - e1.printStackTrace(); - } - echo = new echoClient(); - echo.openport(); - echo.losthost(); - }else{ - + // insert + // リーダーの子ノードがproxyに対して親が落ちたことを報告をする + if ("1".equals(echoClient.value.leaderflag)) { + echo = new echoClient(); + echo.openport(); + echo.losthost(); + } else if ("0".equals(echoClient.value.leaderflag)) { + try { + Thread.sleep(1000); + } catch (InterruptedException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } + echo = new echoClient(); + echo.openport(); + echo.losthost(); + } else { - if (showOfflineDesktop) { - e.printStackTrace(); - System.out - .println("Network error: remote side closed connection"); - if (vc != null) { - vc.enableInput(false); - } - if (inSeparateFrame) { - vncFrame.setTitle(rfb.desktopName + " [disconnected]"); + if (showOfflineDesktop) { + e.printStackTrace(); + System.out + .println("Network error: remote side closed connection"); + if (vc != null) { + vc.enableInput(false); + } + if (inSeparateFrame) { + vncFrame.setTitle(rfb.desktopName + " [disconnected]"); + } + if (rfb != null && !rfb.closed()) + rfb.close(); + if (showControls && buttonPanel != null) { + buttonPanel.disableButtonsOnDisconnect(); + if (inSeparateFrame) { + vncFrame.pack(); + } else { + validate(); + } + } + } else { + fatalError("Network error: remote side closed connection", + e); } - if (rfb != null && !rfb.closed()) - rfb.close(); - if (showControls && buttonPanel != null) { - buttonPanel.disableButtonsOnDisconnect(); - if (inSeparateFrame) { - vncFrame.pack(); - } else { - validate(); - } - } - } else { - fatalError("Network error: remote side closed connection", e); } - } } catch (IOException e) { String str = e.getMessage(); if (str != null && str.length() != 0) { @@ -660,45 +649,46 @@ // void readParameters(Revalue value) { - /* - host = readParameter("HOST", !inAnApplet); + /* + * host = readParameter("HOST", !inAnApplet); + * + * if (host == null) { host = getCodeBase().getHost(); if + * (host.equals("")) { fatalError("HOST parameter not specified"); } } + * + * port = readIntParameter("PORT", 5550); + */ - if (host == null) { host = getCodeBase().getHost(); if - (host.equals("")) { fatalError("HOST parameter not specified"); } } - - port = readIntParameter("PORT", 5550); - */ + if (mainArgs.length > 0) + host = mainArgs[0]; + else + host = "cls080.ie.u-ryukyu.ac.jp"; - if(mainArgs.length > 0)host = mainArgs[0]; - else host = "cls080.ie.u-ryukyu.ac.jp"; - - if(value==null){ - if(clientSocket==null) - { - echo = new echoClient(host); - echo.openport(); - // value = echo.hostn(mainArgs[0]); - value = echo.hostn("1"); - }else{ - echo = new echoClient(); - value = echo.Interruption(clientSocket); - } + if (value == null) { + if (clientSocket == null) { + echo = new echoClient(host); + echo.openport(); + // value = echo.hostn(mainArgs[0]); + value = echo.hostn("1"); + } else { + echo = new echoClient(); + value = echo.Interruption(clientSocket); + } } - //proxyからの返信で接続先を決定する - host=value.responseLine; - parent=value.parent; - treenum=value.treenum; - System.out.println("親は"+parent); - System.out.println("自分の番号"+treenum); - System.out.println("接続先hostは" + host); + // proxyからの返信で接続先を決定する + host = value.responseLine; + parent = value.parent; + treenum = value.treenum; + System.out.println("親は" + parent); + System.out.println("自分の番号" + treenum); + System.out.println("接続先hostは" + host); - if (host == null) { - host = getCodeBase().getHost(); - if (host.equals("")) { - fatalError("HOST parameter not specified"); + if (host == null) { + host = getCodeBase().getHost(); + if (host.equals("")) { + fatalError("HOST parameter not specified"); + } } - } - port = 5550; + port = 5550; // Read "ENCPASSWORD" or "PASSWORD" parameter if specified. readPasswordParameters(); @@ -1020,17 +1010,19 @@ public void windowDeiconified(WindowEvent evt) { } + public static void main(Socket _clientSocket) { // TODO Auto-generated method stub clientSocket = _clientSocket; MyVncClient v = new MyVncClient(); -// v.mainArgs = argv; + // v.mainArgs = argv; v.inAnApplet = false; v.inSeparateFrame = true; v.init(null); v.start(); } + public static void main(Revalue value) { // TODO Auto-generated method stub MyVncClient v = new MyVncClient(); @@ -1040,7 +1032,6 @@ v.init(value); v.start(); - + } } - \ No newline at end of file