changeset 65:4225c2fd3e16

modify CuiMyVncClient.java
author e085711
date Fri, 05 Aug 2011 19:46:51 +0900
parents d19913a42a36
children 9ace9a5e6c9f
files build.xml src/myVncClient/CuiMyVncClient.java src/myVncClient/CuiVncCanvas.java src/myVncClient/EchoClient.java src/myVncClient/MyRfbProto.java src/myVncClient/MyVncClient.java src/myVncClient/OptionNoFrame.java src/myVncClient/RfbProto.java src/myVncClient/VncCanvas.java
diffstat 9 files changed, 133 insertions(+), 113 deletions(-) [+]
line wrap: on
line diff
--- a/build.xml	Fri Aug 05 17:26:45 2011 +0900
+++ b/build.xml	Fri Aug 05 19:46:51 2011 +0900
@@ -21,6 +21,8 @@
 		</jar>
 		<jar jarfile="VncViewer.jar" basedir="${dir}" manifest="${mfdir}MANIFEST2.MF">
 		</jar>
+        <jar jarfile="CuiMyVncClient.jar" basedir="${dir}" manifest="${mfdir}MANIFEST3.MF">
+	</jar>
 	</target>
 
 
--- a/src/myVncClient/CuiMyVncClient.java	Fri Aug 05 17:26:45 2011 +0900
+++ b/src/myVncClient/CuiMyVncClient.java	Fri Aug 05 19:46:51 2011 +0900
@@ -1,4 +1,5 @@
 package myVncClient;
+
 import java.awt.*;
 import java.awt.event.*;
 import java.io.*;
@@ -8,26 +9,24 @@
 import myVncClient.OptionsNoFrame;
 
 public class CuiMyVncClient implements InterfaceForViewer, java.lang.Runnable {
-	
+
 	public static void main(String[] argv) {
 		CuiMyVncClient v = new CuiMyVncClient();
 		v.runClient(argv, v);
-		
+
 	}
-	
+
 	private void runClient(String[] argv, CuiMyVncClient v) {
 		mainArgs = argv;
 
 		v.init(null);
 		v.start_threads();
-		
+
 	}
-	
-	
-	
+
 	String[] mainArgs;
 	String username;
-	
+
 	// RfbProto rfb;
 	MyRfbProto rfb;
 	Thread rfbThread;
@@ -41,7 +40,7 @@
 	ButtonPanel buttonPanel;
 	Label connStatusLabel;
 	CuiVncCanvas vc;
-//	OptionsFrame options;
+	// OptionsFrame options;
 	OptionsNoFrame options;
 	ClipboardFrame clipboard;
 	RecordingFrame rec;
@@ -78,25 +77,24 @@
 
 	EchoClient echo;
 
-	
-	void checkArgs(String[] argv){
-		if(argv.length > 3){
-			username = argv[3]; 
-		}else if(argv.length < 2){
+	void checkArgs(String[] argv) {
+		if (argv.length > 3) {
+			username = argv[3];
+		} else if (argv.length < 2) {
 			System.out.println("Please enter argv");
 			System.out.println("hostname(IPaddress) port password");
 			System.exit(0);
-		}else{
+		} else {
 			username = argv[0];
 		}
 	}
-	
+
 	//
 	// init()
 	//
 
 	public void init(EchoClient value) {
-		
+
 		// readParameters();
 
 		readParameters(value);
@@ -110,19 +108,20 @@
 		cursorUpdatesDef = null;
 		eightBitColorsDef = null;
 
-		try{
+		try {
 			connectAndAuthenticate();
-		}catch (NoRouteToHostException e) {
+		} catch (NoRouteToHostException e) {
 			fatalError("Network error: no route to server: " + host, e);
 		} catch (UnknownHostException e) {
 			fatalError("Network error: server name unknown: " + host, e);
 		} catch (ConnectException e) {
 			fatalError("Network error: could not connect to server: " + host
 					+ ":" + port, e);
-		}catch(Exception e){}
+		} catch (Exception e) {
+		}
 
 		rfbThread = new Thread(this);
-		accThread = new Thread(new AcceptThread(rfb, 5999)); 
+		accThread = new Thread(new AcceptThread(rfb, 5999));
 
 	}
 
@@ -130,23 +129,23 @@
 	// run() - executed by the rfbThread to deal with the RFB socket.
 	//
 
-	public void start_threads(){
+	public void start_threads() {
 		rfbThread.start();
+		accThread.start();
 	}
-	
-	
+
 	public void run() {
 
 		try {
-//			connectAndAuthenticate();
+			// connectAndAuthenticate();
 			doProtocolInitialisation();
-/*
-			htmlFile = new CreateHtmlFile(rfb, host, username);
-			htmlFile.createHtml();
-*/
+			/*
+			 * htmlFile = new CreateHtmlFile(rfb, host, username);
+			 * htmlFile.createHtml();
+			 */
 			vc = new CuiVncCanvas(this, 0, 0);
 			vc.updateFramebufferSize();
-			
+
 			processNormalProtocol();// main loop
 
 		} catch (NoRouteToHostException e) {
@@ -157,20 +156,32 @@
 			fatalError("Network error: could not connect to server: " + host
 					+ ":" + port, e);
 		} catch (EOFException e) {
-			if (showOfflineDesktop) {
-				e.printStackTrace();
-				System.out
-						.println("Network error: remote side closed connection");
-				if (vc != null) {
-					vc.enableInput(false);
-				}
-				if (rfb != null && !rfb.closed())
-					rfb.close();
-				if (showControls && buttonPanel != null) {
-					buttonPanel.disableButtonsOnDisconnect();
+
+			if (leaderflag != null) {
+				while (true) {
+					echo = new EchoClient(echo, this);
+					echo.openport();
+					// runflag = echo.losthost();
+					if (echo.losthost()) {
+						break;
+					}
 				}
 			} else {
-				fatalError("Network error: remote side closed connection", e);
+				if (showOfflineDesktop) {
+					e.printStackTrace();
+					System.out
+							.println("Network error: remote side closed connection");
+					if (vc != null) {
+						vc.enableInput(false);
+					}
+					if (rfb != null && !rfb.closed())
+						rfb.close();
+					if (showControls && buttonPanel != null) {
+						buttonPanel.disableButtonsOnDisconnect();
+					}
+				} else {
+					fatalError("Network error: remote side closed connection",e);
+				}
 			}
 		} catch (IOException e) {
 			String str = e.getMessage();
@@ -179,7 +190,7 @@
 			} else {
 				fatalError(e.toString(), e);
 			}
-		} catch (Exception e) { 
+		} catch (Exception e) {
 			String str = e.getMessage();
 			if (str != null && str.length() != 0) {
 				fatalError("Error: " + str, e);
@@ -220,6 +231,7 @@
 
 		// rfb = new RfbProto(host, port, this);
 		rfb = new MyRfbProto(host, port);
+
 		showConnectionStatus("Connected to server");
 
 		rfb.readVersionMsg();
@@ -274,18 +286,17 @@
 
 	String askPassword() throws Exception {
 		/*
-		 * showConnectionStatus(null);
-		 * AuthPanel authPanel = new AuthPanel(this);
+		 * showConnectionStatus(null); AuthPanel authPanel = new
+		 * AuthPanel(this);
 		 * 
 		 * GridBagConstraints gbc = new GridBagConstraints(); gbc.gridwidth =
 		 * GridBagConstraints.REMAINDER; gbc.anchor =
 		 * GridBagConstraints.NORTHWEST; gbc.weightx = 1.0; gbc.weighty = 1.0;
 		 * gbc.ipadx = 100; gbc.ipady = 50; gridbag.setConstraints(authPanel,
 		 * gbc); vncContainer.add(authPanel);
-
-
-		authPanel.moveFocusToDefaultField();
-		vncContainer.remove(authPanel);
+		 * 
+		 * 
+		 * authPanel.moveFocusToDefaultField(); vncContainer.remove(authPanel);
 		 */
 		showConnectionStatus("ask password...");
 		String pw = mainArgs[2];
@@ -300,14 +311,13 @@
 		rfb.writeClientInit();
 		rfb.readServerInit();
 
-
 		System.out.println("Desktop name is " + rfb.desktopName);
 		System.out.println("Desktop size is " + rfb.framebufferWidth + " x "
 				+ rfb.framebufferHeight);
 
 		setEncodings();
 
-		//showConnectionStatus(null);
+		// showConnectionStatus(null);
 	}
 
 	//
@@ -363,7 +373,6 @@
 		int[] encodings = new int[20];
 		int nEncodings = 0;
 
-
 		encodings[nEncodings++] = preferredEncoding;
 		if (options.useCopyRect) {
 			encodings[nEncodings++] = RfbProto.EncodingCopyRect;
@@ -381,29 +390,22 @@
 			encodings[nEncodings++] = RfbProto.EncodingZlib;
 		}
 		/*
-		if (preferredEncoding != RfbProto.EncodingCoRRE) {
-			encodings[nEncodings++] = RfbProto.EncodingCoRRE;
-		}
-		if (preferredEncoding != RfbProto.EncodingRRE) {
-			encodings[nEncodings++] = RfbProto.EncodingRRE;
-		}
+		 * if (preferredEncoding != RfbProto.EncodingCoRRE) {
+		 * encodings[nEncodings++] = RfbProto.EncodingCoRRE; } if
+		 * (preferredEncoding != RfbProto.EncodingRRE) { encodings[nEncodings++]
+		 * = RfbProto.EncodingRRE; }
+		 * 
+		 * if (options.compressLevel >= 0 && options.compressLevel <= 9) {
+		 * encodings[nEncodings++] = RfbProto.EncodingCompressLevel0 +
+		 * options.compressLevel; } if (options.jpegQuality >= 0 &&
+		 * options.jpegQuality <= 9) { encodings[nEncodings++] =
+		 * RfbProto.EncodingQualityLevel0 + options.jpegQuality; } if
+		 * (options.requestCursorUpdates) { encodings[nEncodings++] =
+		 * RfbProto.EncodingXCursor; encodings[nEncodings++] =
+		 * RfbProto.EncodingRichCursor; if (!options.ignoreCursorUpdates)
+		 * encodings[nEncodings++] = RfbProto.EncodingPointerPos; }
+		 */
 
-		if (options.compressLevel >= 0 && options.compressLevel <= 9) {
-			encodings[nEncodings++] = RfbProto.EncodingCompressLevel0
-					+ options.compressLevel;
-		}
-		if (options.jpegQuality >= 0 && options.jpegQuality <= 9) {
-			encodings[nEncodings++] = RfbProto.EncodingQualityLevel0
-					+ options.jpegQuality;
-		}
-		if (options.requestCursorUpdates) {
-			encodings[nEncodings++] = RfbProto.EncodingXCursor;
-			encodings[nEncodings++] = RfbProto.EncodingRichCursor;
-			if (!options.ignoreCursorUpdates)
-				encodings[nEncodings++] = RfbProto.EncodingPointerPos;
-		}
- */
-		
 		encodings[nEncodings++] = RfbProto.EncodingLastRect;
 		encodings[nEncodings++] = RfbProto.EncodingNewFBSize;
 
@@ -421,7 +423,7 @@
 
 		if (encodingsWereChanged) {
 			try {
-				//rfb.writeSetEncodings(encodings, nEncodings);
+				// rfb.writeSetEncodings(encodings, nEncodings);
 				if (vc != null) {
 					vc.softCursorFree();
 				}
@@ -553,11 +555,13 @@
 
 			if (clientSocket == null) {
 				String pHost;
-				if (mainArgs.length > 0) pHost = mainArgs[0];
-				else pHost = "cls080.ie.u-ryukyu.ac.jp";
-				echo = new EchoClient(pHost,this);
+				if (mainArgs.length > 0)
+					pHost = mainArgs[0];
+				else
+					pHost = "cls080.ie.u-ryukyu.ac.jp";
+				echo = new EchoClient(pHost, this);
 				echo.openport();
-				
+
 				value = echo.hostn("1");
 			} else {
 				echo = new EchoClient();
@@ -567,12 +571,12 @@
 		// proxyからの返信で接続先を決定する
 		host = value.responseLine;
 		parent = value.parent;
-		if(value.treenum != null) {
+		if (value.treenum != null) {
 			treenum = value.treenum;
 		} else {
 			treenum = echo.treenum;
 		}
-		if(value.leaderflag != null) {
+		if (value.leaderflag != null) {
 			leaderflag = value.leaderflag;
 		} else {
 			leaderflag = echo.leaderflag;
@@ -581,20 +585,16 @@
 		System.out.println("mynumber =" + treenum);
 		System.out.println("connect host =" + host);
 		System.out.println("leaderflag(boolean) = " + leaderflag);
-		
+
 		echo = value;
 
-/*
-		if (host == null) {
-			host = getCodeBase().getHost();
-			if (host.equals("")) {
-				fatalError("HOST parameter not specified");
-			}
-		}
-*/
+		/*
+		 * if (host == null) { host = getCodeBase().getHost(); if
+		 * (host.equals("")) { fatalError("HOST parameter not specified"); } }
+		 */
 		port = 5999;
 		// Read "ENCPASSWORD" or "PASSWORD" parameter if specified.
-		//readPasswordParameters();
+		// readPasswordParameters();
 
 		String str;
 		if (inAnApplet) {
@@ -644,9 +644,8 @@
 	private void readPasswordParameters() {
 		String encPasswordParam = readParameter("ENCPASSWORD", false);
 
-
 		if (encPasswordParam == null) {
-			 passwordParam = readParameter("PASSWORD", false);
+			passwordParam = readParameter("PASSWORD", false);
 		} else {
 			// ENCPASSWORD is hexascii-encoded. Decode.
 			byte[] pw = { 0, 0, 0, 0, 0, 0, 0, 0 };
@@ -735,7 +734,7 @@
 
 		if (rfb != null && !rfb.closed())
 			rfb.close();
-//		options.dispose();
+		// options.dispose();
 		clipboard.dispose();
 		if (rec != null)
 			rec.dispose();
@@ -821,7 +820,7 @@
 		System.out.println("Destroying applet");
 
 		vncContainer.removeAll();
-//		options.dispose();
+		// options.dispose();
 		clipboard.dispose();
 		if (rec != null)
 			rec.dispose();
@@ -876,8 +875,8 @@
 		clientSocket = sock;
 	}
 
-	public void start(){
-		
+	public void start() {
+
 	}
-	
+
 }
--- a/src/myVncClient/CuiVncCanvas.java	Fri Aug 05 17:26:45 2011 +0900
+++ b/src/myVncClient/CuiVncCanvas.java	Fri Aug 05 19:46:51 2011 +0900
@@ -350,7 +350,7 @@
 
 		// Start/stop session recording if necessary.
 		viewer.checkRecordingStatus();
-
+		
 		rfb.writeFramebufferUpdateRequest(0, 0, rfb.framebufferWidth,
 				rfb.framebufferHeight, false);
 
@@ -363,7 +363,7 @@
 		
 		long count = 0;
 		while (true) {
-			System.out.println("\ncount=" + count);
+//			System.out.println("\ncount=" + count);
 			
 			count++;
 			
@@ -468,6 +468,10 @@
 					}
 
 					rfb.stopTiming();
+					
+					long kbitsPerSecond = rfb.kbitsPerSecond();
+					System.out.println("kbitsPerSecond = " + kbitsPerSecond);
+					
 
 					statNumPixelRects++;
 					statNumBytesDecoded += rw * rh * bytesPixel;
--- a/src/myVncClient/EchoClient.java	Fri Aug 05 17:26:45 2011 +0900
+++ b/src/myVncClient/EchoClient.java	Fri Aug 05 19:46:51 2011 +0900
@@ -73,8 +73,8 @@
 			System.err.println("Don't know about host: localhost");
 		} catch (IOException e) {
 			System.out.println("接続に失敗しました");
-			System.err
-			.println("Couldn't get I/O for the connection to: localhost");
+			System.err.println("Couldn't get I/O for the connection to: localhost");
+			System.exit(0);
 		}
 	}
 
--- a/src/myVncClient/MyRfbProto.java	Fri Aug 05 17:26:45 2011 +0900
+++ b/src/myVncClient/MyRfbProto.java	Fri Aug 05 19:46:51 2011 +0900
@@ -3,10 +3,12 @@
 import java.awt.Graphics;
 import java.awt.Image;
 import java.awt.image.BufferedImage;
+import java.io.BufferedInputStream;
 import java.io.BufferedOutputStream;
 import java.io.BufferedReader;
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
+import java.io.DataInputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.InputStreamReader;
@@ -60,6 +62,7 @@
 
 	byte[] pngBytes;
 
+
 	// private MulticastQueue<LinkedList<ByteBuffer>> multicastqueue = new MostRecentMultiCast<LinkedList<ByteBuffer>>(10);
 	private MulticastQueue<LinkedList<ByteBuffer>> multicastqueue = new MulticastQueue<LinkedList<ByteBuffer>>();
 	private int clients = 0;
@@ -84,7 +87,8 @@
 		// executor = Executors.newCachedThreadPool();
 		// executor = Executors.newSingleThreadExecutor();
 	}
-
+	
+	
 	// over write
 	void writeVersionMsg() throws IOException {
 		clientMajor = 3;
@@ -301,7 +305,7 @@
 		rectW = readU16();           //  8
 		rectH = readU16();           //  10
 		encoding = readU32();      //   12
-		System.out.println("encoding = "+encoding);
+		//		System.out.println("encoding = "+encoding);
 		if (encoding == EncodingZRLE)
 			zLen = readU32();
 		else
@@ -703,6 +707,14 @@
 								   os.write(out.array(),out.position(),out.limit());
 								}
 							}
+							if (encoding==RfbProto.EncodingRaw) {
+								LinkedList<ByteBuffer> outs = bufs;
+								inputIndex = 0;
+								while( inputIndex < outs.size()){
+									ByteBuffer out = outs.get(inputIndex++);
+									os.write(out.array(), out.position(), out.limit());
+								}
+							}
 							os.flush();
 							continue;
 						}
--- a/src/myVncClient/MyVncClient.java	Fri Aug 05 17:26:45 2011 +0900
+++ b/src/myVncClient/MyVncClient.java	Fri Aug 05 19:46:51 2011 +0900
@@ -215,9 +215,8 @@
 					+ ":" + port, e);
 		} catch (EOFException e) {
 
-			// window を消してnullを突っ込んでGCで削除させる。
 			vncFrame.setVisible(false);
-			vncFrame = null;
+			vncFrame.dispose();
 			// num4
 			// リーダーの子ノードがproxyに対して親が落ちたことを報告をする
 			if (leaderflag != null) {
--- a/src/myVncClient/OptionNoFrame.java	Fri Aug 05 17:26:45 2011 +0900
+++ b/src/myVncClient/OptionNoFrame.java	Fri Aug 05 19:46:51 2011 +0900
@@ -76,8 +76,9 @@
   //
 
   OptionsNoFrame(CuiMyVncClient v) {
-    viewer = v;
-    
+
+	  viewer = v;
+/*    
     for (int i = 0; i < names.length; i++) {
     	labels[i] = new Label(names[i]);
     	
@@ -143,12 +144,14 @@
 	}
       }
     }
+*/
 
     // Make the booleans and encodings array correspond to the state of the GUI
 
-    setEncodings();
-    setColorFormat();
-    setOtherOptions();
+//    setEncodings();
+//    setColorFormat();
+//    setOtherOptions();
+	  
   }
 
 
--- a/src/myVncClient/RfbProto.java	Fri Aug 05 17:26:45 2011 +0900
+++ b/src/myVncClient/RfbProto.java	Fri Aug 05 19:46:51 2011 +0900
@@ -176,6 +176,9 @@
 //	private boolean closed;
 	protected boolean closed;
 
+	public RfbProto(){
+	}
+	
 	//
 	// Constructor. Make TCP connection to RFB server.
 	//
--- a/src/myVncClient/VncCanvas.java	Fri Aug 05 17:26:45 2011 +0900
+++ b/src/myVncClient/VncCanvas.java	Fri Aug 05 19:46:51 2011 +0900
@@ -424,8 +424,6 @@
 				for (int i = 0; i < rfb.updateNRects; i++) {
 
 					rfb.readFramebufferUpdateRectHdr();
-					System.out.println("encoding = "+rfb.updateRectEncoding);
-
 					
 					statNumTotalRects++;
 					int rx = rfb.updateRectX, ry = rfb.updateRectY;