Mercurial > hg > Applications > TreeVNC
changeset 54:0ae87c7e767c
bug fix
line wrap: on
line diff
--- a/src/main/java/com/glavsoft/rfb/protocol/ReceiverTask.java Tue Nov 05 17:20:53 2013 +0900 +++ b/src/main/java/com/glavsoft/rfb/protocol/ReceiverTask.java Tue Nov 19 15:29:04 2013 +0900 @@ -133,8 +133,8 @@ counter++; } } else if (isRunning) { - logger.severe("Close proxy: "); - context.cleanUpSession("Connection closed."); +// logger.severe("Close proxy: "); +// context.cleanUpSession("Connection closed."); } stopTask(); } catch (ProtocolException e) {
--- a/src/main/java/com/glavsoft/rfb/protocol/TreeTask.java Tue Nov 05 17:20:53 2013 +0900 +++ b/src/main/java/com/glavsoft/rfb/protocol/TreeTask.java Tue Nov 19 15:29:04 2013 +0900 @@ -11,7 +11,8 @@ import com.glavsoft.rfb.encoding.decoder.ZRLEESender; public class TreeTask extends ReceiverTask { - final static String versionMsg_3_855 = "RFB 003.855\n"; + //final static String versionMsg_3_855 = "RFB 003.855\n"; + final static String versionMsg_3_856 = "RFB 003.856\n"; public TreeTask(Reader reader, IRepaintController repaintController, ClipboardController clipboardController,
--- a/src/main/java/jp/ac/u_ryukyu/treevnc/MyRfbProto.java Tue Nov 05 17:20:53 2013 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/treevnc/MyRfbProto.java Tue Nov 19 15:29:04 2013 +0900 @@ -22,7 +22,8 @@ final static int CheckDelay = 11; final static int FramebufferUpdate = 0; private ProtocolContext context; - final static String versionMsg_3_855 = "RFB 003.855\n"; + //final static String versionMsg_3_855 = "RFB 003.855\n"; + final static String versionMsg_3_856 = "RFB 003.856\n"; private int clients; protected MulticastQueue<LinkedList<ByteBuffer>> multicastqueue = new MulticastQueue<LinkedList<ByteBuffer>>(); private RequestScreenThread rThread; @@ -191,7 +192,7 @@ private void sendRfbVersion(Writer writer) throws IOException, TransportException { // os.write(versionMsg_3_8.getBytes()); - writer.write(versionMsg_3_855.getBytes()); + writer.write(versionMsg_3_856.getBytes()); } private int readVersionMsg(Reader reader, Writer writer) throws IOException, TransportException {
--- a/src/main/java/jp/ac/u_ryukyu/treevnc/client/EchoClient.java Tue Nov 05 17:20:53 2013 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/treevnc/client/EchoClient.java Tue Nov 19 15:29:04 2013 +0900 @@ -82,14 +82,8 @@ return true; } sendDataProxy(); -// String checkRepetition = getProxyData2(is); -// if (checkRepetition.equals("stop")) { -// return true; -// } -// if (!(waitReply.checkPath())) { - reConnectionMain(echoSocket); - streamClose(); -// } + reConnectionMain(echoSocket); + streamClose(); } catch (UnknownHostException e) { System.err.println("Trying to connect to unknown host: " + e); } catch (IOException e) { @@ -192,11 +186,14 @@ try { client.close(); // set Socket for connection in VncViewer. - client.setSocket(createSocketForClient(echoSocket,false)); - client.run(); + Socket soc = createSocketForClient(echoSocket,false); + client.setSocket(soc); + if(soc != null) + client.run(); break; } catch (IOException e) { - continue; + break; + //continue; } } } @@ -258,14 +255,16 @@ String parentAddress; int count = 0; + System.out.println("########################PATH************************"); + BufferedReader is = new BufferedReader(new InputStreamReader( soc.getInputStream())); parentAddress = is.readLine(); + // It is called when the screen changes. if ("reconnection".equals(parentAddress)) { String port = is.readLine(); while (true) { try { - System.out.println("-----------------into function \n" + this.parentAddress+":"+port); client.setOpenPort(Integer.parseInt(port)); return new Socket(this.parentAddress, Integer.parseInt(port)); @@ -281,36 +280,13 @@ } } } else { + System.out.println("###########################faild"+parentAddress); + if(parentAddress==null) + return null; is.readLine();// parentNum } - - socket = new Socket(parentAddress, 5999); + socket = new Socket(parentAddress,5999); socket.setReuseAddress(true); - /* - //String tempParentAddress = is.readLine(); - //is.readLine();// parentNum - if ("reconnection".equals(tempParentAddress)) { - System.out.println("-----------------into function \n" + parentNum); - while (true) { - try { - return new Socket(parentAddress, - Integer.parseInt(parentNum)); - } catch (IOException e) { - try { - Thread.sleep(1000); - } catch (InterruptedException e1) { - e1.printStackTrace(); - } - if (count++ > 5) - break; - continue; - } - } - } - //is.readLine();// treeNum - //is.readLine();// leaderFlag - */ - return socket; }
--- a/src/main/java/jp/ac/u_ryukyu/treevnc/client/MyRfbProtoClient.java Tue Nov 05 17:20:53 2013 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/treevnc/client/MyRfbProtoClient.java Tue Nov 19 15:29:04 2013 +0900 @@ -23,7 +23,8 @@ public class MyRfbProtoClient extends MyRfbProto { final static int FramebufferUpdate = 0; final static int CheckDelay = 11; - final static String versionMsg_3_855 = "RFB 003.855\n"; + //final static String versionMsg_3_855 = "RFB 003.855\n"; + final static String versionMsg_3_856 = "RFB 003.856\n"; private static final int INFLATE_BUFSIZE = 1024 * 100; private Reader reader; private String host; @@ -102,7 +103,7 @@ } void sendRfbVersion(OutputStream os) throws IOException { - os.write(versionMsg_3_855.getBytes()); + os.write(versionMsg_3_856.getBytes()); // os.write(versionMsg_3_8.getBytes()); }
--- a/src/main/java/jp/ac/u_ryukyu/treevnc/server/AcceptClient.java Tue Nov 05 17:20:53 2013 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/treevnc/server/AcceptClient.java Tue Nov 19 15:29:04 2013 +0900 @@ -10,39 +10,33 @@ private int nodeCounter = 0, parentnum = 0; private LinkedList<String> ls = new LinkedList<String>(); private boolean addrRegistor = true; - //private int passNumber=0,numberZone; + // private int passNumber=0,numberZone; boolean runflag = false; private int passCheck = 0; - private final int treebranch = 2; - private String newparent,request,myAddress; + private final int treebranch = 2; + private String newparent, request, myAddress; private String leaderflag = "0", sendleaderflag = "0"; private final int intv_time = 100; - - public AcceptClient() { - //this.name = name; + // this.name = name; } - /* - public AcceptClient() { - new CreateThread(this); - } - */ + * public AcceptClient() { new CreateThread(this); } + */ - - public void transferParentAddrerss(BufferedReader is,PrintStream os) { + public void transferParentAddrerss(BufferedReader is, PrintStream os) { try { while (true) { String line = is.readLine(); String port = is.readLine(); myAddress = getMyAddress(); - if ("1".equals(line)||"3".equals(line)) { + if ("1".equals(line) || "3".equals(line)) { String treeNumber = is.readLine(); // reply to Parents lost node - checkWait(os,is,port,Integer.parseInt(treeNumber)); - + checkWait(os, is, port, Integer.parseInt(treeNumber)); + } else if ("2".equals(line)) { // reply to not Found Parents replyNodeInformation(port); @@ -51,13 +45,13 @@ port, leaderflag); os.close(); is.close(); - } else if (line!=null){ - //connection First time - if(checkAddress(line)){ - outputStream(os, myAddress,"0","0","0"); + } else if (line != null) { + // connection First time + if (checkAddress(line)) { + outputStream(os, myAddress, "0", "0", "0"); break; - }else { - if(replyCreateTree(os, port, line)) { + } else { + if (replyCreateTree(os, port, line)) { break; } else { break; @@ -71,15 +65,16 @@ e.printStackTrace(); } } - - private boolean checkAddress(String line){ + + private boolean checkAddress(String line) { String test[] = line.split("\\."); int a = Integer.parseInt(test[0]); int b = Integer.parseInt(test[1]); - if((192==a&&b==168)||(172==a&&(b>15||b<32))||10==a) { + if ((192 == a && b == 168) || (172 == a && (b > 15 || b < 32)) + || 10 == a) { return true; - } else{ - return false; + } else { + return false; } } @@ -92,8 +87,8 @@ ls.add(Integer.parseInt(port), ls.getLast()); ls.removeLast(); } - - private synchronized 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(); @@ -117,7 +112,7 @@ if (line != null) { ls.add(line); } - //displyLinkedList(ls); + // displyLinkedList(ls); } private String decisionLeader(int counter, int treebranch) { @@ -128,8 +123,8 @@ return "1"; } } - - String getMyAddress () { + + String getMyAddress() { InetAddress addr = null; try { addr = InetAddress.getLocalHost(); @@ -138,73 +133,77 @@ } return new String(addr.getHostAddress()); } - - private void replyNodeInformation (String port) { + + private void replyNodeInformation(String port) { parentnum = (Integer.parseInt(port) - 1) / treebranch; newparent = ls.get(parentnum); sendleaderflag = decisionLeader(Integer.parseInt(port), treebranch); - //leaderflag = decisionLeader(Integer.parseInt(port),treebranch); + // leaderflag = decisionLeader(Integer.parseInt(port),treebranch); } - - private void replyLeaderNode(PrintStream os,BufferedReader is,String port,String treeNumber) throws IOException, InterruptedException { - String host = ls.getLast(); - System.out.println("send for leadernode"+ host); - os.println(host); + + private void replyLeaderNode(PrintStream os, BufferedReader is, String port, int treeNumber) throws IOException, + InterruptedException { + String lastNode = ls.getLast(); + if(lastNode != ls.get(treeNumber)){ + os.println(lastNode); + } replyNodeInformation(port); nodeCounter--; passCheck = 1; - reportLastNode(ls.getLast(), newparent,port, String.valueOf(parentnum),sendleaderflag); + reportLastNode(lastNode, newparent, port, String.valueOf(parentnum), sendleaderflag); listupdate(port); - // waitThread(); - /* - if (Integer.parseInt(treeNumber)==ls.size()-1) - return; - */ - //displyLinkedList(ls); - os.println(port); - leaderflag = decisionLeader(Integer.parseInt(treeNumber),treebranch); - lostNodeConnection(Integer.parseInt(treeNumber),host,port,treeNumber); - os.println(treeNumber); + if(lastNode != ls.get(treeNumber)) { + os.println(port); + os.println(treeNumber); + } + leaderflag = decisionLeader(treeNumber, treebranch); + lostNodeConnection(treeNumber, lastNode, port); Thread.sleep(intv_time); is.close(); os.close(); } - - private void lostNodeConnection(int treeNum,String hostNode,String port,String treeNumber) throws UnknownHostException, IOException { - for(int i = 1; i < treebranch; i++) { - String host = ls.get(treeNum+i); - System.out.println("connection socket for-------------------- " + host ); - Socket clients = new Socket(host, 10001); - clients.setReuseAddress(true); - DataOutputStream os = new DataOutputStream(clients.getOutputStream()); - System.out.println("hostnode"+hostNode+"::port" + port); - os.writeBytes(hostNode+"\n"); - //os.writeBytes(port+"\n"); - os.writeBytes(String.valueOf(treeNum+1)+"\n"); - os.close(); + + private void lostNodeConnection(int treeNum, String hostNode, String port) + throws UnknownHostException, IOException { + for (int i = 1; i < treebranch; i++) { + String host = ls.get(treeNum + i); + if (host != hostNode) { + System.out.println("connection socket for-------------------- " + host); + Socket clients = new Socket(host, 10001); + clients.setReuseAddress(true); + DataOutputStream os = new DataOutputStream(clients.getOutputStream()); + System.out.println("hostnode" + hostNode + "::port" + port); + os.writeBytes(hostNode + "\n"); + // os.writeBytes(port+"\n"); + os.writeBytes(String.valueOf(treeNum + 1) + "\n"); + os.close(); + } } } - - private void replyNormalChildren(PrintStream os,BufferedReader is,String port,String treeNumber,boolean flag) throws IOException, InterruptedException { - if(flag) + + private void replyNormalChildren(PrintStream os, BufferedReader is, + String port, String treeNumber, boolean flag) throws IOException, + InterruptedException { + if (flag) notifyThread(); else waitThread(); - if (Integer.parseInt(treeNumber)==ls.size()) + if (Integer.parseInt(treeNumber) == ls.size()) return; os.println(ls.get(Integer.parseInt(port))); os.println(port); - if(ls.size()-1+passCheck == Integer.parseInt(treeNumber)) + if (ls.size() - 1 + passCheck == Integer.parseInt(treeNumber)) treeNumber = "skip"; passCheck = 0; os.println(treeNumber); - System.out.println("num4="+ ls.get(Integer.parseInt(port))); + System.out.println("num4=" + ls.get(Integer.parseInt(port))); runflag = false; is.close(); os.close(); } - - private synchronized boolean replyCreateTree(PrintStream os,String port,String line) throws InterruptedException { + + private synchronized boolean replyCreateTree(PrintStream os, String port, + String line) throws InterruptedException { if (addrRegistor == true) { ls.add(myAddress); addrRegistor = false; @@ -216,18 +215,18 @@ } else { return true; } - + if (nodeCounter >= treebranch + 1) { leaderflag = decisionLeader(nodeCounter, treebranch); parentnum = (nodeCounter - 1) / treebranch; request = ls.get(parentnum); System.out.println(parentnum); - outputStream(os, request,String.valueOf(parentnum), + outputStream(os, request, String.valueOf(parentnum), String.valueOf(nodeCounter), leaderflag); checkParameter(parentnum, nodeCounter, leaderflag); } else { - outputStream(os, myAddress, "0", - String.valueOf(nodeCounter), leaderflag); + outputStream(os, myAddress, "0", String.valueOf(nodeCounter), + leaderflag); } Thread.sleep(intv_time); return false; @@ -238,15 +237,17 @@ try { Socket echoSocket; System.out.println(newchild + "connect"); - // echoSocket = new Socket(newchild, 10001 + (i + 1));// + // echoSocket = new Socket(newchild, 10001 + (i + 1)); echoSocket = new Socket(newchild, 10001); - DataOutputStream os = new DataOutputStream(echoSocket.getOutputStream()); - BufferedReader is = new BufferedReader(new InputStreamReader(echoSocket.getInputStream())); + DataOutputStream os = new DataOutputStream( + echoSocket.getOutputStream()); + BufferedReader is = new BufferedReader(new InputStreamReader( + echoSocket.getInputStream())); os.writeBytes(newparent + "\n"); os.writeBytes(newpnum + "\n"); -// os.writeBytes(newtreenum + "\n"); -// os.writeBytes(newleaderflag + "\n"); - // wait for last node connection. + // os.writeBytes(newtreenum + "\n"); + // os.writeBytes(newleaderflag + "\n"); + // wait for last node connection. is.readLine(); is.close(); os.close(); @@ -274,35 +275,23 @@ } /* - // previous viersion for reconnection. - synchronized void checkWait(PrintStream os,BufferedReader is,String port,int treeNum) throws InterruptedException, IOException { - final int TIMEOUT = 3000; - if (passNumber == 0) { - passNumber++; - numberZone = ((treeNum - 1) / treebranch); - replyLeaderNode(os,is,port,String.valueOf(treeNum)); - notifyAll(); - passNumber = 0; - } else if (numberZone == ((treeNum - 1) / treebranch)) { - if (++passNumber == treebranch) { - passNumber = 0; - replyNormalChildren(os,is,port,String.valueOf(treeNum),true); - } else { - replyNormalChildren(os,is,port,String.valueOf(treeNum),false); - wait(TIMEOUT); - } - } else { - wait(); - checkWait(os,is,port,treeNum); - } + * // previous viersion for reconnection. synchronized void + * checkWait(PrintStream os,BufferedReader is,String port,int treeNum) + * throws InterruptedException, IOException { final int TIMEOUT = 3000; if + * (passNumber == 0) { passNumber++; numberZone = ((treeNum - 1) / + * treebranch); replyLeaderNode(os,is,port,String.valueOf(treeNum)); + * notifyAll(); passNumber = 0; } else if (numberZone == ((treeNum - 1) / + * treebranch)) { if (++passNumber == treebranch) { passNumber = 0; + * replyNormalChildren(os,is,port,String.valueOf(treeNum),true); } else { + * replyNormalChildren(os,is,port,String.valueOf(treeNum),false); + * wait(TIMEOUT); } } else { wait(); checkWait(os,is,port,treeNum); } } + */ + + synchronized void checkWait(PrintStream os, BufferedReader is, String port, + int treeNum) throws InterruptedException, IOException { + replyLeaderNode(os, is, port, treeNum); } - */ - - - synchronized void checkWait(PrintStream os,BufferedReader is,String port,int treeNum) throws InterruptedException, IOException { - replyLeaderNode(os,is,port,String.valueOf(treeNum)); - } - + private void waitThread() { final int TIMEOUT = 3000; try { @@ -311,19 +300,20 @@ e.printStackTrace(); } } + private void notifyThread() { notifyAll(); } - + public LinkedList<String> getList() { return ls; } - + public void setList(LinkedList<String> _ls) { ls = _ls; } - + public int getTreeBranch() { return treebranch; } - } \ No newline at end of file +} \ No newline at end of file
--- a/src/main/java/jp/ac/u_ryukyu/treevnc/server/MyRfbProtoProxy.java Tue Nov 05 17:20:53 2013 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/treevnc/server/MyRfbProtoProxy.java Tue Nov 19 15:29:04 2013 +0900 @@ -21,9 +21,10 @@ import jp.ac.u_ryukyu.treevnc.MyRfbProto; public class MyRfbProtoProxy extends MyRfbProto { - final static String versionMsg_3_855 = "RFB 003.855\n"; + //final static String versionMsg_3_855 = "RFB 003.855\n"; + final static String versionMsg_3_856 = "RFB 003.856\n"; /** - * CheckMillis is one of new msgType for RFB 3.855. + * CheckMillis is one of new msgType for RFB 3.855 and 3.856. */ final static byte SpeedCheckMillis = 4; final static int FramebufferUpdate = 0; @@ -400,7 +401,7 @@ void sendRfbVersion(Writer writer) throws IOException, TransportException { // os.write(versionMsg_3_8.getBytes()); - writer.write(versionMsg_3_855.getBytes()); + writer.write(versionMsg_3_856.getBytes()); } int readVersionMsg(Reader reader, Writer writer) throws IOException,
--- a/src/main/java/jp/ac/u_ryukyu/treevnc/server/VncProxyService.java Tue Nov 05 17:20:53 2013 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/treevnc/server/VncProxyService.java Tue Nov 19 15:29:04 2013 +0900 @@ -311,8 +311,11 @@ clientSocket.getInputStream())); String newHostName = is.readLine(); // String screenSize = is.readLine(); - changeVNCServer(newHostName); - System.out.println("----------success----------"); + if(permitChangeScreen()) { + changeVNCServer(newHostName); + } else { + continue; + } clientSocket.close(); } } catch (IOException e) { @@ -323,6 +326,11 @@ }); th.start(); } + + private boolean permitChangeScreen() { + + return true; + } protected void socketClose() { try {
--- a/src/main/java/jp/ac/u_ryukyu/treevnc/server/state/ReconnectionRequest.java Tue Nov 05 17:20:53 2013 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/treevnc/server/state/ReconnectionRequest.java Tue Nov 19 15:29:04 2013 +0900 @@ -9,7 +9,7 @@ public class ReconnectionRequest implements ScreenChanges { private VncProxyService vps; - private String host; +// private String host; public ReconnectionRequest(VncProxyService vps) { this.vps = vps; @@ -35,5 +35,4 @@ i++; } } - }
--- a/src/viewer_swing/java/com/glavsoft/viewer/Viewer.java Tue Nov 05 17:20:53 2013 +0900 +++ b/src/viewer_swing/java/com/glavsoft/viewer/Viewer.java Tue Nov 19 15:29:04 2013 +0900 @@ -280,10 +280,13 @@ @Override public void run() { + /* if (forceReconnection) { + System.out.println("error10#####################"); connectionManager.showReconnectDialog("Connection lost", reconnectionReason); forceReconnection = false; } + */ tryAgain = true; while (tryAgain) {