Mercurial > hg > Members > you > TreeVNC
diff src/treeVnc/MyVncClient.java @ 27:41b2e2ebcff2
modify AcceptClient.java
author | one |
---|---|
date | Sat, 28 Jan 2012 03:26:02 +0900 |
parents | cbbdabc7645f |
children | a477a210a39a |
line wrap: on
line diff
--- a/src/treeVnc/MyVncClient.java Mon Jan 23 20:49:46 2012 +0900 +++ b/src/treeVnc/MyVncClient.java Sat Jan 28 03:26:02 2012 +0900 @@ -20,10 +20,10 @@ 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 EchoClient echoValue; private int echoPort; private String pHost; private TextBoxClient getHost; @@ -49,61 +49,69 @@ System.out.println(mainArgs.length); inAnApplet = false; inSeparateFrame = true; - -// if(mainArgs.length == 0) { + if (mainArgs.length != 0) { + if ("-c".equals(argv[0])) { + getHost = new TextBoxClient(); + getHost.ipRegister(); + pHost = getHost.getAddressOption(); + port = Integer.parseInt(getHost.getPortOption()); + } else { + bCast = new BroadCastClient("who"); + bCast.createSocket(); + bCast.sendData(); + getBcast = new GetBroadCastClient(); + if ("-reg".equals(argv[0]) && getNamePort() != null) { + getBcast.text.checkBox(getNamePort()); + getBcast.text.setButton(); + getBcast.text.visible(); + } else { + runBcast = new Thread(getBcast); + runBcast.start(); + getBcast.setStopFlag(true); + } + pHost = getBcast.text.getAddress(); + port = Integer.parseInt(getBcast.text.getPort()); + if (!("-reg".equals(argv[0]))) + getBcast.socketClose(); + + } + } else { bCast = new BroadCastClient("who"); bCast.createSocket(); bCast.sendData(); getBcast = new GetBroadCastClient(); - if(getNamePort() != null) - getBcast.text.checkBox(getNamePort()); runBcast = new Thread(getBcast); runBcast.start(); -// } - - //getBcast.text.checkBox(getNamePort()); - /* - try { - Thread.sleep(1000); - } catch (InterruptedException e) { - e.printStackTrace(); - } getBcast.setStopFlag(true); pHost = getBcast.text.getAddress(); port = Integer.parseInt(getBcast.text.getPort()); - getBcast.socketClose(); - - */ - - - if(mainArgs.length == 0) - getBcast.setStopFlag(true); - else { - getHost = new TextBoxClient(); - getHost.ipRegister(); } - if (mainArgs.length > 0) - pHost = getHost.getAddressOption(); - //pHost = mainArgs[0]; - else { - pHost = getBcast.text.getAddress(); - } - - - //pHost = "cls080.ie.u-ryukyu.ac.jp"; - if (mainArgs.length > 0) - port = Integer.parseInt(getHost.getPortOption()); - //port = Integer.parseInt(mainArgs[1]); - else { - port = Integer.parseInt(getBcast.text.getPort()); - getBcast.socketClose(); -// port = 5999; - } + // getBcast.text.checkBox(getNamePort()); + /* + * try { Thread.sleep(1000); } catch (InterruptedException e) { + * e.printStackTrace(); } + */ + /* + * + * if(mainArgs.length == 0) getBcast.setStopFlag(true); else { getHost = + * new TextBoxClient(); getHost.ipRegister(); } + * + * if (mainArgs.length > 0) pHost = getHost.getAddressOption(); //pHost + * = mainArgs[0]; else { pHost = getBcast.text.getAddress(); } + * + * + * //pHost = "cls080.ie.u-ryukyu.ac.jp"; if (mainArgs.length > 0) port = + * Integer.parseInt(getHost.getPortOption()); //port = + * Integer.parseInt(mainArgs[1]); else { port = + * Integer.parseInt(getBcast.text.getPort()); getBcast.socketClose(); // + * port = 5999; } + */ init(); start_threads(); start(); + } public void init() { @@ -177,8 +185,8 @@ } else { System.out.println("reConnectAndAuthenticate() "); reConnectAndAuthenticate(); - //accThread = new Thread(new AcceptThread(rfb, 5999)); - //accThread.start(); + // accThread = new Thread(new AcceptThread(rfb, 5999)); + // accThread.start(); } doProtocolInitialisation(); @@ -226,11 +234,11 @@ } echoValue.openport(); - - if (echoValue.losthost()) { + + if (echoValue.lostHost()) { break; } - + counter++; } } catch (Exception e) { @@ -239,7 +247,7 @@ } 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. @@ -291,7 +299,7 @@ echoValue = new EchoClient(echoValue); echoValue.openport(); // runflag = echo.losthost(); - if (echoValue.losthost()) { + if (echoValue.lostHost()) { break; } @@ -416,8 +424,8 @@ if (rfb.serverMinor == 855) { /* - * if connect to proxy, userEchoPortFlag is true. - * if connect to client, userEchoPortFlag is false. + * if connect to proxy, userEchoPortFlag is true. if connect to + * client, userEchoPortFlag is false. */ boolean useEchoPortFlag = rfb.readProxyFlag(); if (useEchoPortFlag) { @@ -425,7 +433,6 @@ b = rfb.readEchoPort(); echoPort = castByteInt(b); - InetAddress addr = InetAddress.getByName(pHost); String h = new String(addr.getHostAddress()); @@ -434,7 +441,7 @@ rfb.changeParent(host, port); rfb.readVersionMsg(); rfb.writeVersionMsg(); - boolean flag = rfb.readProxyFlag(); + boolean flag = rfb.readProxyFlag(); } } } @@ -1242,34 +1249,32 @@ public Image getScreenImage() { return vc.rawPixelsImage; } - + public void writeScreenData(byte[] b, String imageFormat) { - try{ + try { vc.drawBufferedImage(b); - }catch(IOException e){ + } catch (IOException e) { e.printStackTrace(); } } - + private String getNamePort() { - ConfFileReader crf = new ConfFileReader(); - crf.fileRead(); - for(int i=0 ; i < crf.getName().size() ; i++) { - if(serverConfirm(crf.getName().get(i),crf.getPort().get(i))) - return crf.getName().get(i)+":"+crf.getPort().get(i); + ConfFileReader cfr = new ConfFileReader(); + cfr.fileRead(); + for (int i = 0; i < cfr.getName().size(); i++) { + if (serverConfirm(cfr.getName().get(i), cfr.getPort().get(i))) + return cfr.getName().get(i) + ":" + cfr.getPort().get(i); } return null; } - - - private boolean serverConfirm(String name,int port) { - try{ - new Socket(name,port); - return true; - } - catch (IOException e){ - return false; - } + + private boolean serverConfirm(String name, int port) { + try { + new Socket(name, port); + return true; + } catch (IOException e) { + return false; + } } }