diff src/myVncClient/MyRfbProto.java @ 18:4881586aead9

succeed drawFirstimage()!!
author e085711
date Tue, 26 Apr 2011 09:08:14 +0900
parents f9ecb0315303
children 965360af5f0b
line wrap: on
line diff
--- a/src/myVncClient/MyRfbProto.java	Sun Apr 24 16:55:29 2011 +0900
+++ b/src/myVncClient/MyRfbProto.java	Tue Apr 26 09:08:14 2011 +0900
@@ -1,11 +1,16 @@
 package myVncClient;
+import java.awt.image.BufferedImage;
 import java.io.BufferedReader;
+import java.io.ByteArrayInputStream;
 import java.io.IOException;
 import java.io.InputStreamReader;
+import java.net.BindException;
 import java.net.ServerSocket;
 import java.net.Socket;
 import java.util.LinkedList;
 
+import javax.imageio.ImageIO;
+
 
 class MyRfbProto extends RfbProto {
 
@@ -14,8 +19,10 @@
 	private int encoding;
 
 	private ServerSocket servSock; 	
+	private int acceptPort;
 	private byte initData[];
 	private LinkedList <Socket> cliList;
+	byte[] pngBytes;
 	
 	MyRfbProto(String h, int p, VncViewer v ) throws IOException {
 		super(h, p, v);
@@ -27,9 +34,26 @@
 		cliList = new LinkedList <Socket>();
 	}
 	
-	
 	void initServSock(int port) throws IOException{
 		servSock = new ServerSocket(port);
+		acceptPort = port;
+	}
+	void selectPort(){
+		int i = 5550;
+		while(true){
+			try{
+				initServSock(i);
+				break;
+			}catch(BindException e){
+				i++;
+				continue;
+			}catch(IOException e){
+				
+			}
+		}
+	}
+	int getAcceptPort(){
+		return acceptPort;
 	}
 
 	void setSoTimeout(int num) throws IOException {
@@ -101,6 +125,20 @@
 
 		inNormalProtocol = true;
 	}
+	void readPngData()throws IOException{
+		// Dataの大きさを読み込む
+		int length = readU32();
+ 		pngBytes = new byte[length];
+//		skipBytes(1);
+//		pngBytes = new byte[is.available()];
+ 		System.out.println("is.available()="+is.available());
+		readFully(pngBytes);
+	}
+	
+	BufferedImage createBimg()throws IOException{
+		BufferedImage bimg = ImageIO.read(new ByteArrayInputStream(pngBytes));
+		return bimg;
+	}
 
 	void sendInitData(Socket sock) throws IOException{
 			sock.getOutputStream().write(initData);
@@ -152,6 +190,10 @@
 		encoding = readU32();	
 		reset();	
 	}
+	
+	
+	
+	
 	void printFramebufferUpdate(){
 	
 		System.out.println("messageType=" + messageType);