Mercurial > hg > Members > you > TreeVNC
changeset 28:a477a210a39a
befor update
author | one |
---|---|
date | Tue, 07 Feb 2012 14:03:43 +0900 |
parents | 41b2e2ebcff2 |
children | a4ef63d95304 |
files | src/treeVnc/AcceptClient.java src/treeVnc/CuiVncCanvas.java src/treeVnc/GetBroadCastProxy.java src/treeVnc/MyRfbProtoClient.java src/treeVnc/MyRfbProtoProxy.java src/treeVnc/MyVncClient.java src/treeVnc/ProxyVncCanvas.java src/treeVnc/RequestScreenThread.java src/treeVnc/RfbProto.java src/treeVnc/TreeVnc.java src/treeVnc/VncCanvas.java |
diffstat | 11 files changed, 121 insertions(+), 43 deletions(-) [+] |
line wrap: on
line diff
--- a/src/treeVnc/AcceptClient.java Sat Jan 28 03:26:02 2012 +0900 +++ b/src/treeVnc/AcceptClient.java Tue Feb 07 14:03:43 2012 +0900 @@ -14,11 +14,11 @@ boolean runflag = false; //private String name; private int passCheck = 0; - private int treebranch = 2; // treeの子ノードの数 + private final int treebranch = 2; // treeの子ノードの数 private String newparent,request,myAddress; private String leaderflag = "0", sendleaderflag = "0"; - private int intv_time = 100; - //private volatile boolean flag = false; + private final int intv_time = 100; + public AcceptClient(String name) { @@ -41,9 +41,10 @@ String line = is.readLine(); String port = is.readLine(); myAddress = getMyAddress(); - if ("1".equals(line)) { + if ("1".equals(line)||"3".equals(line)) { // reply to Parents lost node replyLeaderNode(os, is, port); + replyNormalChildren(os, is, port); } else if ("2".equals(line)) { // reply to not Found Parents @@ -53,14 +54,10 @@ port, leaderflag); os.close(); is.close(); - } else if ("3".equals(line)) { - // At lost time send to not leader children - replyNormalChildren(os, is, port); - line = null; } else if (line!=null){ //connection First time if(checkAddress(line)){ - outputStream(os, ls.getFirst(),"0","0", "0"); + outputStream(os, myAddress,"0","0","0"); break; }else { if(replyCreateTree(os, port, line)) { @@ -161,7 +158,7 @@ } private void replyLeaderNode(PrintStream os,BufferedReader is,String port) throws IOException, InterruptedException { - String checkRepetition = is.readLine(); + String checkRepetition = is.readLine(); // checkRepetition is TreeNumber String tempLastNode = null; os.println(ls.getLast()); replyNodeInformation(port); @@ -284,26 +281,39 @@ } synchronized void checkWait(int treeNum) throws InterruptedException { - if (passNumber == 0) { - passNumber++; - numberZone = ( (treeNum-1) / treebranch); - System.out.println(treeNum+"waitしまーす"); - wait(300); - notifyAll(); - } else if (numberZone == ( (treeNum-1) / treebranch)) { + final int TIMEOUT = 3000; + if (passNumber == 0) { + passNumber++; + numberZone = ((treeNum - 1) / treebranch); + System.out.println(treeNum + "--wait--"); + wait(TIMEOUT); + notifyAll(); + passNumber = 0; + } else if (numberZone == ((treeNum - 1) / treebranch)) { if (++passNumber == treebranch) { - System.out.println(treeNum+"notifyしまーす"); - passNumber = 0; - notifyAll(); - } else { - passNumber++; - System.out.println(treeNum+"waityobiしまーす"); - wait(300); - } + System.out.println(treeNum + "--notify--"); + passNumber = 0; + notifyAll(); } else { - wait(); - checkWait(treeNum); + passNumber++; + System.out.println(treeNum + "--waityobi--"); + wait(TIMEOUT); } + } else { + wait(); + checkWait(treeNum); + } } - -} \ No newline at end of file + + private void waitThread() { + final int TIMEOUT = 3000; + try { + wait(TIMEOUT); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + private void notifyThread() { + notifyAll(); + } + } \ No newline at end of file
--- a/src/treeVnc/CuiVncCanvas.java Sat Jan 28 03:26:02 2012 +0900 +++ b/src/treeVnc/CuiVncCanvas.java Tue Feb 07 14:03:43 2012 +0900 @@ -371,6 +371,7 @@ /** * read Data from parents and send Data to Client. */ + rfb.sendDataToClient(); long numBytesRead = rfb.getNumBytesRead();
--- a/src/treeVnc/GetBroadCastProxy.java Sat Jan 28 03:26:02 2012 +0900 +++ b/src/treeVnc/GetBroadCastProxy.java Tue Feb 07 14:03:43 2012 +0900 @@ -39,13 +39,22 @@ inputStream = new ByteArrayInputStream(recvPacket.getData()); inputStream.read(resorve); if("who".equals(castString(resorve))){ - bCast.createSocket(address); + replyBroadCast(); } } } catch (IOException e) { e.printStackTrace(); } } + + private void replyBroadCast() { + Runnable sender = new Runnable() { + public void run() { + bCast.createSocket(address); + } + }; + new Thread(sender).start(); + } private String getAddress(SocketAddress addr) { String str = addr.toString(); @@ -53,7 +62,7 @@ return str; } /* - private int castInt(byte[] a) { + private int castBytoToInt(byte[] a) { int value = 0; ByteArrayInputStream bais = new ByteArrayInputStream(a); DataInputStream dis = new DataInputStream(bais);
--- a/src/treeVnc/MyRfbProtoClient.java Sat Jan 28 03:26:02 2012 +0900 +++ b/src/treeVnc/MyRfbProtoClient.java Tue Feb 07 14:03:43 2012 +0900 @@ -551,6 +551,7 @@ e.printStackTrace(); } } + // unnecessary method void readWriteJpegData() throws IOException { @@ -731,6 +732,14 @@ * which reset decoder for each packet. ZRLEE can be invisible from user, but it have to be implemented in the clients. * ZRLEE compression is not context dependent, so no recompression is necessary. */ + void sendDataCheckDelay() { + LinkedList<ByteBuffer>bufs = new LinkedList<ByteBuffer>(); + ByteBuffer b = ByteBuffer.allocate(8); + b.put((byte)CheckDelay); + bufs.add(b); + multicastqueue.put(bufs); + } + void readSendData(int dataLen) throws IOException, DataFormatException { LinkedList<ByteBuffer>bufs = new LinkedList<ByteBuffer>(); ByteBuffer header = ByteBuffer.allocate(16); @@ -793,7 +802,7 @@ public void run() { int count = 0; for(;;) { - long timeout = 30000/8; + long timeout = 40000/8; try { synchronized(this) { int state,flag; @@ -863,6 +872,7 @@ sendInitData(os); new Thread(reader).start(); // discard incoming packet here after. if(rfbMinor == 855){ + //checkDilay(os); // send jpeg data of full screen. // sendFullScreen("jpeg" ,os); } else { @@ -874,6 +884,10 @@ int inputIndex = 0; ByteBuffer header = bufs.get(inputIndex); if (header==null) continue; + if (header.get(0)==RfbProto.CheckDelay) { + writeToClient(os, bufs, inputIndex); + continue; + } if (header.get(0)==RfbProto.FramebufferUpdate) { // System.out.println("client "+ myId); }
--- a/src/treeVnc/MyRfbProtoProxy.java Sat Jan 28 03:26:02 2012 +0900 +++ b/src/treeVnc/MyRfbProtoProxy.java Tue Feb 07 14:03:43 2012 +0900 @@ -704,6 +704,15 @@ * which reset decoder for each packet. ZRLEE can be invisible from user, but it have to be implemented in the clients. * ZRLEE compression is not context dependent, so no recompression is necessary. */ + void sendDataCheckDelay() { + LinkedList<ByteBuffer>bufs = new LinkedList<ByteBuffer>(); + ByteBuffer b = ByteBuffer.allocate(1); + b.put((byte)CheckDelay); + b.position(0); + bufs.add(b); + multicastqueue.put(bufs); + } + void readSendData(int dataLen) throws IOException, DataFormatException { LinkedList<ByteBuffer>bufs = new LinkedList<ByteBuffer>(); ByteBuffer header = ByteBuffer.allocate(16); @@ -783,7 +792,7 @@ public void run() { int count = 0; for(;;) { - long timeout = 30000/8; + long timeout = 50000/8; try { synchronized(this) { int state,flag; @@ -841,6 +850,7 @@ writerRunning.set(1); try { requestThreadNotify(); + //rThread.checkDelay(); /** * initial connection of RFB protocol @@ -860,6 +870,11 @@ int inputIndex = 0; ByteBuffer header = bufs.get(inputIndex); if (header==null) continue; + if (header.get(0)==RfbProto.CheckDelay) { + writeToClient(os, bufs, inputIndex); + //System.out.println("データ来たよ"); + continue; + } if (header.get(0)==RfbProto.FramebufferUpdate) { // System.out.println("client "+ myId); }
--- a/src/treeVnc/MyVncClient.java Sat Jan 28 03:26:02 2012 +0900 +++ b/src/treeVnc/MyVncClient.java Tue Feb 07 14:03:43 2012 +0900 @@ -51,10 +51,15 @@ inSeparateFrame = true; if (mainArgs.length != 0) { if ("-c".equals(argv[0])) { - getHost = new TextBoxClient(); - getHost.ipRegister(); - pHost = getHost.getAddressOption(); - port = Integer.parseInt(getHost.getPortOption()); + if(argv.length==3){ + pHost = argv[1]; + port = Integer.parseInt(argv[2]); + } else { + getHost = new TextBoxClient(); + getHost.ipRegister(); + pHost = getHost.getAddressOption(); + port = Integer.parseInt(getHost.getPortOption()); + } } else { bCast = new BroadCastClient("who"); bCast.createSocket();
--- a/src/treeVnc/ProxyVncCanvas.java Sat Jan 28 03:26:02 2012 +0900 +++ b/src/treeVnc/ProxyVncCanvas.java Tue Feb 07 14:03:43 2012 +0900 @@ -372,11 +372,9 @@ /** * read Data from parents and send Data to Client. */ - - - + //rfb.sendDataCheckDelay(); rfb.sendDataToClient(); - +// rfb.checkDelayData(); // long kbitsPerSecond = rfb.kbitsPerSecond(); // System.out.println("Throughput " + kbitsPerSecond + " kbit/s"); @@ -386,6 +384,7 @@ int w = rfb.framebufferWidth; int h = rfb.framebufferHeight; rfb.writeFramebufferUpdateRequest(0, 0, w, h, !fullUpdateNeeded); + // rfb.checkDelayData(); continue; } @@ -540,6 +539,7 @@ int w = rfb.framebufferWidth; int h = rfb.framebufferHeight; rfb.writeFramebufferUpdateRequest(0, 0, w, h, !fullUpdateNeeded); + //rfb.checkDelayData(); break; @@ -554,7 +554,11 @@ String s = rfb.readServerCutText(); viewer.clipboard.setCutText(s); break; - + + case RfbProto.CheckDelay: + rfb.checkDelayData(); + break; + default: throw new Exception("Unknown RFB message type " + msgType); }
--- a/src/treeVnc/RequestScreenThread.java Sat Jan 28 03:26:02 2012 +0900 +++ b/src/treeVnc/RequestScreenThread.java Tue Feb 07 14:03:43 2012 +0900 @@ -1,5 +1,7 @@ package treeVnc; +import java.io.IOException; + public class RequestScreenThread implements Runnable { MyRfbProtoProxy rfb; @@ -34,5 +36,8 @@ notify(); } + public void checkDelay() throws IOException { + rfb.checkDelayData(); + } }
--- a/src/treeVnc/RfbProto.java Sat Jan 28 03:26:02 2012 +0900 +++ b/src/treeVnc/RfbProto.java Tue Feb 07 14:03:43 2012 +0900 @@ -59,6 +59,9 @@ // Standard server-to-client messages final static int FramebufferUpdate = 0, SetColourMapEntries = 1, Bell = 2, ServerCutText = 3; + + // Check Delay Top form Bottom + final static int CheckDelay = 11; // Non-standard server-to-client messages final static int EndOfContinuousUpdates = 150; @@ -848,6 +851,14 @@ // // Write a FramebufferUpdateRequest message // + + + void checkDelayData() throws IOException { + System.out.println("sousinn"); + byte[] b = new byte[1]; + b[0] = (byte) CheckDelay; + os.write(b); + } void writeFramebufferUpdateRequest(int x, int y, int w, int h, boolean incremental) throws IOException {
--- a/src/treeVnc/TreeVnc.java Sat Jan 28 03:26:02 2012 +0900 +++ b/src/treeVnc/TreeVnc.java Tue Feb 07 14:03:43 2012 +0900 @@ -19,7 +19,7 @@ System.out.println("client"); MyVncClient client = new MyVncClient(); client.treeVncClient(argv); - } else if (argv.length == 1) { + } else if (argv.length == 1||argv.length==3) { if ("-p".equals(argv[0])) { System.out.println("proxy"); // String[] temp = new String[0];
--- a/src/treeVnc/VncCanvas.java Sat Jan 28 03:26:02 2012 +0900 +++ b/src/treeVnc/VncCanvas.java Tue Feb 07 14:03:43 2012 +0900 @@ -405,6 +405,7 @@ * read Data from parents and send Data to Client. * */ + //rfbc.sendDataCheckDelay(); rfbc.sendDataToClient(); // rfb.printNumBytesRead(); @@ -414,6 +415,9 @@ // Process the message depending on its type. switch (msgType) { + case MyRfbProtoClient.CheckDelay: + System.out.println("---------------into data------------"); + break; case MyRfbProtoClient.SpeedCheckMillis: rfbc.readSpeedCheck(); break;