# HG changeset patch # User e085711 # Date 1311827361 -32400 # Node ID bf5ac06df67545418576543d7f7ddf05e8f6b04f # Parent c92ec725895300308ff10fd20aca44da93d9eb8a modify AcceptThread diff -r c92ec7258953 -r bf5ac06df675 bin/myVncProxy/acceptThread.class Binary file bin/myVncProxy/acceptThread.class has changed diff -r c92ec7258953 -r bf5ac06df675 bin/myVncProxy/sock.class Binary file bin/myVncProxy/sock.class has changed diff -r c92ec7258953 -r bf5ac06df675 src/myVncProxy/AcceptThread.java --- a/src/myVncProxy/AcceptThread.java Thu Jul 28 13:25:03 2011 +0900 +++ b/src/myVncProxy/AcceptThread.java Thu Jul 28 13:29:21 2011 +0900 @@ -1,239 +1,31 @@ package myVncProxy; import java.net.Socket; -import java.io.*; -import java.net.*; -import java.util.*; - -public class acceptClient extends Thread { - int counter = 0 , parentnum = 0,t = 0/*落ちたときの親の番号をカウントするためのもの*/; - LinkedList ls = new LinkedList(); - boolean runflag =false; - private String name; - boolean addrRegistor=true; - - public acceptClient(String _name) { - name = _name; - } - public acceptClient() { - new CreateThread(this); - } - - public synchronized void gethost(BufferedReader is,PrintStream os) { - String line,port,handover; - int intv_time = 100; - String request; - int treebranch = 2;//treeの子ノードの数 - String leaderflag="0",sendleaderflag="0";//Socket send standardization String - - - // クライアントからのメッセージを待ち、受け取ったメッセージをそのまま返す - try { - while (true){ - line = is.readLine(); - port = is.readLine(); - - System.out.println("データーを受信しましたlin="+line+" port="+port); - //自分の IPADRESSを取得する - InetAddress addr = InetAddress.getLocalHost(); - String add = new String(addr.getHostAddress()); +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; - if("1".equals(line)){ - System.out.println("親が落ちましたmessage" + port); - os.println(ls.getLast()); - handover = String.valueOf((Integer.parseInt(port) - 1) / treebranch); - String hidenchild=ls.getLast(); - String newparent=ls.get(Integer.parseInt(handover)); - listupdate(port); - /* - ls.remove(Integer.parseInt(port)); - ls.add(Integer.parseInt(port),ls.getLast()); - ls.remove(Integer.parseInt(port)); - */ - counter--; - t++; - runflag = true; - /* - if(t % treebranch == 0){ - parentnum--; - } - */ - parentnum = (Integer.parseInt(port) -1) / treebranch; - - if((counter-1)%treebranch==1){ // children in most young treenum have leaderflag 1 other 0 - sendleaderflag = "1"; - }else{ - sendleaderflag = "0"; - } +public class AcceptThread implements Runnable { + MyRfbProto rfb; + byte[] imageBytes; - child child = new child(); - child.clost(hidenchild,newparent,port,handover,sendleaderflag,counter); - os.println(port); - Thread.sleep(intv_time); - is.close(); - os.close(); - - }else if("2".equals(line)){ - System.out.println("子供が落ちましたmessage" + port); - //exit シグナルを送る - Thread.sleep(intv_time); - }else if("3".equals(line)){ - System.out.println("落ちたのを確認しました"); - - os.println(ls.get(Integer.parseInt(port))); - os.println(port); - int g = 0; - for(String bs: ls){ - System.out.println(g+"番目"+bs); - g++; - } - System.out.println("num4=" + ls.get(Integer.parseInt(port))); - line=null; - runflag = false; - is.close(); - os.close(); - }else{ - if(addrRegistor==true){ - ls.add(add); - addrRegistor = false; - } - System.out.println(parentnum); - if(line != null){ - arg(line,ls); - counter++; - }else{ - break; - } + AcceptThread(MyRfbProto _rfb) { + rfb = _rfb; + } - if(counter>=treebranch+1){ - if((counter-1)%treebranch==0){ - leaderflag = "1"; - }else{ - leaderflag = "0"; - } - /* - if((counter-1)%treebranch==0){ - parentnum++; - } - */ - parentnum = (counter - 1) / treebranch; - // request = [p-1]; - request = ls.get(parentnum); - /* - os.println(request); - os.println(String.valueOf(parentnum)); - os.println(String.valueOf(counter)); - os.println(leaderflag); - */ - outputStream(os,request,String.valueOf(parentnum),String.valueOf(counter),leaderflag); - checkParameter(parentnum,counter,leaderflag); - }else{ - //treeの親ノードに接続する人に接続する人を教える - outputStream(os,name,"0",String.valueOf(counter),leaderflag); - /* - os.println(name);//あとで渡されたmainArgs[1](現在はname)を渡す予定,addに変更 - os.println("0"); - os.println(String.valueOf(counter)); - os.println(leaderflag); - */ - } - Thread.sleep(intv_time); - } - } - - } catch (IOException e){ - System.out.println(e); - } - - catch(InterruptedException e){ - e.printStackTrace(); - } - /* - try{ - echoServer.close(); - } - catch (IOException e){ - System.out.println(e); - } - */ - //} comment out while - } - - /** - * @param port - * parent value - */ - void listupdate(String port) { - ls.remove(Integer.parseInt(port)); - ls.add(Integer.parseInt(port),ls.getLast()); - ls.removeLast(); - } + public void run() { + rfb.selectPort(); + while (true) { + try { + Socket newCli = rfb.accept(); - void outputStream(PrintStream os,String request,String parentnum,String counter,String leaderflag) { - os.println(request); - os.println(parentnum); - os.println(counter); - os.println(leaderflag); - } - - void checkParameter(int parent,int counter,String leaderflag) { - System.out.println("pの値="+parentnum); - System.out.println("iの値="+counter); - System.out.println("leaderflag="+leaderflag + "\n"); - } - - void arg(String line,LinkedList ls) { - if(line != null){ - ls.add(line); - } - int g=0; - - for(String bs: ls){ - System.out.println(g+"番目"+bs); - g++; - } - } - -} - -/* -class sock { - void arg(String line,LinkedList ls) { - if(line != null){ - ls.add(line); - } - int g=0; - - for(String bs: ls){ - System.out.println(g+"番目"+bs); - g++; - } - } -} -*/ -class child{ - Socket echoSocket; - DataOutputStream os = null; - BufferedReader is = null; - void clost(String hiddenchild,String newparent,String newtreenum,String newpnum,String newleaderflag,int i) throws IOException{ - try { - - System.out.println(hiddenchild + "に接続します"); - echoSocket = new Socket(hiddenchild, 10001 + (i + 1));//i+1は実験中に同じマシーンを使っていたのでportを変えて対応、本番時には取り除く予定。 - - os = new DataOutputStream(echoSocket.getOutputStream()); - is = new BufferedReader(new InputStreamReader(echoSocket.getInputStream())); - - os.writeBytes(newparent+"\n"); - os.writeBytes(newpnum+"\n"); - os.writeBytes(newtreenum+"\n"); - os.writeBytes(newleaderflag+"\n"); - - } catch (UnknownHostException e) { - System.err.println("Don't know about host: localhost"); - } catch (IOException e) { - System.err.println("Couldn't get I/O for the connection to: localhost"); - } - - } -} + OutputStream os = newCli.getOutputStream(); + InputStream is = newCli.getInputStream(); + rfb.newClient(this, newCli, os, is); + } catch (IOException e) { + e.printStackTrace(); + System.out.println(e); + } + } + } +} \ No newline at end of file diff -r c92ec7258953 -r bf5ac06df675 src/myVncProxy/MyRfbProto.java --- a/src/myVncProxy/MyRfbProto.java Thu Jul 28 13:25:03 2011 +0900 +++ b/src/myVncProxy/MyRfbProto.java Thu Jul 28 13:29:21 2011 +0900 @@ -516,7 +516,7 @@ } - void newClient(acceptThread acceptThread, final Socket newCli, + void newClient(AcceptThread acceptThread, final Socket newCli, final OutputStream os, final InputStream is) throws IOException { // createBimgFlag = true; // rfb.addSockTmp(newCli); diff -r c92ec7258953 -r bf5ac06df675 src/myVncProxy/RfbProto.java --- a/src/myVncProxy/RfbProto.java Thu Jul 28 13:25:03 2011 +0900 +++ b/src/myVncProxy/RfbProto.java Thu Jul 28 13:29:21 2011 +0900 @@ -78,7 +78,7 @@ // Supported encodings and pseudo-encodings final static int EncodingRaw = 0, EncodingCopyRect = 1, EncodingRRE = 2, - EncodingCoRRE = 4, EncodingHextile = 5, EncodingZlib = 6, + EncodingCoRRE = 4, EncodingHextile = 5, EncodingZlib = 6, EncodingTight = 7, EncodingZRLE = 16, EncodingCompressLevel0 = 0xFFFFFF00, EncodingQualityLevel0 = 0xFFFFFFE0, EncodingXCursor = 0xFFFFFF10, diff -r c92ec7258953 -r bf5ac06df675 src/myVncProxy/VncProxyService.java --- a/src/myVncProxy/VncProxyService.java Thu Jul 28 13:25:03 2011 +0900 +++ b/src/myVncProxy/VncProxyService.java Thu Jul 28 13:29:21 2011 +0900 @@ -106,7 +106,7 @@ }catch(Exception e){} rfbThread = new Thread(this); - accThread = new Thread(new acceptThread(rfb)); + accThread = new Thread(new AcceptThread(rfb)); } diff -r c92ec7258953 -r bf5ac06df675 src/myVncProxy/VncViewer.java --- a/src/myVncProxy/VncViewer.java Thu Jul 28 13:25:03 2011 +0900 +++ b/src/myVncProxy/VncViewer.java Thu Jul 28 13:29:21 2011 +0900 @@ -136,7 +136,7 @@ rfbThread = new Thread(this); rfbThread.start(); - accThread = new Thread(new acceptThread(rfb)); + accThread = new Thread(new AcceptThread(rfb)); accThread.start(); }