diff src/MyRfbProto.java @ 10:9c7eab50c708

update MyRfbProto. add acceptThread
author e085711
date Sat, 16 Apr 2011 20:40:24 +0900
parents 2237c4a06427
children 1b2bca9583cb
line wrap: on
line diff
--- a/src/MyRfbProto.java	Sat Apr 16 00:22:17 2011 +0900
+++ b/src/MyRfbProto.java	Sat Apr 16 20:40:24 2011 +0900
@@ -1,16 +1,39 @@
 import java.io.IOException;
+import java.net.ServerSocket;
 import java.net.Socket;
 import java.nio.ByteBuffer;
+import java.util.LinkedList;
 
 
 class MyRfbProto extends RfbProto {
 
+	private ServerSocket servSock; 	
 	private byte initData[];
+	private LinkedList <Socket> cliList;
+	boolean MYVNC = true;
+	
 	
 	MyRfbProto(String h, int p, VncViewer v) throws IOException {
 		super(h, p, v);
+		cliList = new LinkedList <Socket>();
+	}
+
+	void initServSock(int port) throws IOException{
+		servSock = new ServerSocket(port);
 	}
 
+	void setSoTimeout(int num) throws IOException {
+		servSock.setSoTimeout(num);
+	}
+	
+	Socket accept() throws IOException {
+		return servSock.accept();
+	}
+
+	void addSock(Socket sock){
+		cliList.add(sock);
+	}
+	
 	void mark(int len) throws IOException {
 		is.mark(len);
 	}
@@ -28,7 +51,11 @@
 		mark(255);
 		skipBytes(20);
 		int nlen = readU32();
-		initData = new byte[20+4+nlen];
+		int blen = 20+4+nlen;
+		initData = new byte[blen];
+		reset();
+
+		mark(blen);
 		readFully(initData);
 		reset();
 		
@@ -66,8 +93,16 @@
 	}
 
 	void sendInitData(Socket sock) throws IOException{
-		sock.getOutputStream().write(initData);
+			sock.getOutputStream().write(initData);
 	}
-	
+
+	void sendData(byte b[]) throws IOException{
+		for(Socket cli : cliList)
+			cli.getOutputStream().write(b, 0, b.length);		
+	}	
+
+	int cliSize(){
+		return cliList.size();
+	}	
 	
 }