changeset 67:5e7110277cf0

modify CuiMyVncClient
author e085711
date Sat, 06 Aug 2011 23:23:00 +0900
parents 9ace9a5e6c9f
children 4e31d8494360
files src/myVncClient/AcceptThread.java src/myVncClient/CuiMyVncClient.java src/myVncClient/CuiVncCanvas.java src/myVncClient/MyRfbProto.java
diffstat 4 files changed, 71 insertions(+), 26 deletions(-) [+]
line wrap: on
line diff
--- a/src/myVncClient/AcceptThread.java	Fri Aug 05 19:48:09 2011 +0900
+++ b/src/myVncClient/AcceptThread.java	Sat Aug 06 23:23:00 2011 +0900
@@ -8,7 +8,7 @@
         MyRfbProto rfb;
         byte[] imageBytes;
         int port;
-        
+
         AcceptThread(MyRfbProto _rfb) {
                 rfb = _rfb;
         }
@@ -17,9 +17,9 @@
             rfb = _rfb;
             port = p;
         }
-
+        
         public void run() {
-                rfb.selectPort(port);
+        		rfb.selectPort(port);
                 while (true) {
                         try {
                                 Socket newCli = rfb.accept();
@@ -33,4 +33,5 @@
                         }
                 }
         }
+
 }
--- a/src/myVncClient/CuiMyVncClient.java	Fri Aug 05 19:48:09 2011 +0900
+++ b/src/myVncClient/CuiMyVncClient.java	Sat Aug 06 23:23:00 2011 +0900
@@ -4,6 +4,7 @@
 import java.awt.event.*;
 import java.io.*;
 import java.net.*;
+import java.util.Random;
 
 import myVncClient.AcceptThread;
 import myVncClient.OptionsNoFrame;
@@ -108,20 +109,16 @@
 		cursorUpdatesDef = null;
 		eightBitColorsDef = null;
 
-		try {
-			connectAndAuthenticate();
-		} 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) {
-		}
-
+		/*
+		 * try { connectAndAuthenticate(); } 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) { }
+		 */
 		rfbThread = new Thread(this);
-		accThread = new Thread(new AcceptThread(rfb, 5999));
 
 	}
 
@@ -131,21 +128,68 @@
 
 	public void start_threads() {
 		rfbThread.start();
-		accThread.start();
 	}
 
 	public void run() {
 
 		try {
-			// connectAndAuthenticate();
+			connectAndAuthenticate();
+			accThread = new Thread(new AcceptThread(rfb, 5999));
+			accThread.start();
 			doProtocolInitialisation();
-			/*
-			 * htmlFile = new CreateHtmlFile(rfb, host, username);
-			 * htmlFile.createHtml();
-			 */
+
 			vc = new CuiVncCanvas(this, 0, 0);
 			vc.updateFramebufferSize();
 
+		} catch (IOException e) {
+			System.out.println("Socket error");
+			// parent no find
+			Random rnd = new Random();
+			long ran = rnd.nextInt(5000) + 5000;
+			System.out.println(ran);
+			// 親がいない場合の処理はここに書く!!!!
+			/**
+			 * this while reconnection
+			 */
+
+			int counter = 0;
+			// window を消してnullを突っ込んでGCで削除させる。
+			/*
+			 * vncFrame.setVisible(false); vncFrame = null;
+			 */
+			while (true) {
+				/**
+				 * if my last node case reconnectoion stop
+				 */
+
+				echo = new EchoClient(echo, this);
+				try {
+					Thread.sleep(ran);
+				} catch (InterruptedException e1) {
+					e1.printStackTrace();
+				}
+
+				if (counter >= 3) {
+					echo.openport();
+					echo.notfoundParent();
+				}
+
+				echo.openport();
+				// runflag = echo.losthost();
+				if (echo.losthost()) {
+					break;
+				}
+				counter++;
+			}
+
+			// System.exit(0);
+		} catch (Exception e) {
+			System.out.println(e);
+			System.exit(0);
+		}
+
+		try {
+
 			processNormalProtocol();// main loop
 
 		} catch (NoRouteToHostException e) {
@@ -180,7 +224,8 @@
 						buttonPanel.disableButtonsOnDisconnect();
 					}
 				} else {
-					fatalError("Network error: remote side closed connection",e);
+					fatalError("Network error: remote side closed connection",
+							e);
 				}
 			}
 		} catch (IOException e) {
--- a/src/myVncClient/CuiVncCanvas.java	Fri Aug 05 19:48:09 2011 +0900
+++ b/src/myVncClient/CuiVncCanvas.java	Sat Aug 06 23:23:00 2011 +0900
@@ -470,8 +470,7 @@
 					rfb.stopTiming();
 					
 					long kbitsPerSecond = rfb.kbitsPerSecond();
-					System.out.println("kbitsPerSecond = " + kbitsPerSecond);
-					
+//					System.out.println("kbitsPerSecond = " + kbitsPerSecond);
 
 					statNumPixelRects++;
 					statNumBytesDecoded += rw * rh * bytesPixel;
--- a/src/myVncClient/MyRfbProto.java	Fri Aug 05 19:48:09 2011 +0900
+++ b/src/myVncClient/MyRfbProto.java	Sat Aug 06 23:23:00 2011 +0900
@@ -305,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