changeset 33:9d3478d11d3b

Add the processing of client
author Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
date Tue, 04 Sep 2012 06:06:17 +0900
parents 758d025ee24b
children f70008073a03
files src/main/java/com/glavsoft/rfb/encoding/decoder/ZRLEESender.java src/main/java/com/glavsoft/rfb/protocol/TreeTask.java src/main/java/jp/ac/u_ryukyu/treevnc/MyRfbProto.java src/main/java/jp/ac/u_ryukyu/treevnc/client/EchoClient.java src/main/java/jp/ac/u_ryukyu/treevnc/client/MyRfbProtoClient.java src/main/java/jp/ac/u_ryukyu/treevnc/server/MyRfbProtoProxy.java src/main/java/jp/ac/u_ryukyu/treevnc/server/RequestScreenThread.java src/viewer_swing/java/com/glavsoft/viewer/TreeConnectionManager.java src/viewer_swing/java/com/glavsoft/viewer/Viewer.java
diffstat 9 files changed, 94 insertions(+), 122 deletions(-) [+]
line wrap: on
line diff
--- a/src/main/java/com/glavsoft/rfb/encoding/decoder/ZRLEESender.java	Mon Sep 03 17:34:52 2012 +0900
+++ b/src/main/java/com/glavsoft/rfb/encoding/decoder/ZRLEESender.java	Tue Sep 04 06:06:17 2012 +0900
@@ -26,6 +26,14 @@
 		int dataLen = getZrleLength(rect,reader);
 		reader.reset();
 		rfb.readSendData(dataLen, reader);
+		if(rfb instanceof MyRfbProtoClient) {
+			reader.readByte();// message
+			reader.readByte();// padding 
+			reader.readUInt16();// numberOfRectangle
+			rect.fill(reader);// fill
+			Decoder decoder = new ZRLEDecoder();
+			decoder.decode(reader,renderer,rect);
+		}
 	}
 
 	private int getZrleLength(FramebufferUpdateRectangle rect,Reader reader)
--- a/src/main/java/com/glavsoft/rfb/protocol/TreeTask.java	Mon Sep 03 17:34:52 2012 +0900
+++ b/src/main/java/com/glavsoft/rfb/protocol/TreeTask.java	Tue Sep 04 06:06:17 2012 +0900
@@ -23,6 +23,7 @@
 		Decoder decoder = new ZRLEESender(rfb);
 		decoders.setDecoderByType(EncodingType.ZLIB, decoder);
 		decoders.setDecoderByType(EncodingType.ZRLE, decoder);
+		decoders.setDecoderByType(EncodingType.ZRLEE, decoder);
 	}
 	
 	/*  public void framebufferUpdateMessage() throws CommonException {
--- a/src/main/java/jp/ac/u_ryukyu/treevnc/MyRfbProto.java	Mon Sep 03 17:34:52 2012 +0900
+++ b/src/main/java/jp/ac/u_ryukyu/treevnc/MyRfbProto.java	Tue Sep 04 06:06:17 2012 +0900
@@ -15,6 +15,7 @@
 import com.glavsoft.transport.Writer;
 
 public class MyRfbProto {
+	final static int FramebufferUpdateRequest = 3;
 	final static int CheckDelay = 11;
 	final static int FramebufferUpdate = 0;
 	private ProtocolContext context;
@@ -23,6 +24,10 @@
 	protected MulticastQueue<LinkedList<ByteBuffer>> multicastqueue = new MulticastQueue<LinkedList<ByteBuffer>>();
 	private RequestScreenThread rThread;
 	private boolean proxyFlag = true;
+	
+	public MyRfbProto() {
+		rThread = new RequestScreenThread(this);
+	}
 
 	
 	public void newClient(AcceptThread acceptThread, final Socket newCli,
@@ -284,4 +289,27 @@
 	public void selectPort(int port) {
 		
 	}
+
+
+	public void writeFramebufferUpdateRequest(int x, int y, int w, int h,
+			boolean incremental) throws TransportException {
+		byte[] b = new byte[10];
+
+		b[0] = (byte) FramebufferUpdateRequest; // 3 is FrameBufferUpdateRequest
+		b[1] = (byte) (incremental ? 1 : 0);
+		b[2] = (byte) ((x >> 8) & 0xff);
+		b[3] = (byte) (x & 0xff);
+		b[4] = (byte) ((y >> 8) & 0xff);
+		b[5] = (byte) (y & 0xff);
+		b[6] = (byte) ((w >> 8) & 0xff);
+		b[7] = (byte) (w & 0xff);
+		b[8] = (byte) ((h >> 8) & 0xff);
+		b[9] = (byte) (h & 0xff);
+
+//		os.write(b);
+	}
+	
+	public void notProxy() {
+		proxyFlag = false;
+	}
 }
--- a/src/main/java/jp/ac/u_ryukyu/treevnc/client/EchoClient.java	Mon Sep 03 17:34:52 2012 +0900
+++ b/src/main/java/jp/ac/u_ryukyu/treevnc/client/EchoClient.java	Tue Sep 04 06:06:17 2012 +0900
@@ -16,10 +16,10 @@
 	private Socket clientSocket = null;
 	private InterfaceForViewer client;
 	private int echoPort = 9999;
-	public String responseLine;
-	public String parent;
-	public String treenum;
-	public String leaderflag;
+	public String parentAddress;
+	public String parentNum;
+	public String treeNum;
+	public String leaderFlag;
 
 
 	public EchoClient() {
@@ -27,9 +27,9 @@
 
 	public EchoClient(EchoClient echo) {
 		this.name = echo.name;
-		this.leaderflag = echo.leaderflag;
-		this.parent = echo.parent;
-		this.treenum = echo.treenum;
+		this.leaderFlag = echo.leaderFlag;
+		this.parentNum = echo.parentNum;
+		this.treeNum = echo.treeNum;
 		this.client = echo.client;
 		this.waitReply = echo.waitReply;
 		// checkMove = (MyVncClient)echo.client;
@@ -54,9 +54,9 @@
 	public EchoClient(EchoClient echo, MyVncClient client) {
 		this.client = (InterfaceForViewer) client;
 		this.name = echo.name;
-		leaderflag = echo.leaderflag;
-		parent = echo.parent;
-		treenum = echo.treenum;
+		leaderFlag = echo.leaderFlag;
+		parentNum = echo.parentNum;
+		treeNum = echo.treeNum;
 		waitReply = echo.waitReply;
 	}
 
@@ -102,7 +102,7 @@
 			} catch (IOException e) {
 				System.err.println("IOException: " + e);
 			}
-			waitReply = new WaitReply(treenum, client);
+			waitReply = new WaitReply(treeNum, client);
 			waitReply.start();
 		}
 		return this;
@@ -133,7 +133,6 @@
 				return false;
 			} catch (InterruptedException e) {
 				e.printStackTrace();
-
 			} catch (NullPointerException e) {
 				openport();
 				System.out.println("notFoundParents");
@@ -147,7 +146,7 @@
 		if (echoSocket != null && os != null && is != null) {
 			runflag = true;
 			try {
-				sendDataProxy("2", parent, null);
+				sendDataProxy("2", parentNum, null);
 				getProxyData(is);
 				reConnectionMain(echoSocket);
 				streamClose();
@@ -176,28 +175,28 @@
 	}
 
 	void getProxyData(BufferedReader is) throws IOException {
-		if ((responseLine = is.readLine()) != null) {
-			System.out.println("Server: " + responseLine);
+		if ((parentAddress = is.readLine()) != null) {
+			System.out.println("Server: " + parentAddress);
 		}
-		if ((parent = is.readLine()) != null) {
-			System.out.println("parent: " + parent);
+		if ((parentNum = is.readLine()) != null) {
+			System.out.println("parent: " + parentNum);
 		}
-		if ((treenum = is.readLine()) != null) {
-			System.out.println("treenum: " + treenum);
+		if ((treeNum = is.readLine()) != null) {
+			System.out.println("treenum: " + treeNum);
 		}
-		if ((leaderflag = is.readLine()) != null) {
-			System.out.println("leaderflag: " + leaderflag);
+		if ((leaderFlag = is.readLine()) != null) {
+			System.out.println("leaderflag: " + leaderFlag);
 		}
 	}
 
 	String getProxyData2(BufferedReader is) throws IOException {
 		String checkRepetition;
 		System.out.println("-------------------re----------------------------");
-		if ((responseLine = is.readLine()) != null) {
-			System.out.println("Server: " + responseLine);
+		if ((parentAddress = is.readLine()) != null) {
+			System.out.println("Server: " + parentAddress);
 		}
-		if ((parent = is.readLine()) != null) {
-			System.out.println("parent:test " + parent);
+		if ((parentNum = is.readLine()) != null) {
+			System.out.println("parent:test " + parentNum);
 		}
 		if ((checkRepetition = is.readLine()) != null) {
 			System.out.println("checkRepetition: " + checkRepetition);
@@ -218,11 +217,11 @@
 	}
 
 	void sendDataProxy() {
-		if ("1".equals(leaderflag)) {
-			sendDataProxy("1", parent, treenum);
+		if ("1".equals(leaderFlag)) {
+			sendDataProxy("1", parentNum, treeNum);
 			System.out.println("---------------------------------------------");
 		} else {
-			sendDataProxy("3", parent, treenum);
+			sendDataProxy("3", parentNum, treeNum);
 			System.out.println("---------------------------------------------");
 		}
 	}
@@ -244,4 +243,14 @@
 			System.err.println("IOException: " + e);
 		}
 	}
+	
+	public void getParentName() {
+		if (clientSocket == null) {
+			// echo = new EchoClient(pHost, this);
+			openport();
+			requestHostName("1");
+		} else {
+			Interruption(clientSocket);
+		}
+	}
 }
\ No newline at end of file
--- a/src/main/java/jp/ac/u_ryukyu/treevnc/client/MyRfbProtoClient.java	Mon Sep 03 17:34:52 2012 +0900
+++ b/src/main/java/jp/ac/u_ryukyu/treevnc/client/MyRfbProtoClient.java	Tue Sep 04 06:06:17 2012 +0900
@@ -9,19 +9,16 @@
 import java.net.Socket;
 import java.nio.ByteBuffer;
 import java.util.LinkedList;
-import java.util.concurrent.atomic.AtomicInteger;
 import java.util.zip.DataFormatException;
 import java.util.zip.Deflater;
 import java.util.zip.Inflater;
 
-import jp.ac.u_ryukyu.treevnc.MulticastQueue;
 import jp.ac.u_ryukyu.treevnc.MyRfbProto;
 
 import com.glavsoft.exceptions.TransportException;
 import com.glavsoft.rfb.encoding.EncodingType;
 import com.glavsoft.rfb.protocol.ProtocolContext;
 import com.glavsoft.transport.Reader;
-import com.glavsoft.viewer.ContainerManager;
 import com.glavsoft.viewer.swing.ParametersHandler.ConnectionParams;
 
 public class MyRfbProtoClient extends MyRfbProto {
@@ -38,16 +35,15 @@
 	OutputStream os;
 	private ServerSocket servSock;
 	private ProtocolContext context;
-	private MulticastQueue<LinkedList<ByteBuffer>> multicastqueue = new MulticastQueue<LinkedList<ByteBuffer>>();
 	boolean proxyFlag = false;
 	int serverMajor, serverMinor;
 	int clientMajor, clientMinor;
 
 	private Inflater inflater = new Inflater();
 	private Deflater deflater = new Deflater();
-	
+
 	public MyRfbProtoClient() {
-		
+
 	}
 
 	public MyRfbProtoClient(Reader reader, String host, String port) {
@@ -74,36 +70,6 @@
 		return b;
 	}
 
-	public void getParentName() {
-		if (echoValue == null) {
-
-			if (clientSocket == null) {
-
-				// echo = new EchoClient(pHost, this);
-				echoValue = new EchoClient(pHost, echoPort);
-				echoValue.openport();
-
-				echoValue = echoValue.requestHostName("1");
-			} else {
-				echoValue = new EchoClient();
-				echoValue = echoValue.Interruption(clientSocket);
-			}
-		}
-		// proxyからの返信で接続先を決定する
-		host = echoValue.responseLine;
-		parent = echoValue.parent;
-		if (echoValue.treenum != null) {
-			treenum = echoValue.treenum;
-		} else {
-			treenum = echoValue.treenum;
-		}
-
-		if (echoValue.leaderflag != null) {
-			leaderflag = echoValue.leaderflag;
-		} else {
-			leaderflag = echoValue.leaderflag;
-		}
-	}
 
 	int castByteInt(byte[] b) {
 		ByteBuffer bb = ByteBuffer.wrap(b);
@@ -143,7 +109,6 @@
 		System.out.println("accept port = " + port);
 	}
 
-
 	void sendRfbVersion(OutputStream os) throws IOException {
 		os.write(versionMsg_3_855.getBytes());
 		// os.write(versionMsg_3_8.getBytes());
@@ -347,6 +312,7 @@
 			throws TransportException {
 		LinkedList<ByteBuffer> bufs = new LinkedList<ByteBuffer>();
 		ByteBuffer header = ByteBuffer.allocate(16);
+		reader.mark(dataLen);
 		reader.readBytes(header.array(), 0, 16);
 		header.limit(16);
 		if (header.get(0) == FramebufferUpdate) {
@@ -382,7 +348,7 @@
 
 					bufs.addFirst(header);
 					multicastqueue.put(bufs);
-					is.reset();
+					reader.reset();
 				} catch (DataFormatException e) {
 					throw new TransportException(e);
 				} catch (IOException e) {
@@ -399,12 +365,7 @@
 			bufs.add(b);
 		}
 		multicastqueue.put(bufs);
-		try {
-			is.reset();
-		} catch (IOException e) {
-			throw new TransportException(e);
-		}
-
+		reader.reset();
 		// It may be compressed. We can inflate here to avoid repeating clients
 		// decompressing here,
 		// but it may generate too many large data. It is better to do it in
--- a/src/main/java/jp/ac/u_ryukyu/treevnc/server/MyRfbProtoProxy.java	Mon Sep 03 17:34:52 2012 +0900
+++ b/src/main/java/jp/ac/u_ryukyu/treevnc/server/MyRfbProtoProxy.java	Tue Sep 04 06:06:17 2012 +0900
@@ -601,23 +601,5 @@
 		byte[] b = new byte[0];
 		in.readBytes(b);
 	}
-
-	public void writeFramebufferUpdateRequest(int x, int y, int w, int h,
-			boolean incremental) throws TransportException {
-		byte[] b = new byte[10];
-
-		b[0] = (byte) FramebufferUpdateRequest;
-		b[1] = (byte) (incremental ? 1 : 0);
-		b[2] = (byte) ((x >> 8) & 0xff);
-		b[3] = (byte) (x & 0xff);
-		b[4] = (byte) ((y >> 8) & 0xff);
-		b[5] = (byte) (y & 0xff);
-		b[6] = (byte) ((w >> 8) & 0xff);
-		b[7] = (byte) (w & 0xff);
-		b[8] = (byte) ((h >> 8) & 0xff);
-		b[9] = (byte) (h & 0xff);
-
-//		os.write(b);
-	}
 	
 }
--- a/src/main/java/jp/ac/u_ryukyu/treevnc/server/RequestScreenThread.java	Mon Sep 03 17:34:52 2012 +0900
+++ b/src/main/java/jp/ac/u_ryukyu/treevnc/server/RequestScreenThread.java	Tue Sep 04 06:06:17 2012 +0900
@@ -1,12 +1,14 @@
 package jp.ac.u_ryukyu.treevnc.server;
 
+import jp.ac.u_ryukyu.treevnc.MyRfbProto;
+
 import com.glavsoft.rfb.protocol.Protocol;
 
 public class RequestScreenThread implements Runnable {
-	MyRfbProtoProxy rfb;
+	MyRfbProto rfb;
 	Protocol protocol;
 
-	RequestScreenThread(MyRfbProtoProxy _rfb) {
+	public RequestScreenThread(MyRfbProto _rfb) {
 		rfb = _rfb;
 	}
 
--- a/src/viewer_swing/java/com/glavsoft/viewer/TreeConnectionManager.java	Mon Sep 03 17:34:52 2012 +0900
+++ b/src/viewer_swing/java/com/glavsoft/viewer/TreeConnectionManager.java	Tue Sep 04 06:06:17 2012 +0900
@@ -18,7 +18,6 @@
 	 * 
 	 */
 	private static final long serialVersionUID = 1L;
-	private EchoClient echoValue;
 	
 	public TreeConnectionManager(WindowListener appWindowListener,
 			boolean isApplet) {
@@ -40,10 +39,14 @@
 			// 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;
+			// getBcast.ipRegister();
+			EchoClient echo = new EchoClient(getBcast.textAddress(),9999);
+			echo.getParentName();
+			connectionParams.hostName = echo.parentAddress;
+			connectionParams.portNumber = Integer.parseInt(getBcast.textPort()); // I should get port number 
+			// connectionParams.hostName = getBcast.textAddress();
+			// connectionParams.portNumber = Integer.parseInt(getBcast.textPort());
+			// connectionParams.portNumber = 5900;
 		}
 			Viewer.logger.info("Connecting to host " + connectionParams.hostName + ":" + connectionParams.portNumber);
 			try {
@@ -60,28 +63,5 @@
 			}
 		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	Mon Sep 03 17:34:52 2012 +0900
+++ b/src/viewer_swing/java/com/glavsoft/viewer/Viewer.java	Tue Sep 04 06:06:17 2012 +0900
@@ -57,8 +57,7 @@
 
 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,
@@ -320,6 +319,8 @@
 				updateFrameTitle();
 				if(rfb != null) {
 					runAcceptThread();
+					rfb.setProtocolContext(workingProtocol);
+					rfb.notProxy();
 					workingProtocol.startTreeClientHandling(this,surface, clipboardController,rfb);
 				} else {
 					workingProtocol.startNormalHandling(this, surface, clipboardController);