Mercurial > hg > Applications > TightVNC_orginal
changeset 32:758d025ee24b
add TextBox.java
line wrap: on
line diff
--- a/src/main/java/com/glavsoft/rfb/encoding/decoder/ZRLEESender.java Sat Sep 01 21:23:30 2012 +0900 +++ b/src/main/java/com/glavsoft/rfb/encoding/decoder/ZRLEESender.java Mon Sep 03 17:34:52 2012 +0900 @@ -1,7 +1,7 @@ package com.glavsoft.rfb.encoding.decoder; +import jp.ac.u_ryukyu.treevnc.MyRfbProto; import jp.ac.u_ryukyu.treevnc.server.MyRfbProtoProxy; -import jp.ac.u_ryukyu.treevnc.test.MyRfbProto; import jp.ac.u_ryukyu.treevnc.client.MyRfbProtoClient; import com.glavsoft.drawing.Renderer;
--- a/src/main/java/com/glavsoft/rfb/protocol/Protocol.java Sat Sep 01 21:23:30 2012 +0900 +++ b/src/main/java/com/glavsoft/rfb/protocol/Protocol.java Mon Sep 03 17:34:52 2012 +0900 @@ -42,6 +42,7 @@ import java.util.logging.Logger; +import jp.ac.u_ryukyu.treevnc.MyRfbProto; import jp.ac.u_ryukyu.treevnc.server.MyRfbProtoProxy; import jp.ac.u_ryukyu.treevnc.server.VncProxyService; @@ -322,5 +323,35 @@ receiverThread = new Thread(receiverTask); receiverThread.start(); } + + public void startTreeClientHandling(IRfbSessionListener rfbSessionListener, + IRepaintController repaintController, ClipboardController clipboardController, MyRfbProto rfb) { + this.rfbSessionListener = rfbSessionListener; + this.repaintController = repaintController; +// if (settings.getBitsPerPixel() == 0) { +// settings.setBitsPerPixel(pixelFormat.bitsPerPixel); // the same the server sent when not initialized yet +// } + serverPixelFormat = pixelFormat; + serverPixelFormat.trueColourFlag = 1; // correct flag - we don't support color maps + setPixelFormat(createPixelFormat(settings)); + sendMessage(new SetPixelFormatMessage(pixelFormat)); + logger.fine("sent: "+pixelFormat); + + sendSupportedEncodingsMessage(settings); + settings.addListener(this); // to support pixel format (color depth), and encodings changes + settings.addListener(repaintController); + + sendRefreshMessage(); + senderTask = new SenderTask(messageQueue, writer, this); + senderThread = new Thread(senderTask); + senderThread.start(); + decoders.resetDecoders(); + receiverTask = new TreeTask( + reader, repaintController, + clipboardController, + decoders, this, rfb); + receiverThread = new Thread(receiverTask); + receiverThread.start(); + } }
--- a/src/main/java/com/glavsoft/rfb/protocol/TreeTask.java Sat Sep 01 21:23:30 2012 +0900 +++ b/src/main/java/com/glavsoft/rfb/protocol/TreeTask.java Mon Sep 03 17:34:52 2012 +0900 @@ -1,8 +1,8 @@ package com.glavsoft.rfb.protocol; +import jp.ac.u_ryukyu.treevnc.MyRfbProto; import jp.ac.u_ryukyu.treevnc.client.MyRfbProtoClient; import jp.ac.u_ryukyu.treevnc.server.MyRfbProtoProxy; -import jp.ac.u_ryukyu.treevnc.test.MyRfbProto; import com.glavsoft.rfb.ClipboardController; import com.glavsoft.rfb.IRepaintController; @@ -25,12 +25,6 @@ decoders.setDecoderByType(EncodingType.ZRLE, decoder); } - public TreeTask(Reader reader, IRepaintController repaintController, - ClipboardController clipboardController, - DecodersContainer decoders, ProtocolContext context, MyRfbProtoClient rfb) { - super(reader, repaintController, clipboardController, decoders, context); - Decoder decoder = new ZRLEESender(rfb); - } /* public void framebufferUpdateMessage() throws CommonException { * * (non-Javadoc)
--- a/src/main/java/jp/ac/u_ryukyu/treevnc/AcceptThread.java Sat Sep 01 21:23:30 2012 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/treevnc/AcceptThread.java Mon Sep 03 17:34:52 2012 +0900 @@ -5,7 +5,6 @@ import java.io.OutputStream; import jp.ac.u_ryukyu.treevnc.server.MyRfbProtoProxy; -import jp.ac.u_ryukyu.treevnc.test.MyRfbProto; import com.glavsoft.transport.Reader; import com.glavsoft.transport.Writer;
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/jp/ac/u_ryukyu/treevnc/MyRfbProto.java Mon Sep 03 17:34:52 2012 +0900 @@ -0,0 +1,287 @@ +package jp.ac.u_ryukyu.treevnc; + +import java.io.IOException; +import java.net.Socket; +import java.nio.ByteBuffer; +import java.util.LinkedList; +import java.util.concurrent.atomic.AtomicInteger; + +import jp.ac.u_ryukyu.treevnc.server.RequestScreenThread; + +import com.glavsoft.exceptions.TransportException; +import com.glavsoft.rfb.protocol.Protocol; +import com.glavsoft.rfb.protocol.ProtocolContext; +import com.glavsoft.transport.Reader; +import com.glavsoft.transport.Writer; + +public class MyRfbProto { + final static int CheckDelay = 11; + final static int FramebufferUpdate = 0; + private ProtocolContext context; + final static String versionMsg_3_855 = "RFB 003.855\n"; + private int clients; + protected MulticastQueue<LinkedList<ByteBuffer>> multicastqueue = new MulticastQueue<LinkedList<ByteBuffer>>(); + private RequestScreenThread rThread; + private boolean proxyFlag = true; + + + public void newClient(AcceptThread acceptThread, final Socket newCli, + final Writer os, final Reader is) throws IOException { + // createBimgFlag = true; + // rfb.addSockTmp(newCli); + // addSock(newCli); + final int myId = clients; + final MulticastQueue.Client<LinkedList<ByteBuffer>> c = multicastqueue.newClient(); + final AtomicInteger writerRunning = new AtomicInteger(); + writerRunning.set(1); + /** + * Timeout thread. If a client is suspended, it has top of queue + * indefinitely, which caused memory overflow. After the timeout, we + * poll the queue and discard it. Start long wait if writer is running. + */ + final Runnable timer = new Runnable() { + public void run() { + int count = 0; + for (;;) { + long timeout = 50000 / 8; + try { + synchronized (this) { + int state, flag; + writerRunning.set(0); + wait(timeout); + flag = 0; + while ((state = writerRunning.get()) == 0) { + c.poll(); // discard, should be timeout + count++; + if (flag == 0) { + System.out.println("Discarding " + myId + + " count=" + count); + flag = 1; + } + wait(10); // if this is too short, writer cannot + // take the poll, if this is too + // long, memory will overflow... + } + if (flag == 1) + System.out.println("Resuming " + myId + + " count=" + count); + if (state != 1) { + System.out.println("Client died " + myId); + break; + } + } + } catch (InterruptedException e) { + } + } + } + }; + new Thread(timer).start(); + /** + * discard all incoming from clients + */ + final Runnable reader = new Runnable() { + public void run() { + byte b[] = new byte[4096]; + for (;;) { + try { + int c = is.readByte(b); + if (c <= 0) + throw new IOException(); + // System.out.println("client read "+c); + } catch (IOException e) { + try { + writerRunning.set(2); + os.close(); + is.close(); + } catch (IOException e1) { + } catch (TransportException e1) { + e1.printStackTrace(); + } + return; + } catch (TransportException e) { + e.printStackTrace(); + } + } + } + }; + /** + * send packets to a client + */ + Runnable sender = new Runnable() { + public void run() { + writerRunning.set(1); + try { + requestThreadNotify(); + // rThread.checkDelay(); + + /** + * initial connection of RFB protocol + */ + sendRfbVersion(os); + // readVersionMsg(is); + readVersionMsg(is, os); + sendSecurityType(os); + readSecType(is); + sendSecResult(os); + readClientInit(is); + sendInitData(os); + new Thread(reader).start(); // discard incoming packet here + // after. + // writeFramebufferUpdateRequest(0,0, framebufferWidth, + // framebufferHeight, false ); + for (;;) { + LinkedList<ByteBuffer> bufs = c.poll(); + int inputIndex = 0; + ByteBuffer header = bufs.get(inputIndex); + if (header == null) + continue; + else if (header.get(0) == CheckDelay) { + writeToClient(os, bufs, inputIndex); + continue; + } else if (header.get(0) == FramebufferUpdate) { + // System.out.println("client "+ myId); + } + /* + * if(i%20==0){ sendDataCheckDelay(); } i++; + */ + writeToClient(os, bufs, inputIndex); + writerRunning.set(1); // yes my client is awaking. + } + } catch (IOException e) { + try { + writerRunning.set(2); + os.close(); + } catch (IOException e1) { + } + /* if socket closed cliList.remove(newCli); */ + } catch (TransportException e) { + e.printStackTrace(); + } + } + + public void writeToClient(final Writer os, + LinkedList<ByteBuffer> bufs, int inputIndex) + throws TransportException { + while (inputIndex < bufs.size()) { + ByteBuffer b = bufs.get(inputIndex++); + os.write(b.array(), b.position(), b.limit()); + } + os.flush(); + } + }; + clients++; + new Thread(sender).start(); + + } + + public synchronized void requestThreadNotify() { + rThread.reStart(); + } + + private void sendRfbVersion(Writer writer) throws IOException, TransportException { + // os.write(versionMsg_3_8.getBytes()); + writer.write(versionMsg_3_855.getBytes()); + } + + private int readVersionMsg(Reader reader, Writer writer) throws IOException, TransportException { + + byte[] b = new byte[12]; + + reader.readBytes(b); + + if ((b[0] != 'R') || (b[1] != 'F') || (b[2] != 'B') || (b[3] != ' ') + || (b[4] < '0') || (b[4] > '9') || (b[5] < '0') || (b[5] > '9') + || (b[6] < '0') || (b[6] > '9') || (b[7] != '.') + || (b[8] < '0') || (b[8] > '9') || (b[9] < '0') || (b[9] > '9') + || (b[10] < '0') || (b[10] > '9') || (b[11] != '\n')) { + throw new IOException("this is not an RFB server"); + } + + int rfbMajor = (b[4] - '0') * 100 + (b[5] - '0') * 10 + (b[6] - '0'); + int rfbMinor = (b[8] - '0') * 100 + (b[9] - '0') * 10 + (b[10] - '0'); + + if (rfbMajor < 3) { + throw new IOException( + "RFB server does not support protocol version 3"); + } + + if (rfbMinor == 855) { + sendProxyFlag(writer); + if (proxyFlag) + sendPortNumber(writer); + } + return rfbMinor; + } + + private void sendProxyFlag(Writer writer) throws TransportException { + if (proxyFlag) + writer.writeInt(1); + else + writer.writeInt(0); + } + + private void sendPortNumber(Writer writer) throws TransportException { + byte[] b = new byte[4]; + //b = castIntByte(getHost.getPort()); + b = castIntByte(9999); + writer.write(b); + } + + private byte[] castIntByte(int len) { + byte[] b = new byte[4]; + b[0] = (byte) ((len >>> 24) & 0xFF); + b[1] = (byte) ((len >>> 16) & 0xFF); + b[2] = (byte) ((len >>> 8) & 0xFF); + b[3] = (byte) ((len >>> 0) & 0xFF); + return b; + } + + private void readSecType(Reader reader) throws TransportException { + byte[] b = new byte[1]; + reader.read(b); + } + + private void sendSecurityType(Writer os) throws TransportException { + // number-of-security-types + os.writeInt(1); + // security-types + // 1:None + os.writeInt(1); + + /* + * os.write(4); os.write(30); os.write(31); os.write(32); os.write(35); + * os.flush(); + */ + } + + private void sendSecResult(Writer os) throws TransportException { + byte[] b = castIntByte(0); + os.write(b); + } + + private void readClientInit(Reader in) throws TransportException { + byte[] b = new byte[0]; + in.readBytes(b); + } + + private void sendInitData(Writer os) throws TransportException { + os.write(context.getInitData()); + } + + public void setProtocolContext(Protocol workingProtocol) { + context = workingProtocol; + } + + + public void readSendData(int dataLen, Reader reader) throws TransportException { + + } + + public Socket accept() throws IOException { + return null; + } + + public void selectPort(int port) { + + } +}
--- a/src/main/java/jp/ac/u_ryukyu/treevnc/client/EchoClient.java Sat Sep 01 21:23:30 2012 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/treevnc/client/EchoClient.java Mon Sep 03 17:34:52 2012 +0900 @@ -5,7 +5,6 @@ import jp.ac.u_ryukyu.treevnc.*; -//import myVncProxy.MulticastQueue.Client; public class EchoClient { private String name; @@ -15,20 +14,14 @@ private boolean runflag = false; private WaitReply waitReply; private Socket clientSocket = null; - // MyVncClient client; private InterfaceForViewer client; private int echoPort = 9999; - // private IpV6 ipV6; - // private MyVncClient checkMove; - // private VncViewer vncV; - String responseLine; - String parent;// 親の番号 - String treenum;// 自分の番号 - String leaderflag;// リーダフラグ + public String responseLine; + public String parent; + public String treenum; + public String leaderflag; - // boolean passflag; - // WaitReplyに自分自身を渡している public EchoClient() { } @@ -42,7 +35,6 @@ // checkMove = (MyVncClient)echo.client; } - // VncViewerから引数をもらってきてproxy役を認識する public EchoClient(String name, MyVncClient client) { this.client = (InterfaceForViewer) client; this.name = name; @@ -67,29 +59,8 @@ treenum = echo.treenum; waitReply = echo.waitReply; } -/* - public EchoClient(String name, CuiMyVncClient client) { - this.client = client; - this.name = name; - } - public EchoClient(String name, CuiMyVncClient client, int echoPort) { - this.client = client; - this.name = name; - this.echoPort = echoPort; - } - - public EchoClient(EchoClient echo, CuiMyVncClient client) { - this.client = client; - this.name = echo.name; - leaderflag = echo.leaderflag; - parent = echo.parent; - treenum = echo.treenum; - } -*/ - - // void hostn(String args){ - void openport() { + public void openport() { try { if (name != null) { echoSocket = new Socket(name, echoPort); @@ -113,8 +84,7 @@ * select connect port * @return */ - EchoClient requestHostName(String args) { - // サーバーにメッセージを送る + public EchoClient requestHostName(String args) { if (echoSocket != null && os != null && is != null) { try { @@ -152,18 +122,11 @@ if (checkRepetition.equals("stop")) { return true; } - // if(!(checkRepetition.equals("skip")) || - // "1".equals(leaderflag)) { if (!(waitReply.checkPath())) { Thread.sleep(1000); reConnectionMain(echoSocket); streamClose(); } - // Thread.sleep(1000); - /* - * if(!(checkMove.vncFrame.isShowing())&&"skip".equals( - * checkRepetition)) { openport(); notfoundParent(); } - */ } catch (UnknownHostException e) { System.err.println("Trying to connect to unknown host: " + e); } catch (IOException e) { @@ -197,15 +160,15 @@ return true; } - EchoClient Interruption(Socket _clientSocket) { + public EchoClient Interruption(Socket _clientSocket) { clientSocket = _clientSocket; - BufferedReader lostis = null;// あとで修正する + BufferedReader lostis = null; try { lostis = new BufferedReader(new InputStreamReader( clientSocket.getInputStream())); getProxyData(lostis); - clientSocket.close();// WaitReplyのacceptを終了させる + clientSocket.close(); } catch (IOException e) { System.out.println(e); } @@ -246,13 +209,6 @@ client.close(); client.setClientSocket(echoSocket); client.run(); - /* - client.init(); - client.setEchoValue(this); - client.getParentName(); - client.start_threads(); - client.start(); - */ } void streamClose() throws IOException { @@ -288,8 +244,4 @@ System.err.println("IOException: " + e); } } - /* - * String getIpV6() { ipV6 = new IpV6(); ipV6.getInterface(); return - * ipV6.getV6(); } - */ } \ No newline at end of file
--- a/src/main/java/jp/ac/u_ryukyu/treevnc/client/GetDataClient.java Sat Sep 01 21:23:30 2012 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/treevnc/client/GetDataClient.java Mon Sep 03 17:34:52 2012 +0900 @@ -9,31 +9,10 @@ public class GetDataClient implements Runnable { private ServerSocket server = null; - BufferedReader is; + private BufferedReader is; private int port = 8182; private boolean stopFlag = false; - public TextBoxClient text = new TextBoxClient(); - - private void getData() { - try { - server = new ServerSocket(port); - while(true) { - Socket socket = server.accept(); - is = new BufferedReader(new InputStreamReader( - socket.getInputStream())); - String line = is.readLine(); -// text = new TextBoxClient(); - if(line!=null){ - text.checkBox(line); - } - // TextBoxClient text = new TextBoxClient(); - text.setButton(); - text.visible(); - } - } catch (IOException e) { - e.printStackTrace(); - } - } + private TextBoxClient text = new TextBoxClient(); public String textAddress() { @@ -75,9 +54,25 @@ return recover; } */ - + @Override public void run() { - getData(); + try { + server = new ServerSocket(port); + while(true) { + Socket socket = server.accept(); + is = new BufferedReader(new InputStreamReader( + socket.getInputStream())); + String line = is.readLine(); +// text = new TextBoxClient(); + if(line!=null) + text.checkBox(line); + // TextBoxClient text = new TextBoxClient(); + text.setButton(); + text.visible(); + } + } catch (IOException e) { + e.printStackTrace(); + } } public void setStopFlag(boolean stopFlag) { @@ -87,5 +82,9 @@ public boolean isStopFlag() { return stopFlag; } + + public void ipRegister() { + text.ipRegister(); + } }
--- a/src/main/java/jp/ac/u_ryukyu/treevnc/client/GetHostClient.java Sat Sep 01 21:23:30 2012 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/treevnc/client/GetHostClient.java Mon Sep 03 17:34:52 2012 +0900 @@ -35,7 +35,7 @@ DatagramPacket sendPacket = new DatagramPacket(buf, str.length(), mAddr, PORT); try { - soc.send(sendPacket); + soc.send(sendPacket); } catch (IOException e) { e.printStackTrace(); }
--- a/src/main/java/jp/ac/u_ryukyu/treevnc/client/MyRfbProtoClient.java Sat Sep 01 21:23:30 2012 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/treevnc/client/MyRfbProtoClient.java Mon Sep 03 17:34:52 2012 +0900 @@ -15,7 +15,7 @@ import java.util.zip.Inflater; import jp.ac.u_ryukyu.treevnc.MulticastQueue; -import jp.ac.u_ryukyu.treevnc.test.MyRfbProto; +import jp.ac.u_ryukyu.treevnc.MyRfbProto; import com.glavsoft.exceptions.TransportException; import com.glavsoft.rfb.encoding.EncodingType;
--- a/src/main/java/jp/ac/u_ryukyu/treevnc/client/MyVncClient.java Sat Sep 01 21:23:30 2012 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/treevnc/client/MyVncClient.java Mon Sep 03 17:34:52 2012 +0900 @@ -6,7 +6,10 @@ import javax.swing.SwingUtilities; -import jp.ac.u_ryukyu.treevnc.test.MyRfbProto; +import jp.ac.u_ryukyu.treevnc.AcceptThread; +import jp.ac.u_ryukyu.treevnc.MyRfbProto; +import jp.ac.u_ryukyu.treevnc.server.GetBroadCastProxy; +import jp.ac.u_ryukyu.treevnc.test.TestTextBox; import com.glavsoft.rfb.IChangeSettingsListener; @@ -34,7 +37,6 @@ private final ProtocolSettings settings; private final UiSettings uiSettings; private TreeConnectionManager treeConnectionManager; - private MyRfbProto rfb; public MyVncClient() { @@ -42,7 +44,6 @@ settings = ProtocolSettings.getDefaultSettings(); uiSettings = super.uiSettings; treeConnectionManager = new TreeConnectionManager(this, isApplet); - rfb = new MyRfbProtoClient(); } public MyVncClient(Parser parser) { @@ -71,18 +72,14 @@ } MyVncClient myClient = new MyVncClient(parser); myClient.setType(); - SwingUtilities.invokeLater(myClient); + //SwingUtilities.invokeLater(myClient); + new Thread(myClient).start(); } public void setType() { - super.setType(treeConnectionManager); + super.setType(treeConnectionManager,new MyRfbProtoClient()); } - - - public void destroy() { - - } - + @Override
--- a/src/main/java/jp/ac/u_ryukyu/treevnc/client/TextBoxClient.java Sat Sep 01 21:23:30 2012 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/treevnc/client/TextBoxClient.java Mon Sep 03 17:34:52 2012 +0900 @@ -28,6 +28,7 @@ private String hostAddress; private String port; private CheckboxGroup ch = new CheckboxGroup(); + private Container contentPane = getContentPane(); public TextBoxClient() { setTitle("Informatin Connection Address"); @@ -68,7 +69,6 @@ //panel.add(button); //button.addActionListener(this); label = new JLabel(); - Container contentPane = getContentPane(); contentPane.add(panel, BorderLayout.CENTER); contentPane.add(label, BorderLayout.SOUTH); } @@ -88,10 +88,11 @@ } public void setButton() { + // check[counter] = new Checkbox("test display", false, ch); + // panel.add(check[counter]); panel.add(button); // panel.setBackground(Color.blue); button.addActionListener(this); - Container contentPane = getContentPane(); contentPane.add(panel, BorderLayout.CENTER); }
--- a/src/main/java/jp/ac/u_ryukyu/treevnc/server/MyRfbProtoProxy.java Sat Sep 01 21:23:30 2012 +0900 +++ b/src/main/java/jp/ac/u_ryukyu/treevnc/server/MyRfbProtoProxy.java Mon Sep 03 17:34:52 2012 +0900 @@ -28,7 +28,7 @@ import java.util.zip.Inflater; import jp.ac.u_ryukyu.treevnc.MulticastQueue; -import jp.ac.u_ryukyu.treevnc.test.MyRfbProto; +import jp.ac.u_ryukyu.treevnc.MyRfbProto; public class MyRfbProtoProxy extends MyRfbProto { final static String versionMsg_3_855 = "RFB 003.855\n"; @@ -54,7 +54,6 @@ private ServerSocket servSock; protected int acceptPort; // private byte initData[]; - ProtocolContext context; private LinkedList<Socket> cliListTmp; private LinkedList<Socket> cliList; boolean createBimgFlag; @@ -65,7 +64,7 @@ // private MulticastQueue<LinkedList<ByteBuffer>> multicastqueue = new // MostRecentMultiCast<LinkedList<ByteBuffer>>(10); - private MulticastQueue<LinkedList<ByteBuffer>> multicastqueue = new MulticastQueue<LinkedList<ByteBuffer>>(); +// private MulticastQueue<LinkedList<ByteBuffer>> multicastqueue = new MulticastQueue<LinkedList<ByteBuffer>>(); private Inflater inflater = new Inflater(); private Deflater deflater = new Deflater(); // private Thread requestThread; @@ -603,10 +602,6 @@ in.readBytes(b); } - void sendInitData(Writer os) throws TransportException { - os.write(context.getInitData()); - } - public void writeFramebufferUpdateRequest(int x, int y, int w, int h, boolean incremental) throws TransportException { byte[] b = new byte[10]; @@ -624,9 +619,5 @@ // os.write(b); } - - public void setProtocolContext(Protocol workingProtocol) { - context = workingProtocol; - } }
--- a/src/main/java/jp/ac/u_ryukyu/treevnc/test/MyRfbProto.java Sat Sep 01 21:23:30 2012 +0900 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,289 +0,0 @@ -package jp.ac.u_ryukyu.treevnc.test; - -import java.io.IOException; -import java.net.Socket; -import java.nio.ByteBuffer; -import java.util.LinkedList; -import java.util.concurrent.atomic.AtomicInteger; - -import jp.ac.u_ryukyu.treevnc.AcceptThread; -import jp.ac.u_ryukyu.treevnc.MulticastQueue; -import jp.ac.u_ryukyu.treevnc.server.RequestScreenThread; - -import com.glavsoft.exceptions.TransportException; -import com.glavsoft.rfb.protocol.Protocol; -import com.glavsoft.rfb.protocol.ProtocolContext; -import com.glavsoft.transport.Reader; -import com.glavsoft.transport.Writer; - -public class MyRfbProto { - final static int CheckDelay = 11; - final static int FramebufferUpdate = 0; - private ProtocolContext context; - final static String versionMsg_3_855 = "RFB 003.855\n"; - private int clients; - private MulticastQueue<LinkedList<ByteBuffer>> multicastqueue = new MulticastQueue<LinkedList<ByteBuffer>>(); - private RequestScreenThread rThread; - private boolean proxyFlag = true; - - - public void newClient(AcceptThread acceptThread, final Socket newCli, - final Writer os, final Reader is) throws IOException { - // createBimgFlag = true; - // rfb.addSockTmp(newCli); - // addSock(newCli); - final int myId = clients; - final MulticastQueue.Client<LinkedList<ByteBuffer>> c = multicastqueue.newClient(); - final AtomicInteger writerRunning = new AtomicInteger(); - writerRunning.set(1); - /** - * Timeout thread. If a client is suspended, it has top of queue - * indefinitely, which caused memory overflow. After the timeout, we - * poll the queue and discard it. Start long wait if writer is running. - */ - final Runnable timer = new Runnable() { - public void run() { - int count = 0; - for (;;) { - long timeout = 50000 / 8; - try { - synchronized (this) { - int state, flag; - writerRunning.set(0); - wait(timeout); - flag = 0; - while ((state = writerRunning.get()) == 0) { - c.poll(); // discard, should be timeout - count++; - if (flag == 0) { - System.out.println("Discarding " + myId - + " count=" + count); - flag = 1; - } - wait(10); // if this is too short, writer cannot - // take the poll, if this is too - // long, memory will overflow... - } - if (flag == 1) - System.out.println("Resuming " + myId - + " count=" + count); - if (state != 1) { - System.out.println("Client died " + myId); - break; - } - } - } catch (InterruptedException e) { - } - } - } - }; - new Thread(timer).start(); - /** - * discard all incoming from clients - */ - final Runnable reader = new Runnable() { - public void run() { - byte b[] = new byte[4096]; - for (;;) { - try { - int c = is.readByte(b); - if (c <= 0) - throw new IOException(); - // System.out.println("client read "+c); - } catch (IOException e) { - try { - writerRunning.set(2); - os.close(); - is.close(); - } catch (IOException e1) { - } catch (TransportException e1) { - e1.printStackTrace(); - } - return; - } catch (TransportException e) { - e.printStackTrace(); - } - } - } - }; - /** - * send packets to a client - */ - Runnable sender = new Runnable() { - public void run() { - writerRunning.set(1); - try { - requestThreadNotify(); - // rThread.checkDelay(); - - /** - * initial connection of RFB protocol - */ - sendRfbVersion(os); - // readVersionMsg(is); - readVersionMsg(is, os); - sendSecurityType(os); - readSecType(is); - sendSecResult(os); - readClientInit(is); - sendInitData(os); - new Thread(reader).start(); // discard incoming packet here - // after. - // writeFramebufferUpdateRequest(0,0, framebufferWidth, - // framebufferHeight, false ); - for (;;) { - LinkedList<ByteBuffer> bufs = c.poll(); - int inputIndex = 0; - ByteBuffer header = bufs.get(inputIndex); - if (header == null) - continue; - else if (header.get(0) == CheckDelay) { - writeToClient(os, bufs, inputIndex); - continue; - } else if (header.get(0) == FramebufferUpdate) { - // System.out.println("client "+ myId); - } - /* - * if(i%20==0){ sendDataCheckDelay(); } i++; - */ - writeToClient(os, bufs, inputIndex); - writerRunning.set(1); // yes my client is awaking. - } - } catch (IOException e) { - try { - writerRunning.set(2); - os.close(); - } catch (IOException e1) { - } - /* if socket closed cliList.remove(newCli); */ - } catch (TransportException e) { - e.printStackTrace(); - } - } - - public void writeToClient(final Writer os, - LinkedList<ByteBuffer> bufs, int inputIndex) - throws TransportException { - while (inputIndex < bufs.size()) { - ByteBuffer b = bufs.get(inputIndex++); - os.write(b.array(), b.position(), b.limit()); - } - os.flush(); - } - }; - clients++; - new Thread(sender).start(); - - } - - public synchronized void requestThreadNotify() { - rThread.reStart(); - } - - private void sendRfbVersion(Writer writer) throws IOException, TransportException { - // os.write(versionMsg_3_8.getBytes()); - writer.write(versionMsg_3_855.getBytes()); - } - - private int readVersionMsg(Reader reader, Writer writer) throws IOException, TransportException { - - byte[] b = new byte[12]; - - reader.readBytes(b); - - if ((b[0] != 'R') || (b[1] != 'F') || (b[2] != 'B') || (b[3] != ' ') - || (b[4] < '0') || (b[4] > '9') || (b[5] < '0') || (b[5] > '9') - || (b[6] < '0') || (b[6] > '9') || (b[7] != '.') - || (b[8] < '0') || (b[8] > '9') || (b[9] < '0') || (b[9] > '9') - || (b[10] < '0') || (b[10] > '9') || (b[11] != '\n')) { - throw new IOException("this is not an RFB server"); - } - - int rfbMajor = (b[4] - '0') * 100 + (b[5] - '0') * 10 + (b[6] - '0'); - int rfbMinor = (b[8] - '0') * 100 + (b[9] - '0') * 10 + (b[10] - '0'); - - if (rfbMajor < 3) { - throw new IOException( - "RFB server does not support protocol version 3"); - } - - if (rfbMinor == 855) { - sendProxyFlag(writer); - if (proxyFlag) - sendPortNumber(writer); - } - return rfbMinor; - } - - private void sendProxyFlag(Writer writer) throws TransportException { - if (proxyFlag) - writer.writeInt(1); - else - writer.writeInt(0); - } - - private void sendPortNumber(Writer writer) throws TransportException { - byte[] b = new byte[4]; - //b = castIntByte(getHost.getPort()); - b = castIntByte(9999); - writer.write(b); - } - - private byte[] castIntByte(int len) { - byte[] b = new byte[4]; - b[0] = (byte) ((len >>> 24) & 0xFF); - b[1] = (byte) ((len >>> 16) & 0xFF); - b[2] = (byte) ((len >>> 8) & 0xFF); - b[3] = (byte) ((len >>> 0) & 0xFF); - return b; - } - - private void readSecType(Reader reader) throws TransportException { - byte[] b = new byte[1]; - reader.read(b); - } - - private void sendSecurityType(Writer os) throws TransportException { - // number-of-security-types - os.writeInt(1); - // security-types - // 1:None - os.writeInt(1); - - /* - * os.write(4); os.write(30); os.write(31); os.write(32); os.write(35); - * os.flush(); - */ - } - - private void sendSecResult(Writer os) throws TransportException { - byte[] b = castIntByte(0); - os.write(b); - } - - private void readClientInit(Reader in) throws TransportException { - byte[] b = new byte[0]; - in.readBytes(b); - } - - private void sendInitData(Writer os) throws TransportException { - os.write(context.getInitData()); - } - - public void setProtocolContext(Protocol workingProtocol) { - context = workingProtocol; - } - - - public void readSendData(int dataLen, Reader reader) throws TransportException { - - } - - public Socket accept() throws IOException { - return null; - } - - public void selectPort(int port) { - - } -}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/jp/ac/u_ryukyu/treevnc/test/TestTextBox.java Mon Sep 03 17:34:52 2012 +0900 @@ -0,0 +1,17 @@ +package jp.ac.u_ryukyu.treevnc.test; + +import jp.ac.u_ryukyu.treevnc.client.TextBoxClient; + +public class TestTextBox { + TextBoxClient text = new TextBoxClient(); + public static void main(String[] args) { + TestTextBox t = new TestTextBox(); + t.testText(); + } + + public void testText() { + text.checkBox("line"); + text.setButton(); + text.visible(); + } +}
--- a/src/viewer_swing/java/com/glavsoft/viewer/TreeConnectionManager.java Sat Sep 01 21:23:30 2012 +0900 +++ b/src/viewer_swing/java/com/glavsoft/viewer/TreeConnectionManager.java Mon Sep 03 17:34:52 2012 +0900 @@ -7,7 +7,7 @@ import jp.ac.u_ryukyu.treevnc.client.GetDataClient; import jp.ac.u_ryukyu.treevnc.client.GetHostClient; - +import jp.ac.u_ryukyu.treevnc.client.EchoClient; import com.glavsoft.rfb.protocol.ProtocolSettings; import com.glavsoft.viewer.swing.ParametersHandler; @@ -18,6 +18,8 @@ * */ private static final long serialVersionUID = 1L; + private EchoClient echoValue; + public TreeConnectionManager(WindowListener appWindowListener, boolean isApplet) { super(appWindowListener, isApplet); @@ -29,19 +31,19 @@ GetHostClient bCast = new GetHostClient("who"); bCast.createSocket(); bCast.sendData(); - GetDataClient getBcast = new GetDataClient(); - Thread runBcast = new Thread(getBcast); - runBcast.start(); - getBcast.setStopFlag(true); - //connectionParams.hostName = getBcast.textAddress(); + GetDataClient getBcast = new GetDataClient(); + Thread runBcast = new Thread(getBcast); + runBcast.start(); + getBcast.setStopFlag(true); + connectionParams.hostName = getBcast.textAddress(); if("notFound".equals(connectionParams.hostName)) { - getBcast.text.ipRegister(); + // connectionParams.portNumber = Integer.parseInt(getBcast.textPort()); + connectionParams.portNumber = 5900; + } else { +// getBcast.ipRegister(); connectionParams.hostName = getBcast.textAddress(); connectionParams.portNumber = Integer.parseInt(getBcast.textPort()); //connectionParams.portNumber = 5900; - } else { - // connectionParams.portNumber = Integer.parseInt(getBcast.textPort()); - connectionParams.portNumber = 5900; } Viewer.logger.info("Connecting to host " + connectionParams.hostName + ":" + connectionParams.portNumber); try { @@ -59,6 +61,27 @@ return socket; } + public void getParentName(final ParametersHandler.ConnectionParams connectionParams) { + if (echoValue == null) { + Socket clientSocket = null; + if (clientSocket == null) { + // echo = new EchoClient(pHost, this); + echoValue = new EchoClient(connectionParams.hostName, connectionParams.portNumber ); + echoValue.openport(); + + echoValue = echoValue.requestHostName("1"); + } else { + echoValue = new EchoClient(); + echoValue = echoValue.Interruption(clientSocket); + } + } + connectionParams.hostName = echoValue.responseLine; + System.out.println("Parent =" + echoValue.parent); + System.out.println("mynumber =" + echoValue.treenum); + System.out.println("connect host =" + echoValue.leaderflag); + System.out.println("leaderflag(boolean) = " + echoValue.leaderflag); + + } }
--- a/src/viewer_swing/java/com/glavsoft/viewer/Viewer.java Sat Sep 01 21:23:30 2012 +0900 +++ b/src/viewer_swing/java/com/glavsoft/viewer/Viewer.java Mon Sep 03 17:34:52 2012 +0900 @@ -55,6 +55,11 @@ import java.util.jar.Manifest; import java.util.logging.Logger; +import jp.ac.u_ryukyu.treevnc.AcceptThread; +import jp.ac.u_ryukyu.treevnc.MyRfbProto; +import jp.ac.u_ryukyu.treevnc.client.MyRfbProtoClient; +import jp.ac.u_ryukyu.treevnc.server.GetBroadCastProxy; + @SuppressWarnings("serial") public class Viewer extends JApplet implements Runnable, IRfbSessionListener, WindowListener, IChangeSettingsListener { @@ -67,6 +72,7 @@ protected String reconnectionReason; private ContainerManager containerManager; protected ConnectionManager connectionManager; + private MyRfbProto rfb; public Protocol getWorkingProtocol() { return workingProtocol; @@ -88,8 +94,9 @@ isZoomToFitSelected = zoomToFitSelected; } - public void setType(ConnectionManager _connectionManager) { + public void setType(ConnectionManager _connectionManager,MyRfbProto _rfb) { connectionManager = _connectionManager; + rfb = _rfb; } /** @@ -276,11 +283,11 @@ @Override public void run() { - if (forceReconnection) { connectionManager.showReconnectDialog("Connection lost", reconnectionReason); forceReconnection = false; } + tryAgain = true; while (tryAgain) { workingSocket = connectionManager.connectToHost(connectionParams, settings); @@ -311,8 +318,12 @@ containerFrame = createContainer(); connectionManager.setContainerFrame(containerFrame); updateFrameTitle(); - - workingProtocol.startNormalHandling(this, surface, clipboardController); + if(rfb != null) { + runAcceptThread(); + workingProtocol.startTreeClientHandling(this,surface, clipboardController,rfb); + } else { + workingProtocol.startNormalHandling(this, surface, clipboardController); + } tryAgain = false; } catch (UnsupportedProtocolVersionException e) { connectionManager.showReconnectDialog("Unsupported Protocol Version", e.getMessage()); @@ -604,4 +615,11 @@ } } + + private void runAcceptThread() { + Thread accThread = new Thread(new AcceptThread(rfb, 5999)); + accThread.start(); + } + + }