changeset 8:67caa17deb6f

create accept setSoTimeout initServSock
author e085711
date Sat, 16 Apr 2011 01:08:39 +0900
parents d759a2ab6a7a
children c0ad3ecdf827
files src/RfbProto.java src/VncCanvas.java src/VncViewer.java
diffstat 3 files changed, 13 insertions(+), 22 deletions(-) [+]
line wrap: on
line diff
--- a/src/RfbProto.java	Sat Apr 16 00:15:44 2011 +0900
+++ b/src/RfbProto.java	Sat Apr 16 01:08:39 2011 +0900
@@ -129,10 +129,6 @@
 		return numBytesRead;
 	}
 
-	boolean MYVNC = true;
-	Socket cliSock;
-	ByteBuffer buffer;
-	int rnBytes;
 
 	// Java on UNIX does not call keyPressed() on some keys, for example
 	// swedish keys To prevent our workaround to produce duplicate
@@ -190,11 +186,6 @@
 
 		if (viewer.socketFactory == null) {
 			sock = new Socket(host, port);
-			if (MYVNC) {
-				ServerSocket serverSock = new ServerSocket(5550);
-				cliSock = serverSock.accept();
-			}
-
 		} else {
 			try {
 				Class factoryClass = Class.forName(viewer.socketFactory);
@@ -569,6 +560,7 @@
 	int redMax, greenMax, blueMax, redShift, greenShift, blueShift;
 
 	void readServerInit() throws IOException {
+
 		framebufferWidth = readU16();
 		framebufferHeight = readU16();
 		bitsPerPixel = readU8();
--- a/src/VncCanvas.java	Sat Apr 16 00:15:44 2011 +0900
+++ b/src/VncCanvas.java	Sat Apr 16 01:08:39 2011 +0900
@@ -37,7 +37,7 @@
 		MouseMotionListener {
 
 	VncViewer viewer;
-	RfbProto rfb;
+	MyRfbProto rfb;
 	ColorModel cm8, cm24;
 	Color[] colors;
 	int bytesPixel;
@@ -383,9 +383,6 @@
 
 			if (rfb.MYVNC) {
 				System.out.println("\ncount=" + count);
-				int skiplen;
-				if (count > 0)
-					skiplen = rfb.rnBytes + 20;
 
 				int nBytes = 0;
 				rfb.mark(20);
@@ -406,20 +403,17 @@
 
 
 					if (nBytes > 0 & encoding == 16) {// 0より大きい(データがある)ときデータを転送
-						rfb.buffer = ByteBuffer.allocate(len+1); // 使ってない
 
 						rfb.mark(nBytes + 20);
 
-						System.out.println("rfb.rnBytes=" + rfb.rnBytes);
-
 						byte b[] = new byte[nBytes + 20];
 						// byte b[] = new byte[18+rfb.rnBytes];
 						System.out.println("b.length=" + b.length);
 
 						rfb.readFully(b);
 
-
-						rfb.cliSock.getOutputStream().write(b, 0, b.length);
+//						rfb.cliSock.getOutputStream().write(b, 0, b.length);
+						rfb.sendData(b);
 
 						try {
 							rfb.reset();
@@ -915,8 +909,6 @@
 		// FIXME: Do not wait for all the data before decompression.
 		rfb.readFully(zrleBuf, 0, nBytes);
 
-		rfb.rnBytes = nBytes;
-
 		if (rfb.rec != null) {
 			if (rfb.recordFromBeginning) {
 				rfb.rec.writeIntBE(nBytes);
--- a/src/VncViewer.java	Sat Apr 16 00:15:44 2011 +0900
+++ b/src/VncViewer.java	Sat Apr 16 01:08:39 2011 +0900
@@ -56,7 +56,8 @@
 
 	String[] mainArgs;
 
-	RfbProto rfb;
+//	RfbProto rfb;
+	MyRfbProto rfb;
 	Thread rfbThread;
 
 	Frame vncFrame;
@@ -324,7 +325,8 @@
 
 		showConnectionStatus("Connecting to " + host + ", port " + port + "...");
 
-		rfb = new RfbProto(host, port, this);
+//		rfb = new RfbProto(host, port, this);
+		rfb = new MyRfbProto(host, port, this);
 		showConnectionStatus("Connected to server");
 
 		rfb.readVersionMsg();
@@ -445,6 +447,11 @@
 		rfb.writeClientInit();
 		rfb.readServerInit();
 
+		if (rfb.MYVNC) {
+			rfb.initServSock(5550);
+			rfb.accept();
+		}
+
 		System.out.println("Desktop name is " + rfb.desktopName);
 		System.out.println("Desktop size is " + rfb.framebufferWidth + " x "
 				+ rfb.framebufferHeight);