diff src/main/java/jp/ac/u_ryukyu/treevnc/AcceptThread.java @ 38:c2f0b6907448

add doc directory
author one
date Thu, 27 Sep 2012 19:32:25 +0900
parents f70008073a03
children 6a34a5220a01
line wrap: on
line diff
--- a/src/main/java/jp/ac/u_ryukyu/treevnc/AcceptThread.java	Wed Sep 19 19:08:07 2012 +0900
+++ b/src/main/java/jp/ac/u_ryukyu/treevnc/AcceptThread.java	Thu Sep 27 19:32:25 2012 +0900
@@ -8,9 +8,10 @@
 import com.glavsoft.transport.Writer;
 
 public class AcceptThread implements Runnable {
-        MyRfbProto rfb = null;
+        public MyRfbProto rfb = null;
         byte[] imageBytes;
         int port;
+        public boolean flag = false;
         
         public AcceptThread(MyRfbProto _rfb) {
                 rfb = _rfb;
@@ -32,14 +33,28 @@
 		while (true) {
 			try {
 				Socket newCli = rfb.accept();
-
+				if(flag) throw new IOException();
 				OutputStream os = newCli.getOutputStream();
 				InputStream is = newCli.getInputStream();
+				if(confirmHalt(is)) break;
 				rfb.newClient(this, newCli, new Writer(os), new Reader(is));
 			} catch (IOException e) {
-				e.printStackTrace();
-				System.out.println(e);
+				break;
 			}
 		}
 	}
+	
+	
+	/**
+	 * Instruction stop if you come from if WaitReply.
+	 * @return if return true. This Thread halt.
+	 */
+	private boolean confirmHalt(InputStream is) throws IOException {
+		byte[] b = new byte[4];
+		is.mark(4);
+		is.read(b);
+		if(String.valueOf(b).equals("halt")) return true;
+		is.reset();
+		return false;
+	}
 }