changeset 53:923513c47b8f

add files
author one
date Tue, 22 May 2012 17:32:23 +0900
parents d8f8123dcefc
children 163ce1743f49
files src/test/getLocalAddress.java src/test/testDataInputStream.java src/treeVnc/DataInputStream2.java src/treeVnc/ReadBroadcastHandler.java src/treeVnc/VncCanvas.java
diffstat 5 files changed, 170 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/test/getLocalAddress.java	Tue May 22 17:32:23 2012 +0900
@@ -0,0 +1,16 @@
+package test;
+
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+
+public class getLocalAddress {
+	public static void main(String[] argv) {
+		try {
+			InetAddress addr = InetAddress.getLocalHost();
+			System.out.println(addr);
+		} catch (UnknownHostException e) {
+			e.printStackTrace();
+		}
+
+	}
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/test/testDataInputStream.java	Tue May 22 17:32:23 2012 +0900
@@ -0,0 +1,112 @@
+package test;
+
+import static org.junit.Assert.*;
+
+import java.io.BufferedInputStream;
+import java.io.DataInputStream;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.net.InetSocketAddress;
+import java.net.ServerSocket;
+import java.net.Socket;
+import java.net.SocketAddress;
+import java.nio.ByteBuffer;
+import java.nio.channels.Selector;
+import java.nio.channels.ServerSocketChannel;
+import java.nio.channels.SocketChannel;
+import java.nio.channels.spi.AbstractSelector;
+import java.nio.channels.spi.SelectorProvider;
+
+import org.junit.Test;
+
+import treeVnc.DataInputStream1;
+import treeVnc.MyRfbProtoClient;
+
+
+public class testDataInputStream {
+	
+	SocketAddress bindpoint = new InetSocketAddress("localhost",59001);
+	
+	@Test
+	public void test() {
+		
+
+		try {
+			ServerSocketChannel ssChannel = SelectorProvider.provider().openServerSocketChannel();
+			
+			ServerSocket serv = ssChannel.socket();
+			serv.setReuseAddress(true);
+			serv.bind(bindpoint);
+			sender();
+			SocketChannel sock = ssChannel.accept();
+			
+			
+			DataInputStream1 d = new DataInputStream1(sock.socket());
+			MyRfbProtoClient rfbc = new MyRfbProtoClient(d);
+
+
+			byte[] b = new byte[4096];
+			int off = 0;
+			int len = 4096;
+			d.readFully(b, off, len);
+			
+			d.reset();
+			long bufSize = rfbc.getNumBytesRead();
+			int msgType = rfbc.readServerMessageType();
+			rfbc.readFramebufferUpdate();
+			rfbc.readFramebufferUpdateRectHdr();
+		} catch (IOException e) {
+			e.printStackTrace();
+		} catch (Exception e) {
+			e.printStackTrace();
+		}
+		fail("Not yet implemented");
+	}
+	
+	public void  sender() {
+		// create
+		
+		
+		Runnable s = new Runnable() {
+
+			@Override
+			public void run() {
+
+
+				try {
+					Socket sock = new Socket();
+					sock.setReuseAddress(true);
+					while(true) {
+						try {
+							Thread.sleep(100);
+							sock.connect(bindpoint);
+						} catch (Exception e){
+							continue;
+						}
+						break;
+					}
+					byte b[] = {0, 0, 0, 1, 0, 0, 3, -62, 7, -128, 0, 118, 0, 0, 0, 15};
+					 DataInputStream dataInStream = 
+						        new DataInputStream(
+						          new BufferedInputStream(
+						            new FileInputStream("log.txt")));
+					 OutputStream out = sock.getOutputStream();
+					 out.write(b);
+					 int readByte;
+					byte[] d = new byte[4096];
+					while(-1 != (readByte = dataInStream.read(d))){
+						out.write(d, 0, readByte);
+					}
+					out.flush();
+					 
+				} catch (IOException e) {
+					e.printStackTrace();
+				}
+			}
+			
+		};
+		Thread th = new Thread(s);
+		th.start();
+	}
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/treeVnc/DataInputStream2.java	Tue May 22 17:32:23 2012 +0900
@@ -0,0 +1,30 @@
+package treeVnc;
+
+import java.io.IOException;
+import java.net.DatagramSocket;
+import java.nio.ByteBuffer;
+import java.nio.channels.DatagramChannel;
+
+public class DataInputStream2 extends DataInputStream1 {
+	private DatagramChannel datagramChannel;
+
+	public DataInputStream2(DatagramSocket broadcast) {
+		super();
+		datagramChannel = broadcast.getChannel();
+	}
+	
+	@Override
+	public void readFully(byte[] b, int off, int len) throws IOException {
+		long count  = 0;
+		ByteBuffer[] bf = {ByteBuffer.wrap(b)};
+		while(count < len) {
+			long i = datagramChannel.read(bf, off, len);
+			if(i==-1) {
+				throw new IOException();
+			} 
+			count += i;
+		}
+		buf = bf[0]; 
+	}
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/treeVnc/ReadBroadcastHandler.java	Tue May 22 17:32:23 2012 +0900
@@ -0,0 +1,11 @@
+package treeVnc;
+
+import java.nio.channels.DatagramChannel;
+
+public class ReadBroadcastHandler {
+
+	public ReadBroadcastHandler(RfbProto rfbProto, DatagramChannel ssChannel) {
+		rfbProto.is = rfbProto.ib;
+	}
+
+}
--- a/src/treeVnc/VncCanvas.java	Tue May 22 17:12:21 2012 +0900
+++ b/src/treeVnc/VncCanvas.java	Tue May 22 17:32:23 2012 +0900
@@ -393,7 +393,7 @@
 		long count = 0;
 		
 //		new Thread(){public void run() {TestComet.main(null);}}.start();
-		// insert into changeIs()
+//      insert into changeIs()
 		
 		while (true) {
 //			System.out.println("\ncount=" + count);