annotate src/myVncProxy/MyRfbProto.java @ 100:ae4df9b07805

Test passed. VNC partial draw on ZRE.
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Wed, 03 Aug 2011 22:12:41 +0900
parents 0c5762c3a8dd
children 2ce6077bdb09
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
24
87b29d6039a6 add package myVncProxy
e085711
parents: 23
diff changeset
1 package myVncProxy;
54
796f2b3b8665 modify MyRfbProto.java
e085711
parents: 51
diff changeset
2
88
9b3b1e3e7db5 add test routine
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
3 import static org.junit.Assert.*;
9b3b1e3e7db5 add test routine
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
4
25
cded9fd297ab create png data
e085711
parents: 24
diff changeset
5 import java.awt.Graphics;
cded9fd297ab create png data
e085711
parents: 24
diff changeset
6 import java.awt.Image;
cded9fd297ab create png data
e085711
parents: 24
diff changeset
7 import java.awt.image.BufferedImage;
cded9fd297ab create png data
e085711
parents: 24
diff changeset
8 import java.io.BufferedOutputStream;
15
89e1c5f84407 faile ZRLE encode. success raw encode.
e085711
parents: 13
diff changeset
9 import java.io.BufferedReader;
25
cded9fd297ab create png data
e085711
parents: 24
diff changeset
10 import java.io.ByteArrayInputStream;
cded9fd297ab create png data
e085711
parents: 24
diff changeset
11 import java.io.ByteArrayOutputStream;
10
2840c7a259f1 add acceptThread
e085711
parents:
diff changeset
12 import java.io.IOException;
43
08317224ce21 create RFB 003.998
e085711
parents: 40
diff changeset
13 import java.io.InputStream;
15
89e1c5f84407 faile ZRLE encode. success raw encode.
e085711
parents: 13
diff changeset
14 import java.io.InputStreamReader;
23
b51bb7bc0766 test update
e085711
parents: 20
diff changeset
15 import java.net.BindException;
10
2840c7a259f1 add acceptThread
e085711
parents:
diff changeset
16 import java.net.ServerSocket;
2840c7a259f1 add acceptThread
e085711
parents:
diff changeset
17 import java.net.Socket;
90
462bca4c8cec ByteBuffer
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 88
diff changeset
18 import java.nio.ByteBuffer;
93
40c22e507655 unzip/zip Test passed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 92
diff changeset
19 import java.util.Iterator;
10
2840c7a259f1 add acceptThread
e085711
parents:
diff changeset
20 import java.util.LinkedList;
2840c7a259f1 add acceptThread
e085711
parents:
diff changeset
21
25
cded9fd297ab create png data
e085711
parents: 24
diff changeset
22 import javax.imageio.ImageIO;
cded9fd297ab create png data
e085711
parents: 24
diff changeset
23
88
9b3b1e3e7db5 add test routine
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
24 import org.junit.Test;
9b3b1e3e7db5 add test routine
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
25
54
796f2b3b8665 modify MyRfbProto.java
e085711
parents: 51
diff changeset
26 import myVncProxy.MulticastQueue.Client;
796f2b3b8665 modify MyRfbProto.java
e085711
parents: 51
diff changeset
27
40
dd1321b67f95 sendReadData : newSingleThreadExecutor()
e085711
parents: 39
diff changeset
28 import java.util.concurrent.ExecutorService;
dd1321b67f95 sendReadData : newSingleThreadExecutor()
e085711
parents: 39
diff changeset
29 import java.util.concurrent.Executors;
80
712a047908df recompress output
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 78
diff changeset
30 import java.util.zip.DataFormatException;
712a047908df recompress output
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 78
diff changeset
31 import java.util.zip.Deflater;
712a047908df recompress output
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 78
diff changeset
32 import java.util.zip.Inflater;
40
dd1321b67f95 sendReadData : newSingleThreadExecutor()
e085711
parents: 39
diff changeset
33 import java.io.OutputStream;
10
2840c7a259f1 add acceptThread
e085711
parents:
diff changeset
34
88
9b3b1e3e7db5 add test routine
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
35 public
93
40c22e507655 unzip/zip Test passed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 92
diff changeset
36 class MyRfbProto<ByteBuffersIterator> extends RfbProto {
43
08317224ce21 create RFB 003.998
e085711
parents: 40
diff changeset
37 final static String versionMsg_3_998 = "RFB 003.998\n";
65
5fca2bb52dc7 create checkMillis
e085711
parents: 62
diff changeset
38 /**
5fca2bb52dc7 create checkMillis
e085711
parents: 62
diff changeset
39 * CheckMillis is one of new msgType for RFB 3.998.
5fca2bb52dc7 create checkMillis
e085711
parents: 62
diff changeset
40 */
90
462bca4c8cec ByteBuffer
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 88
diff changeset
41 final static byte SpeedCheckMillis = 4;
83
d4236fd2efe1 too much memory
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 82
diff changeset
42 private static final int INFLATE_BUFSIZE = 1024*100;
65
5fca2bb52dc7 create checkMillis
e085711
parents: 62
diff changeset
43 boolean printStatusFlag = false;
5fca2bb52dc7 create checkMillis
e085711
parents: 62
diff changeset
44 long startCheckTime;
54
796f2b3b8665 modify MyRfbProto.java
e085711
parents: 51
diff changeset
45
18
ccad9909e0e2 raw only version
e085711
parents: 17
diff changeset
46 private int messageType;
ccad9909e0e2 raw only version
e085711
parents: 17
diff changeset
47 private int rectangles;
23
b51bb7bc0766 test update
e085711
parents: 20
diff changeset
48 private int rectX;
b51bb7bc0766 test update
e085711
parents: 20
diff changeset
49 private int rectY;
b51bb7bc0766 test update
e085711
parents: 20
diff changeset
50 private int rectW;
b51bb7bc0766 test update
e085711
parents: 20
diff changeset
51 private int rectH;
18
ccad9909e0e2 raw only version
e085711
parents: 17
diff changeset
52 private int encoding;
27
13d4d3118cb8 create rfb.cliListTmp
e085711
parents: 26
diff changeset
53 private int zLen;
18
ccad9909e0e2 raw only version
e085711
parents: 17
diff changeset
54
23
b51bb7bc0766 test update
e085711
parents: 20
diff changeset
55 private ServerSocket servSock;
b51bb7bc0766 test update
e085711
parents: 20
diff changeset
56 private int acceptPort;
10
2840c7a259f1 add acceptThread
e085711
parents:
diff changeset
57 private byte initData[];
54
796f2b3b8665 modify MyRfbProto.java
e085711
parents: 51
diff changeset
58 private LinkedList<Socket> cliListTmp;
796f2b3b8665 modify MyRfbProto.java
e085711
parents: 51
diff changeset
59 private LinkedList<Socket> cliList;
796f2b3b8665 modify MyRfbProto.java
e085711
parents: 51
diff changeset
60 private LinkedList<Thread> sendThreads;
27
13d4d3118cb8 create rfb.cliListTmp
e085711
parents: 26
diff changeset
61 boolean createBimgFlag;
54
796f2b3b8665 modify MyRfbProto.java
e085711
parents: 51
diff changeset
62
40
dd1321b67f95 sendReadData : newSingleThreadExecutor()
e085711
parents: 39
diff changeset
63 ExecutorService executor;
54
796f2b3b8665 modify MyRfbProto.java
e085711
parents: 51
diff changeset
64
25
cded9fd297ab create png data
e085711
parents: 24
diff changeset
65 byte[] pngBytes;
54
796f2b3b8665 modify MyRfbProto.java
e085711
parents: 51
diff changeset
66
99
0c5762c3a8dd Test and VNC not working... Memory Overflow...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 98
diff changeset
67 private MulticastQueue<LinkedList<ByteBuffer>> multicastqueue = new MostRecentMultiCast<LinkedList<ByteBuffer>>(10);
0c5762c3a8dd Test and VNC not working... Memory Overflow...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 98
diff changeset
68 // private MulticastQueue<LinkedList<ByteBuffer>> multicastqueue = new MulticastQueue<LinkedList<ByteBuffer>>();
80
712a047908df recompress output
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 78
diff changeset
69 private int clients = 0;
81
9109273b96dc consume too much memory
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 80
diff changeset
70 private Inflater inflater = new Inflater();
54
796f2b3b8665 modify MyRfbProto.java
e085711
parents: 51
diff changeset
71
88
9b3b1e3e7db5 add test routine
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
72 public
9b3b1e3e7db5 add test routine
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
73 MyRfbProto() throws IOException {
9b3b1e3e7db5 add test routine
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
74 }
9b3b1e3e7db5 add test routine
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
75
54
796f2b3b8665 modify MyRfbProto.java
e085711
parents: 51
diff changeset
76 MyRfbProto(String h, int p, VncViewer v) throws IOException {
10
2840c7a259f1 add acceptThread
e085711
parents:
diff changeset
77 super(h, p, v);
54
796f2b3b8665 modify MyRfbProto.java
e085711
parents: 51
diff changeset
78 cliList = new LinkedList<Socket>();
796f2b3b8665 modify MyRfbProto.java
e085711
parents: 51
diff changeset
79 cliListTmp = new LinkedList<Socket>();
27
13d4d3118cb8 create rfb.cliListTmp
e085711
parents: 26
diff changeset
80 createBimgFlag = false;
61
626cf8cc002c modify MyRfbProto.java
e085711
parents: 60
diff changeset
81 // sendThreads = new LinkedList<Thread>();
54
796f2b3b8665 modify MyRfbProto.java
e085711
parents: 51
diff changeset
82 // executor = Executors.newCachedThreadPool();
796f2b3b8665 modify MyRfbProto.java
e085711
parents: 51
diff changeset
83 // executor = Executors.newSingleThreadExecutor();
10
2840c7a259f1 add acceptThread
e085711
parents:
diff changeset
84 }
2840c7a259f1 add acceptThread
e085711
parents:
diff changeset
85
13
a5d73cafc8fe add ProxyVncCanvas and VncProxyService
e085711
parents: 10
diff changeset
86 MyRfbProto(String h, int p) throws IOException {
a5d73cafc8fe add ProxyVncCanvas and VncProxyService
e085711
parents: 10
diff changeset
87 super(h, p);
54
796f2b3b8665 modify MyRfbProto.java
e085711
parents: 51
diff changeset
88 cliList = new LinkedList<Socket>();
796f2b3b8665 modify MyRfbProto.java
e085711
parents: 51
diff changeset
89 cliListTmp = new LinkedList<Socket>();
27
13d4d3118cb8 create rfb.cliListTmp
e085711
parents: 26
diff changeset
90 createBimgFlag = false;
61
626cf8cc002c modify MyRfbProto.java
e085711
parents: 60
diff changeset
91 // sendThreads = new LinkedList<Thread>();
54
796f2b3b8665 modify MyRfbProto.java
e085711
parents: 51
diff changeset
92 // executor = Executors.newCachedThreadPool();
796f2b3b8665 modify MyRfbProto.java
e085711
parents: 51
diff changeset
93 // executor = Executors.newSingleThreadExecutor();
13
a5d73cafc8fe add ProxyVncCanvas and VncProxyService
e085711
parents: 10
diff changeset
94 }
24
87b29d6039a6 add package myVncProxy
e085711
parents: 23
diff changeset
95
44
e085711
parents: 43
diff changeset
96 // over write
43
08317224ce21 create RFB 003.998
e085711
parents: 40
diff changeset
97 void writeVersionMsg() throws IOException {
08317224ce21 create RFB 003.998
e085711
parents: 40
diff changeset
98 clientMajor = 3;
08317224ce21 create RFB 003.998
e085711
parents: 40
diff changeset
99 if (serverMinor >= 9) {
54
796f2b3b8665 modify MyRfbProto.java
e085711
parents: 51
diff changeset
100 clientMinor = 9;
796f2b3b8665 modify MyRfbProto.java
e085711
parents: 51
diff changeset
101 os.write(versionMsg_3_998.getBytes());
43
08317224ce21 create RFB 003.998
e085711
parents: 40
diff changeset
102 } else if (serverMajor > 3 || serverMinor >= 8) {
08317224ce21 create RFB 003.998
e085711
parents: 40
diff changeset
103 clientMinor = 8;
08317224ce21 create RFB 003.998
e085711
parents: 40
diff changeset
104 os.write(versionMsg_3_8.getBytes());
08317224ce21 create RFB 003.998
e085711
parents: 40
diff changeset
105 } else if (serverMinor >= 9) {
08317224ce21 create RFB 003.998
e085711
parents: 40
diff changeset
106 clientMinor = 9;
08317224ce21 create RFB 003.998
e085711
parents: 40
diff changeset
107 os.write(versionMsg_3_998.getBytes());
08317224ce21 create RFB 003.998
e085711
parents: 40
diff changeset
108 } else if (serverMinor >= 7) {
08317224ce21 create RFB 003.998
e085711
parents: 40
diff changeset
109 clientMinor = 7;
08317224ce21 create RFB 003.998
e085711
parents: 40
diff changeset
110 os.write(versionMsg_3_7.getBytes());
08317224ce21 create RFB 003.998
e085711
parents: 40
diff changeset
111 } else {
08317224ce21 create RFB 003.998
e085711
parents: 40
diff changeset
112 clientMinor = 3;
08317224ce21 create RFB 003.998
e085711
parents: 40
diff changeset
113 os.write(versionMsg_3_3.getBytes());
08317224ce21 create RFB 003.998
e085711
parents: 40
diff changeset
114 }
08317224ce21 create RFB 003.998
e085711
parents: 40
diff changeset
115 protocolTightVNC = false;
08317224ce21 create RFB 003.998
e085711
parents: 40
diff changeset
116 initCapabilities();
08317224ce21 create RFB 003.998
e085711
parents: 40
diff changeset
117 }
08317224ce21 create RFB 003.998
e085711
parents: 40
diff changeset
118
54
796f2b3b8665 modify MyRfbProto.java
e085711
parents: 51
diff changeset
119 void initServSock(int port) throws IOException {
10
2840c7a259f1 add acceptThread
e085711
parents:
diff changeset
120 servSock = new ServerSocket(port);
23
b51bb7bc0766 test update
e085711
parents: 20
diff changeset
121 acceptPort = port;
10
2840c7a259f1 add acceptThread
e085711
parents:
diff changeset
122 }
54
796f2b3b8665 modify MyRfbProto.java
e085711
parents: 51
diff changeset
123
796f2b3b8665 modify MyRfbProto.java
e085711
parents: 51
diff changeset
124 // 5550を開けるが、開いてないなら+1のポートを開ける。
80
712a047908df recompress output
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 78
diff changeset
125 void selectPort(int p) {
712a047908df recompress output
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 78
diff changeset
126 int port = p;
54
796f2b3b8665 modify MyRfbProto.java
e085711
parents: 51
diff changeset
127 while (true) {
796f2b3b8665 modify MyRfbProto.java
e085711
parents: 51
diff changeset
128 try {
80
712a047908df recompress output
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 78
diff changeset
129 initServSock(port);
23
b51bb7bc0766 test update
e085711
parents: 20
diff changeset
130 break;
54
796f2b3b8665 modify MyRfbProto.java
e085711
parents: 51
diff changeset
131 } catch (BindException e) {
80
712a047908df recompress output
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 78
diff changeset
132 port++;
23
b51bb7bc0766 test update
e085711
parents: 20
diff changeset
133 continue;
54
796f2b3b8665 modify MyRfbProto.java
e085711
parents: 51
diff changeset
134 } catch (IOException e) {
10
2840c7a259f1 add acceptThread
e085711
parents:
diff changeset
135
23
b51bb7bc0766 test update
e085711
parents: 20
diff changeset
136 }
b51bb7bc0766 test update
e085711
parents: 20
diff changeset
137 }
80
712a047908df recompress output
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 78
diff changeset
138 System.out.println("accept port = " + port);
23
b51bb7bc0766 test update
e085711
parents: 20
diff changeset
139 }
54
796f2b3b8665 modify MyRfbProto.java
e085711
parents: 51
diff changeset
140
796f2b3b8665 modify MyRfbProto.java
e085711
parents: 51
diff changeset
141 int getAcceptPort() {
23
b51bb7bc0766 test update
e085711
parents: 20
diff changeset
142 return acceptPort;
b51bb7bc0766 test update
e085711
parents: 20
diff changeset
143 }
54
796f2b3b8665 modify MyRfbProto.java
e085711
parents: 51
diff changeset
144
10
2840c7a259f1 add acceptThread
e085711
parents:
diff changeset
145 void setSoTimeout(int num) throws IOException {
2840c7a259f1 add acceptThread
e085711
parents:
diff changeset
146 servSock.setSoTimeout(num);
2840c7a259f1 add acceptThread
e085711
parents:
diff changeset
147 }
54
796f2b3b8665 modify MyRfbProto.java
e085711
parents: 51
diff changeset
148
10
2840c7a259f1 add acceptThread
e085711
parents:
diff changeset
149 Socket accept() throws IOException {
2840c7a259f1 add acceptThread
e085711
parents:
diff changeset
150 return servSock.accept();
2840c7a259f1 add acceptThread
e085711
parents:
diff changeset
151 }
2840c7a259f1 add acceptThread
e085711
parents:
diff changeset
152
54
796f2b3b8665 modify MyRfbProto.java
e085711
parents: 51
diff changeset
153 void addSock(Socket sock) {
10
2840c7a259f1 add acceptThread
e085711
parents:
diff changeset
154 cliList.add(sock);
2840c7a259f1 add acceptThread
e085711
parents:
diff changeset
155 }
54
796f2b3b8665 modify MyRfbProto.java
e085711
parents: 51
diff changeset
156
796f2b3b8665 modify MyRfbProto.java
e085711
parents: 51
diff changeset
157 void addSockTmp(Socket sock) {
796f2b3b8665 modify MyRfbProto.java
e085711
parents: 51
diff changeset
158 System.out.println("connected " + sock.getInetAddress());
27
13d4d3118cb8 create rfb.cliListTmp
e085711
parents: 26
diff changeset
159 cliListTmp.add(sock);
13d4d3118cb8 create rfb.cliListTmp
e085711
parents: 26
diff changeset
160 }
54
796f2b3b8665 modify MyRfbProto.java
e085711
parents: 51
diff changeset
161
10
2840c7a259f1 add acceptThread
e085711
parents:
diff changeset
162 boolean markSupported() {
2840c7a259f1 add acceptThread
e085711
parents:
diff changeset
163 return is.markSupported();
2840c7a259f1 add acceptThread
e085711
parents:
diff changeset
164 }
54
796f2b3b8665 modify MyRfbProto.java
e085711
parents: 51
diff changeset
165
10
2840c7a259f1 add acceptThread
e085711
parents:
diff changeset
166 void readServerInit() throws IOException {
54
796f2b3b8665 modify MyRfbProto.java
e085711
parents: 51
diff changeset
167
78
5970410efee7 modify VncProxyService. EncodingRAW -> EncodingZlib
e085711
parents: 77
diff changeset
168 is.mark(255);
10
2840c7a259f1 add acceptThread
e085711
parents:
diff changeset
169 skipBytes(20);
2840c7a259f1 add acceptThread
e085711
parents:
diff changeset
170 int nlen = readU32();
54
796f2b3b8665 modify MyRfbProto.java
e085711
parents: 51
diff changeset
171 int blen = 20 + 4 + nlen;
10
2840c7a259f1 add acceptThread
e085711
parents:
diff changeset
172 initData = new byte[blen];
78
5970410efee7 modify VncProxyService. EncodingRAW -> EncodingZlib
e085711
parents: 77
diff changeset
173 is.reset();
10
2840c7a259f1 add acceptThread
e085711
parents:
diff changeset
174
78
5970410efee7 modify VncProxyService. EncodingRAW -> EncodingZlib
e085711
parents: 77
diff changeset
175 is.mark(blen);
10
2840c7a259f1 add acceptThread
e085711
parents:
diff changeset
176 readFully(initData);
78
5970410efee7 modify VncProxyService. EncodingRAW -> EncodingZlib
e085711
parents: 77
diff changeset
177 is.reset();
54
796f2b3b8665 modify MyRfbProto.java
e085711
parents: 51
diff changeset
178
10
2840c7a259f1 add acceptThread
e085711
parents:
diff changeset
179 framebufferWidth = readU16();
2840c7a259f1 add acceptThread
e085711
parents:
diff changeset
180 framebufferHeight = readU16();
2840c7a259f1 add acceptThread
e085711
parents:
diff changeset
181 bitsPerPixel = readU8();
2840c7a259f1 add acceptThread
e085711
parents:
diff changeset
182 depth = readU8();
2840c7a259f1 add acceptThread
e085711
parents:
diff changeset
183 bigEndian = (readU8() != 0);
2840c7a259f1 add acceptThread
e085711
parents:
diff changeset
184 trueColour = (readU8() != 0);
2840c7a259f1 add acceptThread
e085711
parents:
diff changeset
185 redMax = readU16();
2840c7a259f1 add acceptThread
e085711
parents:
diff changeset
186 greenMax = readU16();
2840c7a259f1 add acceptThread
e085711
parents:
diff changeset
187 blueMax = readU16();
2840c7a259f1 add acceptThread
e085711
parents:
diff changeset
188 redShift = readU8();
2840c7a259f1 add acceptThread
e085711
parents:
diff changeset
189 greenShift = readU8();
2840c7a259f1 add acceptThread
e085711
parents:
diff changeset
190 blueShift = readU8();
2840c7a259f1 add acceptThread
e085711
parents:
diff changeset
191 byte[] pad = new byte[3];
2840c7a259f1 add acceptThread
e085711
parents:
diff changeset
192 readFully(pad);
2840c7a259f1 add acceptThread
e085711
parents:
diff changeset
193 int nameLength = readU32();
2840c7a259f1 add acceptThread
e085711
parents:
diff changeset
194 byte[] name = new byte[nameLength];
2840c7a259f1 add acceptThread
e085711
parents:
diff changeset
195 readFully(name);
2840c7a259f1 add acceptThread
e085711
parents:
diff changeset
196 desktopName = new String(name);
2840c7a259f1 add acceptThread
e085711
parents:
diff changeset
197
2840c7a259f1 add acceptThread
e085711
parents:
diff changeset
198 // Read interaction capabilities (TightVNC protocol extensions)
2840c7a259f1 add acceptThread
e085711
parents:
diff changeset
199 if (protocolTightVNC) {
2840c7a259f1 add acceptThread
e085711
parents:
diff changeset
200 int nServerMessageTypes = readU16();
2840c7a259f1 add acceptThread
e085711
parents:
diff changeset
201 int nClientMessageTypes = readU16();
2840c7a259f1 add acceptThread
e085711
parents:
diff changeset
202 int nEncodingTypes = readU16();
2840c7a259f1 add acceptThread
e085711
parents:
diff changeset
203 readU16();
2840c7a259f1 add acceptThread
e085711
parents:
diff changeset
204 readCapabilityList(serverMsgCaps, nServerMessageTypes);
2840c7a259f1 add acceptThread
e085711
parents:
diff changeset
205 readCapabilityList(clientMsgCaps, nClientMessageTypes);
2840c7a259f1 add acceptThread
e085711
parents:
diff changeset
206 readCapabilityList(encodingCaps, nEncodingTypes);
2840c7a259f1 add acceptThread
e085711
parents:
diff changeset
207 }
2840c7a259f1 add acceptThread
e085711
parents:
diff changeset
208
2840c7a259f1 add acceptThread
e085711
parents:
diff changeset
209 inNormalProtocol = true;
2840c7a259f1 add acceptThread
e085711
parents:
diff changeset
210 }
2840c7a259f1 add acceptThread
e085711
parents:
diff changeset
211
54
796f2b3b8665 modify MyRfbProto.java
e085711
parents: 51
diff changeset
212 void sendRfbVersion(OutputStream os) throws IOException {
796f2b3b8665 modify MyRfbProto.java
e085711
parents: 51
diff changeset
213 os.write(versionMsg_3_998.getBytes());
43
08317224ce21 create RFB 003.998
e085711
parents: 40
diff changeset
214 }
54
796f2b3b8665 modify MyRfbProto.java
e085711
parents: 51
diff changeset
215
45
b16072ddc911 modify MyRfbProto.java acceptThread.java
e085711
parents: 44
diff changeset
216 void readVersionMsg(InputStream is) throws IOException {
b16072ddc911 modify MyRfbProto.java acceptThread.java
e085711
parents: 44
diff changeset
217
b16072ddc911 modify MyRfbProto.java acceptThread.java
e085711
parents: 44
diff changeset
218 byte[] b = new byte[12];
b16072ddc911 modify MyRfbProto.java acceptThread.java
e085711
parents: 44
diff changeset
219
b16072ddc911 modify MyRfbProto.java acceptThread.java
e085711
parents: 44
diff changeset
220 is.read(b);
b16072ddc911 modify MyRfbProto.java acceptThread.java
e085711
parents: 44
diff changeset
221
b16072ddc911 modify MyRfbProto.java acceptThread.java
e085711
parents: 44
diff changeset
222 if ((b[0] != 'R') || (b[1] != 'F') || (b[2] != 'B') || (b[3] != ' ')
b16072ddc911 modify MyRfbProto.java acceptThread.java
e085711
parents: 44
diff changeset
223 || (b[4] < '0') || (b[4] > '9') || (b[5] < '0') || (b[5] > '9')
b16072ddc911 modify MyRfbProto.java acceptThread.java
e085711
parents: 44
diff changeset
224 || (b[6] < '0') || (b[6] > '9') || (b[7] != '.')
b16072ddc911 modify MyRfbProto.java acceptThread.java
e085711
parents: 44
diff changeset
225 || (b[8] < '0') || (b[8] > '9') || (b[9] < '0') || (b[9] > '9')
b16072ddc911 modify MyRfbProto.java acceptThread.java
e085711
parents: 44
diff changeset
226 || (b[10] < '0') || (b[10] > '9') || (b[11] != '\n')) {
b16072ddc911 modify MyRfbProto.java acceptThread.java
e085711
parents: 44
diff changeset
227 throw new IOException("Host " + host + " port " + port
b16072ddc911 modify MyRfbProto.java acceptThread.java
e085711
parents: 44
diff changeset
228 + " is not an RFB server");
b16072ddc911 modify MyRfbProto.java acceptThread.java
e085711
parents: 44
diff changeset
229 }
b16072ddc911 modify MyRfbProto.java acceptThread.java
e085711
parents: 44
diff changeset
230
b16072ddc911 modify MyRfbProto.java acceptThread.java
e085711
parents: 44
diff changeset
231 serverMajor = (b[4] - '0') * 100 + (b[5] - '0') * 10 + (b[6] - '0');
b16072ddc911 modify MyRfbProto.java acceptThread.java
e085711
parents: 44
diff changeset
232 serverMinor = (b[8] - '0') * 100 + (b[9] - '0') * 10 + (b[10] - '0');
b16072ddc911 modify MyRfbProto.java acceptThread.java
e085711
parents: 44
diff changeset
233
b16072ddc911 modify MyRfbProto.java acceptThread.java
e085711
parents: 44
diff changeset
234 if (serverMajor < 3) {
b16072ddc911 modify MyRfbProto.java acceptThread.java
e085711
parents: 44
diff changeset
235 throw new IOException(
b16072ddc911 modify MyRfbProto.java acceptThread.java
e085711
parents: 44
diff changeset
236 "RFB server does not support protocol version 3");
54
796f2b3b8665 modify MyRfbProto.java
e085711
parents: 51
diff changeset
237 }
796f2b3b8665 modify MyRfbProto.java
e085711
parents: 51
diff changeset
238
796f2b3b8665 modify MyRfbProto.java
e085711
parents: 51
diff changeset
239 }
796f2b3b8665 modify MyRfbProto.java
e085711
parents: 51
diff changeset
240
43
08317224ce21 create RFB 003.998
e085711
parents: 40
diff changeset
241 void sendSecurityType(OutputStream os) throws IOException {
08317224ce21 create RFB 003.998
e085711
parents: 40
diff changeset
242 // number-of-security-types
08317224ce21 create RFB 003.998
e085711
parents: 40
diff changeset
243 os.write(1);
54
796f2b3b8665 modify MyRfbProto.java
e085711
parents: 51
diff changeset
244 // security-types
43
08317224ce21 create RFB 003.998
e085711
parents: 40
diff changeset
245 // 1:None
08317224ce21 create RFB 003.998
e085711
parents: 40
diff changeset
246 os.write(1);
08317224ce21 create RFB 003.998
e085711
parents: 40
diff changeset
247 }
54
796f2b3b8665 modify MyRfbProto.java
e085711
parents: 51
diff changeset
248
46
11da7dacbc1a modify MyRfbProto.java and acceptThread.java add readSecType
e085711
parents: 45
diff changeset
249 void readSecType(InputStream is) throws IOException {
11da7dacbc1a modify MyRfbProto.java and acceptThread.java add readSecType
e085711
parents: 45
diff changeset
250 byte[] b = new byte[1];
11da7dacbc1a modify MyRfbProto.java and acceptThread.java add readSecType
e085711
parents: 45
diff changeset
251 is.read(b);
11da7dacbc1a modify MyRfbProto.java and acceptThread.java add readSecType
e085711
parents: 45
diff changeset
252
11da7dacbc1a modify MyRfbProto.java and acceptThread.java add readSecType
e085711
parents: 45
diff changeset
253 }
54
796f2b3b8665 modify MyRfbProto.java
e085711
parents: 51
diff changeset
254
47
b2bf4e44504a modify MyRfbProto.java and acceptThread.java , add sendSecResult
e085711
parents: 46
diff changeset
255 void sendSecResult(OutputStream os) throws IOException {
b2bf4e44504a modify MyRfbProto.java and acceptThread.java , add sendSecResult
e085711
parents: 46
diff changeset
256 byte[] b = castIntByte(0);
b2bf4e44504a modify MyRfbProto.java and acceptThread.java , add sendSecResult
e085711
parents: 46
diff changeset
257 os.write(b);
b2bf4e44504a modify MyRfbProto.java and acceptThread.java , add sendSecResult
e085711
parents: 46
diff changeset
258 }
54
796f2b3b8665 modify MyRfbProto.java
e085711
parents: 51
diff changeset
259
43
08317224ce21 create RFB 003.998
e085711
parents: 40
diff changeset
260 void readClientInit(InputStream in) throws IOException {
08317224ce21 create RFB 003.998
e085711
parents: 40
diff changeset
261 byte[] b = new byte[0];
08317224ce21 create RFB 003.998
e085711
parents: 40
diff changeset
262 in.read(b);
08317224ce21 create RFB 003.998
e085711
parents: 40
diff changeset
263 }
54
796f2b3b8665 modify MyRfbProto.java
e085711
parents: 51
diff changeset
264
796f2b3b8665 modify MyRfbProto.java
e085711
parents: 51
diff changeset
265 void sendInitData(OutputStream os) throws IOException {
796f2b3b8665 modify MyRfbProto.java
e085711
parents: 51
diff changeset
266 os.write(initData);
10
2840c7a259f1 add acceptThread
e085711
parents:
diff changeset
267 }
2840c7a259f1 add acceptThread
e085711
parents:
diff changeset
268
54
796f2b3b8665 modify MyRfbProto.java
e085711
parents: 51
diff changeset
269
796f2b3b8665 modify MyRfbProto.java
e085711
parents: 51
diff changeset
270 void sendPngImage() {
796f2b3b8665 modify MyRfbProto.java
e085711
parents: 51
diff changeset
271 try {
796f2b3b8665 modify MyRfbProto.java
e085711
parents: 51
diff changeset
272 for (Socket cli : cliListTmp) {
796f2b3b8665 modify MyRfbProto.java
e085711
parents: 51
diff changeset
273 try {
27
13d4d3118cb8 create rfb.cliListTmp
e085711
parents: 26
diff changeset
274 sendPngData(cli);
13d4d3118cb8 create rfb.cliListTmp
e085711
parents: 26
diff changeset
275 addSock(cli);
54
796f2b3b8665 modify MyRfbProto.java
e085711
parents: 51
diff changeset
276 } catch (IOException e) {
27
13d4d3118cb8 create rfb.cliListTmp
e085711
parents: 26
diff changeset
277 // if socket closed
13d4d3118cb8 create rfb.cliListTmp
e085711
parents: 26
diff changeset
278 cliListTmp.remove(cli);
13d4d3118cb8 create rfb.cliListTmp
e085711
parents: 26
diff changeset
279 }
13d4d3118cb8 create rfb.cliListTmp
e085711
parents: 26
diff changeset
280 }
54
796f2b3b8665 modify MyRfbProto.java
e085711
parents: 51
diff changeset
281 // System.out.println("cliSize="+cliSize());
796f2b3b8665 modify MyRfbProto.java
e085711
parents: 51
diff changeset
282 } catch (Exception e) {
27
13d4d3118cb8 create rfb.cliListTmp
e085711
parents: 26
diff changeset
283 }
13d4d3118cb8 create rfb.cliListTmp
e085711
parents: 26
diff changeset
284 cliListTmp.clear();
13d4d3118cb8 create rfb.cliListTmp
e085711
parents: 26
diff changeset
285 }
13d4d3118cb8 create rfb.cliListTmp
e085711
parents: 26
diff changeset
286
15
89e1c5f84407 faile ZRLE encode. success raw encode.
e085711
parents: 13
diff changeset
287 boolean ready() throws IOException {
89e1c5f84407 faile ZRLE encode. success raw encode.
e085711
parents: 13
diff changeset
288 BufferedReader br = new BufferedReader(new InputStreamReader(is));
89e1c5f84407 faile ZRLE encode. success raw encode.
e085711
parents: 13
diff changeset
289 return br.ready();
54
796f2b3b8665 modify MyRfbProto.java
e085711
parents: 51
diff changeset
290 }
10
2840c7a259f1 add acceptThread
e085711
parents:
diff changeset
291
54
796f2b3b8665 modify MyRfbProto.java
e085711
parents: 51
diff changeset
292 int cliSize() {
10
2840c7a259f1 add acceptThread
e085711
parents:
diff changeset
293 return cliList.size();
54
796f2b3b8665 modify MyRfbProto.java
e085711
parents: 51
diff changeset
294 }
796f2b3b8665 modify MyRfbProto.java
e085711
parents: 51
diff changeset
295
796f2b3b8665 modify MyRfbProto.java
e085711
parents: 51
diff changeset
296 void printNumBytesRead() {
796f2b3b8665 modify MyRfbProto.java
e085711
parents: 51
diff changeset
297 System.out.println("numBytesRead=" + numBytesRead);
796f2b3b8665 modify MyRfbProto.java
e085711
parents: 51
diff changeset
298 }
796f2b3b8665 modify MyRfbProto.java
e085711
parents: 51
diff changeset
299
796f2b3b8665 modify MyRfbProto.java
e085711
parents: 51
diff changeset
300
61
626cf8cc002c modify MyRfbProto.java
e085711
parents: 60
diff changeset
301
54
796f2b3b8665 modify MyRfbProto.java
e085711
parents: 51
diff changeset
302 void regiFramebufferUpdate() throws IOException {
78
5970410efee7 modify VncProxyService. EncodingRAW -> EncodingZlib
e085711
parents: 77
diff changeset
303 is.mark(20);
80
712a047908df recompress output
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 78
diff changeset
304 messageType = readU8(); // 0
712a047908df recompress output
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 78
diff changeset
305 skipBytes(1); // 1
712a047908df recompress output
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 78
diff changeset
306 rectangles = readU16(); // 2
712a047908df recompress output
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 78
diff changeset
307 rectX = readU16(); // 4
712a047908df recompress output
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 78
diff changeset
308 rectY = readU16(); // 6
712a047908df recompress output
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 78
diff changeset
309 rectW = readU16(); // 8
712a047908df recompress output
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 78
diff changeset
310 rectH = readU16(); // 10
712a047908df recompress output
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 78
diff changeset
311 encoding = readU32(); // 12
78
5970410efee7 modify VncProxyService. EncodingRAW -> EncodingZlib
e085711
parents: 77
diff changeset
312 System.out.println("encoding = "+encoding);
80
712a047908df recompress output
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 78
diff changeset
313 if (encoding == EncodingZRLE)
27
13d4d3118cb8 create rfb.cliListTmp
e085711
parents: 26
diff changeset
314 zLen = readU32();
80
712a047908df recompress output
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 78
diff changeset
315 else
712a047908df recompress output
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 78
diff changeset
316 zLen = 0;
78
5970410efee7 modify VncProxyService. EncodingRAW -> EncodingZlib
e085711
parents: 77
diff changeset
317 is.reset();
67
f695bc56eb4f add OptionNoFrame.java. add setEncodings.
e085711
parents: 66
diff changeset
318 /*
f695bc56eb4f add OptionNoFrame.java. add setEncodings.
e085711
parents: 66
diff changeset
319 int dataLen;
f695bc56eb4f add OptionNoFrame.java. add setEncodings.
e085711
parents: 66
diff changeset
320 switch (encoding) {
f695bc56eb4f add OptionNoFrame.java. add setEncodings.
e085711
parents: 66
diff changeset
321 case RfbProto.EncodingRaw:
f695bc56eb4f add OptionNoFrame.java. add setEncodings.
e085711
parents: 66
diff changeset
322 dataLen = rectW * rectH * 4 + 16;
f695bc56eb4f add OptionNoFrame.java. add setEncodings.
e085711
parents: 66
diff changeset
323 mark(dataLen);
f695bc56eb4f add OptionNoFrame.java. add setEncodings.
e085711
parents: 66
diff changeset
324 break;
f695bc56eb4f add OptionNoFrame.java. add setEncodings.
e085711
parents: 66
diff changeset
325 case RfbProto.EncodingCopyRect:
f695bc56eb4f add OptionNoFrame.java. add setEncodings.
e085711
parents: 66
diff changeset
326 dataLen = 16 + 4;
f695bc56eb4f add OptionNoFrame.java. add setEncodings.
e085711
parents: 66
diff changeset
327 mark(dataLen);
f695bc56eb4f add OptionNoFrame.java. add setEncodings.
e085711
parents: 66
diff changeset
328 break;
f695bc56eb4f add OptionNoFrame.java. add setEncodings.
e085711
parents: 66
diff changeset
329 case RfbProto.EncodingRRE:
f695bc56eb4f add OptionNoFrame.java. add setEncodings.
e085711
parents: 66
diff changeset
330 case RfbProto.EncodingCoRRE:
f695bc56eb4f add OptionNoFrame.java. add setEncodings.
e085711
parents: 66
diff changeset
331 case RfbProto.EncodingHextile:
f695bc56eb4f add OptionNoFrame.java. add setEncodings.
e085711
parents: 66
diff changeset
332
f695bc56eb4f add OptionNoFrame.java. add setEncodings.
e085711
parents: 66
diff changeset
333 case RfbProto.EncodingZlib:
f695bc56eb4f add OptionNoFrame.java. add setEncodings.
e085711
parents: 66
diff changeset
334 case RfbProto.EncodingTight:
f695bc56eb4f add OptionNoFrame.java. add setEncodings.
e085711
parents: 66
diff changeset
335 case RfbProto.EncodingZRLE:
f695bc56eb4f add OptionNoFrame.java. add setEncodings.
e085711
parents: 66
diff changeset
336 dataLen = zLen + 20;
f695bc56eb4f add OptionNoFrame.java. add setEncodings.
e085711
parents: 66
diff changeset
337 mark(dataLen);
f695bc56eb4f add OptionNoFrame.java. add setEncodings.
e085711
parents: 66
diff changeset
338 break;
f695bc56eb4f add OptionNoFrame.java. add setEncodings.
e085711
parents: 66
diff changeset
339 default:
f695bc56eb4f add OptionNoFrame.java. add setEncodings.
e085711
parents: 66
diff changeset
340 dataLen = 1000000;
f695bc56eb4f add OptionNoFrame.java. add setEncodings.
e085711
parents: 66
diff changeset
341 mark(dataLen);
f695bc56eb4f add OptionNoFrame.java. add setEncodings.
e085711
parents: 66
diff changeset
342 }
f695bc56eb4f add OptionNoFrame.java. add setEncodings.
e085711
parents: 66
diff changeset
343
f695bc56eb4f add OptionNoFrame.java. add setEncodings.
e085711
parents: 66
diff changeset
344 */
f695bc56eb4f add OptionNoFrame.java. add setEncodings.
e085711
parents: 66
diff changeset
345
15
89e1c5f84407 faile ZRLE encode. success raw encode.
e085711
parents: 13
diff changeset
346 }
54
796f2b3b8665 modify MyRfbProto.java
e085711
parents: 51
diff changeset
347
61
626cf8cc002c modify MyRfbProto.java
e085711
parents: 60
diff changeset
348 int checkAndMark() throws IOException {
626cf8cc002c modify MyRfbProto.java
e085711
parents: 60
diff changeset
349 int dataLen;
54
796f2b3b8665 modify MyRfbProto.java
e085711
parents: 51
diff changeset
350 switch (encoding) {
23
b51bb7bc0766 test update
e085711
parents: 20
diff changeset
351 case RfbProto.EncodingRaw:
39
f399eec66846 send data:multi thread
e085711
parents: 38
diff changeset
352 dataLen = rectW * rectH * 4 + 16;
78
5970410efee7 modify VncProxyService. EncodingRAW -> EncodingZlib
e085711
parents: 77
diff changeset
353 is.mark(dataLen);
23
b51bb7bc0766 test update
e085711
parents: 20
diff changeset
354 break;
67
f695bc56eb4f add OptionNoFrame.java. add setEncodings.
e085711
parents: 66
diff changeset
355 case RfbProto.EncodingCopyRect:
f695bc56eb4f add OptionNoFrame.java. add setEncodings.
e085711
parents: 66
diff changeset
356 dataLen = 16 + 4;
78
5970410efee7 modify VncProxyService. EncodingRAW -> EncodingZlib
e085711
parents: 77
diff changeset
357 is.mark(dataLen);
67
f695bc56eb4f add OptionNoFrame.java. add setEncodings.
e085711
parents: 66
diff changeset
358 break;
f695bc56eb4f add OptionNoFrame.java. add setEncodings.
e085711
parents: 66
diff changeset
359 case RfbProto.EncodingRRE:
f695bc56eb4f add OptionNoFrame.java. add setEncodings.
e085711
parents: 66
diff changeset
360 case RfbProto.EncodingCoRRE:
f695bc56eb4f add OptionNoFrame.java. add setEncodings.
e085711
parents: 66
diff changeset
361 case RfbProto.EncodingHextile:
80
712a047908df recompress output
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 78
diff changeset
362 case RfbProto.EncodingTight:
712a047908df recompress output
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 78
diff changeset
363 dataLen = zLen + 20;
712a047908df recompress output
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 78
diff changeset
364 is.mark(dataLen);
712a047908df recompress output
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 78
diff changeset
365 break;
67
f695bc56eb4f add OptionNoFrame.java. add setEncodings.
e085711
parents: 66
diff changeset
366 case RfbProto.EncodingZlib:
27
13d4d3118cb8 create rfb.cliListTmp
e085711
parents: 26
diff changeset
367 case RfbProto.EncodingZRLE:
54
796f2b3b8665 modify MyRfbProto.java
e085711
parents: 51
diff changeset
368 dataLen = zLen + 20;
78
5970410efee7 modify VncProxyService. EncodingRAW -> EncodingZlib
e085711
parents: 77
diff changeset
369 is.mark(dataLen);
5970410efee7 modify VncProxyService. EncodingRAW -> EncodingZlib
e085711
parents: 77
diff changeset
370 break;
5970410efee7 modify VncProxyService. EncodingRAW -> EncodingZlib
e085711
parents: 77
diff changeset
371 case RfbProto.EncodingXCursor:
5970410efee7 modify VncProxyService. EncodingRAW -> EncodingZlib
e085711
parents: 77
diff changeset
372 case RfbProto.EncodingRichCursor:
5970410efee7 modify VncProxyService. EncodingRAW -> EncodingZlib
e085711
parents: 77
diff changeset
373 int pixArray = rectW * rectH * 4;
5970410efee7 modify VncProxyService. EncodingRAW -> EncodingZlib
e085711
parents: 77
diff changeset
374 int u8Array = (int)Math.floor((rectW + 7)/8) * rectH;
5970410efee7 modify VncProxyService. EncodingRAW -> EncodingZlib
e085711
parents: 77
diff changeset
375 dataLen = pixArray + u8Array;
5970410efee7 modify VncProxyService. EncodingRAW -> EncodingZlib
e085711
parents: 77
diff changeset
376 printFramebufferUpdate();
5970410efee7 modify VncProxyService. EncodingRAW -> EncodingZlib
e085711
parents: 77
diff changeset
377 is.mark(dataLen);
27
13d4d3118cb8 create rfb.cliListTmp
e085711
parents: 26
diff changeset
378 break;
23
b51bb7bc0766 test update
e085711
parents: 20
diff changeset
379 default:
61
626cf8cc002c modify MyRfbProto.java
e085711
parents: 60
diff changeset
380 dataLen = 1000000;
78
5970410efee7 modify VncProxyService. EncodingRAW -> EncodingZlib
e085711
parents: 77
diff changeset
381 is.mark(dataLen);
54
796f2b3b8665 modify MyRfbProto.java
e085711
parents: 51
diff changeset
382 }
61
626cf8cc002c modify MyRfbProto.java
e085711
parents: 60
diff changeset
383 return dataLen;
626cf8cc002c modify MyRfbProto.java
e085711
parents: 60
diff changeset
384 }
65
5fca2bb52dc7 create checkMillis
e085711
parents: 62
diff changeset
385
5fca2bb52dc7 create checkMillis
e085711
parents: 62
diff changeset
386
81
9109273b96dc consume too much memory
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 80
diff changeset
387 void sendDataToClient() throws Exception {
61
626cf8cc002c modify MyRfbProto.java
e085711
parents: 60
diff changeset
388 regiFramebufferUpdate();
626cf8cc002c modify MyRfbProto.java
e085711
parents: 60
diff changeset
389 int dataLen = checkAndMark();
626cf8cc002c modify MyRfbProto.java
e085711
parents: 60
diff changeset
390 readSendData(dataLen);
23
b51bb7bc0766 test update
e085711
parents: 20
diff changeset
391 }
54
796f2b3b8665 modify MyRfbProto.java
e085711
parents: 51
diff changeset
392
796f2b3b8665 modify MyRfbProto.java
e085711
parents: 51
diff changeset
393 BufferedImage createBufferedImage(Image img) {
796f2b3b8665 modify MyRfbProto.java
e085711
parents: 51
diff changeset
394 BufferedImage bimg = new BufferedImage(img.getWidth(null),
796f2b3b8665 modify MyRfbProto.java
e085711
parents: 51
diff changeset
395 img.getHeight(null), BufferedImage.TYPE_INT_RGB);
27
13d4d3118cb8 create rfb.cliListTmp
e085711
parents: 26
diff changeset
396
25
cded9fd297ab create png data
e085711
parents: 24
diff changeset
397 Graphics g = bimg.getGraphics();
cded9fd297ab create png data
e085711
parents: 24
diff changeset
398 g.drawImage(img, 0, 0, null);
cded9fd297ab create png data
e085711
parents: 24
diff changeset
399 g.dispose();
cded9fd297ab create png data
e085711
parents: 24
diff changeset
400 return bimg;
cded9fd297ab create png data
e085711
parents: 24
diff changeset
401 }
cded9fd297ab create png data
e085711
parents: 24
diff changeset
402
54
796f2b3b8665 modify MyRfbProto.java
e085711
parents: 51
diff changeset
403 void createPngBytes(BufferedImage bimg) throws IOException {
796f2b3b8665 modify MyRfbProto.java
e085711
parents: 51
diff changeset
404 pngBytes = getImageBytes(bimg, "png");
25
cded9fd297ab create png data
e085711
parents: 24
diff changeset
405 }
54
796f2b3b8665 modify MyRfbProto.java
e085711
parents: 51
diff changeset
406
796f2b3b8665 modify MyRfbProto.java
e085711
parents: 51
diff changeset
407 byte[] getBytes(BufferedImage img) throws IOException {
25
cded9fd297ab create png data
e085711
parents: 24
diff changeset
408 byte[] b = getImageBytes(img, "png");
cded9fd297ab create png data
e085711
parents: 24
diff changeset
409 return b;
cded9fd297ab create png data
e085711
parents: 24
diff changeset
410 }
54
796f2b3b8665 modify MyRfbProto.java
e085711
parents: 51
diff changeset
411
796f2b3b8665 modify MyRfbProto.java
e085711
parents: 51
diff changeset
412 byte[] getImageBytes(BufferedImage image, String imageFormat)
796f2b3b8665 modify MyRfbProto.java
e085711
parents: 51
diff changeset
413 throws IOException {
25
cded9fd297ab create png data
e085711
parents: 24
diff changeset
414 ByteArrayOutputStream bos = new ByteArrayOutputStream();
cded9fd297ab create png data
e085711
parents: 24
diff changeset
415 BufferedOutputStream os = new BufferedOutputStream(bos);
cded9fd297ab create png data
e085711
parents: 24
diff changeset
416 image.flush();
cded9fd297ab create png data
e085711
parents: 24
diff changeset
417 ImageIO.write(image, imageFormat, os);
cded9fd297ab create png data
e085711
parents: 24
diff changeset
418 os.flush();
cded9fd297ab create png data
e085711
parents: 24
diff changeset
419 os.close();
cded9fd297ab create png data
e085711
parents: 24
diff changeset
420 return bos.toByteArray();
cded9fd297ab create png data
e085711
parents: 24
diff changeset
421 }
cded9fd297ab create png data
e085711
parents: 24
diff changeset
422
54
796f2b3b8665 modify MyRfbProto.java
e085711
parents: 51
diff changeset
423 void sendPngData(Socket sock) throws IOException {
26
0aa0e0bd742c succeed drawFirstImage()!!
e085711
parents: 25
diff changeset
424 byte[] dataLength = castIntByte(pngBytes.length);
0aa0e0bd742c succeed drawFirstImage()!!
e085711
parents: 25
diff changeset
425 sock.getOutputStream().write(dataLength);
25
cded9fd297ab create png data
e085711
parents: 24
diff changeset
426 sock.getOutputStream().write(pngBytes);
cded9fd297ab create png data
e085711
parents: 24
diff changeset
427 }
54
796f2b3b8665 modify MyRfbProto.java
e085711
parents: 51
diff changeset
428
796f2b3b8665 modify MyRfbProto.java
e085711
parents: 51
diff changeset
429 byte[] castIntByte(int len) {
26
0aa0e0bd742c succeed drawFirstImage()!!
e085711
parents: 25
diff changeset
430 byte[] b = new byte[4];
54
796f2b3b8665 modify MyRfbProto.java
e085711
parents: 51
diff changeset
431 b[0] = (byte) ((len >>> 24) & 0xFF);
796f2b3b8665 modify MyRfbProto.java
e085711
parents: 51
diff changeset
432 b[1] = (byte) ((len >>> 16) & 0xFF);
796f2b3b8665 modify MyRfbProto.java
e085711
parents: 51
diff changeset
433 b[2] = (byte) ((len >>> 8) & 0xFF);
796f2b3b8665 modify MyRfbProto.java
e085711
parents: 51
diff changeset
434 b[3] = (byte) ((len >>> 0) & 0xFF);
26
0aa0e0bd742c succeed drawFirstImage()!!
e085711
parents: 25
diff changeset
435 return b;
0aa0e0bd742c succeed drawFirstImage()!!
e085711
parents: 25
diff changeset
436 }
54
796f2b3b8665 modify MyRfbProto.java
e085711
parents: 51
diff changeset
437
796f2b3b8665 modify MyRfbProto.java
e085711
parents: 51
diff changeset
438 BufferedImage createBimg() throws IOException {
25
cded9fd297ab create png data
e085711
parents: 24
diff changeset
439 BufferedImage bimg = ImageIO.read(new ByteArrayInputStream(pngBytes));
cded9fd297ab create png data
e085711
parents: 24
diff changeset
440 return bimg;
cded9fd297ab create png data
e085711
parents: 24
diff changeset
441 }
65
5fca2bb52dc7 create checkMillis
e085711
parents: 62
diff changeset
442 /*
54
796f2b3b8665 modify MyRfbProto.java
e085711
parents: 51
diff changeset
443 void readPngData() throws IOException {
25
cded9fd297ab create png data
e085711
parents: 24
diff changeset
444 pngBytes = new byte[is.available()];
cded9fd297ab create png data
e085711
parents: 24
diff changeset
445 readFully(pngBytes);
cded9fd297ab create png data
e085711
parents: 24
diff changeset
446 }
65
5fca2bb52dc7 create checkMillis
e085711
parents: 62
diff changeset
447 */
54
796f2b3b8665 modify MyRfbProto.java
e085711
parents: 51
diff changeset
448 void printFramebufferUpdate() {
796f2b3b8665 modify MyRfbProto.java
e085711
parents: 51
diff changeset
449
18
ccad9909e0e2 raw only version
e085711
parents: 17
diff changeset
450 System.out.println("messageType=" + messageType);
54
796f2b3b8665 modify MyRfbProto.java
e085711
parents: 51
diff changeset
451 System.out.println("rectangles=" + rectangles);
18
ccad9909e0e2 raw only version
e085711
parents: 17
diff changeset
452 System.out.println("encoding=" + encoding);
78
5970410efee7 modify VncProxyService. EncodingRAW -> EncodingZlib
e085711
parents: 77
diff changeset
453 System.out.println("rectX = "+rectX+": rectY = "+rectY);
5970410efee7 modify VncProxyService. EncodingRAW -> EncodingZlib
e085711
parents: 77
diff changeset
454 System.out.println("rectW = "+rectW+": rectH = "+rectH);
54
796f2b3b8665 modify MyRfbProto.java
e085711
parents: 51
diff changeset
455 switch (encoding) {
23
b51bb7bc0766 test update
e085711
parents: 20
diff changeset
456 case RfbProto.EncodingRaw:
54
796f2b3b8665 modify MyRfbProto.java
e085711
parents: 51
diff changeset
457 System.out.println("rectW * rectH * 4 + 16 =" + rectW * rectH * 4
796f2b3b8665 modify MyRfbProto.java
e085711
parents: 51
diff changeset
458 + 16);
23
b51bb7bc0766 test update
e085711
parents: 20
diff changeset
459 break;
b51bb7bc0766 test update
e085711
parents: 20
diff changeset
460 default:
b51bb7bc0766 test update
e085711
parents: 20
diff changeset
461 }
18
ccad9909e0e2 raw only version
e085711
parents: 17
diff changeset
462 }
65
5fca2bb52dc7 create checkMillis
e085711
parents: 62
diff changeset
463
77
fe5925bb9a7e modify MyRfb.java
e085711
parents: 76
diff changeset
464 void readSpeedCheck() throws IOException {
fe5925bb9a7e modify MyRfb.java
e085711
parents: 76
diff changeset
465 byte[] b = new byte[1];
65
5fca2bb52dc7 create checkMillis
e085711
parents: 62
diff changeset
466 readFully(b);
5fca2bb52dc7 create checkMillis
e085711
parents: 62
diff changeset
467 }
5fca2bb52dc7 create checkMillis
e085711
parents: 62
diff changeset
468
77
fe5925bb9a7e modify MyRfb.java
e085711
parents: 76
diff changeset
469 void startSpeedCheck() {
90
462bca4c8cec ByteBuffer
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 88
diff changeset
470 ByteBuffer b = ByteBuffer.allocate(10);
462bca4c8cec ByteBuffer
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 88
diff changeset
471 b.put((byte)SpeedCheckMillis);
462bca4c8cec ByteBuffer
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 88
diff changeset
472 b.flip();
66
7632606406cb create sendCheckMillis
e085711
parents: 65
diff changeset
473 startCheckTime = System.currentTimeMillis();
7632606406cb create sendCheckMillis
e085711
parents: 65
diff changeset
474 System.out.println("startChckTime = "+ startCheckTime);
90
462bca4c8cec ByteBuffer
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 88
diff changeset
475 LinkedList<ByteBuffer>bufs = new LinkedList<ByteBuffer>();
84
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
476 bufs.add(b);
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
477 multicastqueue.put(bufs);
65
5fca2bb52dc7 create checkMillis
e085711
parents: 62
diff changeset
478 }
5fca2bb52dc7 create checkMillis
e085711
parents: 62
diff changeset
479
77
fe5925bb9a7e modify MyRfb.java
e085711
parents: 76
diff changeset
480 void endSpeedCheck() {
65
5fca2bb52dc7 create checkMillis
e085711
parents: 62
diff changeset
481 long accTime = System.currentTimeMillis();
5fca2bb52dc7 create checkMillis
e085711
parents: 62
diff changeset
482 long time = accTime - startCheckTime;
5fca2bb52dc7 create checkMillis
e085711
parents: 62
diff changeset
483 System.out.println("checkMillis: " + time);
5fca2bb52dc7 create checkMillis
e085711
parents: 62
diff changeset
484 }
5fca2bb52dc7 create checkMillis
e085711
parents: 62
diff changeset
485
5fca2bb52dc7 create checkMillis
e085711
parents: 62
diff changeset
486 void printStatus() {
5fca2bb52dc7 create checkMillis
e085711
parents: 62
diff changeset
487 System.out.println();
5fca2bb52dc7 create checkMillis
e085711
parents: 62
diff changeset
488 }
5fca2bb52dc7 create checkMillis
e085711
parents: 62
diff changeset
489
5fca2bb52dc7 create checkMillis
e085711
parents: 62
diff changeset
490 synchronized void changeStatusFlag() {
5fca2bb52dc7 create checkMillis
e085711
parents: 62
diff changeset
491 printStatusFlag = true;
5fca2bb52dc7 create checkMillis
e085711
parents: 62
diff changeset
492 }
5fca2bb52dc7 create checkMillis
e085711
parents: 62
diff changeset
493
5fca2bb52dc7 create checkMillis
e085711
parents: 62
diff changeset
494 void printMills() {
5fca2bb52dc7 create checkMillis
e085711
parents: 62
diff changeset
495 if(printStatusFlag) {
5fca2bb52dc7 create checkMillis
e085711
parents: 62
diff changeset
496
5fca2bb52dc7 create checkMillis
e085711
parents: 62
diff changeset
497 changeStatusFlag();
5fca2bb52dc7 create checkMillis
e085711
parents: 62
diff changeset
498 } else {
5fca2bb52dc7 create checkMillis
e085711
parents: 62
diff changeset
499 changeStatusFlag();
5fca2bb52dc7 create checkMillis
e085711
parents: 62
diff changeset
500 }
5fca2bb52dc7 create checkMillis
e085711
parents: 62
diff changeset
501 }
87
a8c33757ac99 refactoring zip/unzip
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 86
diff changeset
502
a8c33757ac99 refactoring zip/unzip
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 86
diff changeset
503 void speedCheckMillis() {
a8c33757ac99 refactoring zip/unzip
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 86
diff changeset
504 Runnable stdin = new Runnable() {
a8c33757ac99 refactoring zip/unzip
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 86
diff changeset
505 public void run() {
a8c33757ac99 refactoring zip/unzip
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 86
diff changeset
506 int c;
a8c33757ac99 refactoring zip/unzip
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 86
diff changeset
507 try {
a8c33757ac99 refactoring zip/unzip
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 86
diff changeset
508 while( (c = System.in.read()) != -1 ) {
a8c33757ac99 refactoring zip/unzip
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 86
diff changeset
509 switch(c) {
a8c33757ac99 refactoring zip/unzip
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 86
diff changeset
510 case 's':
a8c33757ac99 refactoring zip/unzip
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 86
diff changeset
511 break;
a8c33757ac99 refactoring zip/unzip
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 86
diff changeset
512 default:
a8c33757ac99 refactoring zip/unzip
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 86
diff changeset
513 startSpeedCheck();
a8c33757ac99 refactoring zip/unzip
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 86
diff changeset
514 break;
a8c33757ac99 refactoring zip/unzip
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 86
diff changeset
515 }
a8c33757ac99 refactoring zip/unzip
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 86
diff changeset
516 }
a8c33757ac99 refactoring zip/unzip
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 86
diff changeset
517 }catch(IOException e){
a8c33757ac99 refactoring zip/unzip
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 86
diff changeset
518 System.out.println(e);
a8c33757ac99 refactoring zip/unzip
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 86
diff changeset
519 }
a8c33757ac99 refactoring zip/unzip
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 86
diff changeset
520 }
a8c33757ac99 refactoring zip/unzip
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 86
diff changeset
521 };
a8c33757ac99 refactoring zip/unzip
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 86
diff changeset
522
a8c33757ac99 refactoring zip/unzip
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 86
diff changeset
523 new Thread(stdin).start();
a8c33757ac99 refactoring zip/unzip
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 86
diff changeset
524 }
86
b7225991184b refactor for tests
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 85
diff changeset
525
87
a8c33757ac99 refactoring zip/unzip
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 86
diff changeset
526 /**
a8c33757ac99 refactoring zip/unzip
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 86
diff changeset
527 * gzip byte arrays
a8c33757ac99 refactoring zip/unzip
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 86
diff changeset
528 * @param deflater
a8c33757ac99 refactoring zip/unzip
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 86
diff changeset
529 * @param inputs
a8c33757ac99 refactoring zip/unzip
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 86
diff changeset
530 * byte data[]
96
f0790bcf000d fix concurrent modification
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 95
diff changeset
531 * @param inputIndex
87
a8c33757ac99 refactoring zip/unzip
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 86
diff changeset
532 * @param outputs
a8c33757ac99 refactoring zip/unzip
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 86
diff changeset
533 * byte data[]
a8c33757ac99 refactoring zip/unzip
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 86
diff changeset
534 * @return byte length in last byte array
a8c33757ac99 refactoring zip/unzip
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 86
diff changeset
535 * @throws IOException
a8c33757ac99 refactoring zip/unzip
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 86
diff changeset
536 */
96
f0790bcf000d fix concurrent modification
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 95
diff changeset
537 public int zip(Deflater deflater,LinkedList<ByteBuffer> inputs, int inputIndex, LinkedList<ByteBuffer> outputs) throws IOException {
90
462bca4c8cec ByteBuffer
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 88
diff changeset
538 int len1=0,len = 0;
98
3db7ac2b10f7 JUnit test passed, but VNC stopped.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 97
diff changeset
539 ByteBuffer c1= ByteBuffer.allocate(INFLATE_BUFSIZE);
3db7ac2b10f7 JUnit test passed, but VNC stopped.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 97
diff changeset
540 while(inputIndex < inputs.size() ) {
96
f0790bcf000d fix concurrent modification
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 95
diff changeset
541 ByteBuffer b1 = inputs.get(inputIndex++);
98
3db7ac2b10f7 JUnit test passed, but VNC stopped.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 97
diff changeset
542 deflater.setInput(b1.array(),b1.position(),b1.remaining());
97
145506601e0d minor comment
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 96
diff changeset
543 if (inputIndex==inputs.size()) {
86
b7225991184b refactor for tests
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 85
diff changeset
544 deflater.finish();
90
462bca4c8cec ByteBuffer
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 88
diff changeset
545 }
86
b7225991184b refactor for tests
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 85
diff changeset
546 do {
98
3db7ac2b10f7 JUnit test passed, but VNC stopped.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 97
diff changeset
547 len1 = deflater.deflate(c1.array(),c1.position(),c1.remaining());
3db7ac2b10f7 JUnit test passed, but VNC stopped.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 97
diff changeset
548 if (len1<=0) break; // get next buffer
3db7ac2b10f7 JUnit test passed, but VNC stopped.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 97
diff changeset
549 len += len1;
3db7ac2b10f7 JUnit test passed, but VNC stopped.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 97
diff changeset
550 c1.position(c1.position()+len1);
3db7ac2b10f7 JUnit test passed, but VNC stopped.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 97
diff changeset
551 if (c1.remaining()==0) {
3db7ac2b10f7 JUnit test passed, but VNC stopped.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 97
diff changeset
552 c1.flip();
86
b7225991184b refactor for tests
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 85
diff changeset
553 outputs.addLast(c1);
98
3db7ac2b10f7 JUnit test passed, but VNC stopped.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 97
diff changeset
554 c1 = ByteBuffer.allocate(INFLATE_BUFSIZE);
86
b7225991184b refactor for tests
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 85
diff changeset
555 }
98
3db7ac2b10f7 JUnit test passed, but VNC stopped.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 97
diff changeset
556 } while (!deflater.finished());
3db7ac2b10f7 JUnit test passed, but VNC stopped.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 97
diff changeset
557 }
3db7ac2b10f7 JUnit test passed, but VNC stopped.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 97
diff changeset
558 if (c1.position()!=0) {
3db7ac2b10f7 JUnit test passed, but VNC stopped.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 97
diff changeset
559 c1.flip();
3db7ac2b10f7 JUnit test passed, but VNC stopped.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 97
diff changeset
560 outputs.addLast(c1);
3db7ac2b10f7 JUnit test passed, but VNC stopped.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 97
diff changeset
561 }
3db7ac2b10f7 JUnit test passed, but VNC stopped.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 97
diff changeset
562 deflater.reset();
90
462bca4c8cec ByteBuffer
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 88
diff changeset
563 return len;
86
b7225991184b refactor for tests
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 85
diff changeset
564 }
87
a8c33757ac99 refactoring zip/unzip
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 86
diff changeset
565
a8c33757ac99 refactoring zip/unzip
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 86
diff changeset
566 /**
a8c33757ac99 refactoring zip/unzip
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 86
diff changeset
567 * gunzip byte arrays
a8c33757ac99 refactoring zip/unzip
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 86
diff changeset
568 * @param inflater
a8c33757ac99 refactoring zip/unzip
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 86
diff changeset
569 * @param inputs
a8c33757ac99 refactoring zip/unzip
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 86
diff changeset
570 * byte data[]
a8c33757ac99 refactoring zip/unzip
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 86
diff changeset
571 * @param outputs
a8c33757ac99 refactoring zip/unzip
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 86
diff changeset
572 * byte data[]
91
4116c19cd76e unzip/zip test passed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 90
diff changeset
573 *@return number of total bytes
87
a8c33757ac99 refactoring zip/unzip
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 86
diff changeset
574 * @throws IOException
a8c33757ac99 refactoring zip/unzip
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 86
diff changeset
575 */
98
3db7ac2b10f7 JUnit test passed, but VNC stopped.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 97
diff changeset
576 public int unzip(Inflater inflater, LinkedList<ByteBuffer> inputs, int inputIndex, LinkedList<ByteBuffer> outputs)
88
9b3b1e3e7db5 add test routine
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
577 throws DataFormatException {
86
b7225991184b refactor for tests
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 85
diff changeset
578 int len=0,len0;
98
3db7ac2b10f7 JUnit test passed, but VNC stopped.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 97
diff changeset
579 ByteBuffer buf = ByteBuffer.allocate(INFLATE_BUFSIZE);
3db7ac2b10f7 JUnit test passed, but VNC stopped.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 97
diff changeset
580 // inflater.reset(); // if we uncomment this, test1() will be passed. But it won't work with real connection.
3db7ac2b10f7 JUnit test passed, but VNC stopped.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 97
diff changeset
581 while (inputIndex < inputs.size()) {
96
f0790bcf000d fix concurrent modification
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 95
diff changeset
582 ByteBuffer input = inputs.get(inputIndex++);
90
462bca4c8cec ByteBuffer
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 88
diff changeset
583 inflater.setInput(input.array(),0,input.limit());
88
9b3b1e3e7db5 add test routine
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
584 do {
98
3db7ac2b10f7 JUnit test passed, but VNC stopped.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 97
diff changeset
585 len0 = inflater.inflate(buf.array(),buf.position(),buf.remaining());
99
0c5762c3a8dd Test and VNC not working... Memory Overflow...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 98
diff changeset
586 if (len0<=0) break;
98
3db7ac2b10f7 JUnit test passed, but VNC stopped.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 97
diff changeset
587 buf.position(buf.position()+len0);
88
9b3b1e3e7db5 add test routine
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
588 len += len0;
98
3db7ac2b10f7 JUnit test passed, but VNC stopped.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 97
diff changeset
589 if (buf.remaining()==0) {
3db7ac2b10f7 JUnit test passed, but VNC stopped.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 97
diff changeset
590 buf.flip();
91
4116c19cd76e unzip/zip test passed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 90
diff changeset
591 outputs.addLast(buf);
98
3db7ac2b10f7 JUnit test passed, but VNC stopped.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 97
diff changeset
592 buf = ByteBuffer.allocate(INFLATE_BUFSIZE);
91
4116c19cd76e unzip/zip test passed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 90
diff changeset
593 }
98
3db7ac2b10f7 JUnit test passed, but VNC stopped.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 97
diff changeset
594 } while (!inflater.finished());
3db7ac2b10f7 JUnit test passed, but VNC stopped.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 97
diff changeset
595 }
3db7ac2b10f7 JUnit test passed, but VNC stopped.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 97
diff changeset
596 if (buf.position()!=0) {
3db7ac2b10f7 JUnit test passed, but VNC stopped.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 97
diff changeset
597 buf.flip();
3db7ac2b10f7 JUnit test passed, but VNC stopped.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 97
diff changeset
598 outputs.addLast(buf);
3db7ac2b10f7 JUnit test passed, but VNC stopped.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 97
diff changeset
599 }
99
0c5762c3a8dd Test and VNC not working... Memory Overflow...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 98
diff changeset
600 // inflater.reset(); // this make JUnit happy, but VNC won't happy with this
90
462bca4c8cec ByteBuffer
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 88
diff changeset
601 return len;
86
b7225991184b refactor for tests
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 85
diff changeset
602 }
65
5fca2bb52dc7 create checkMillis
e085711
parents: 62
diff changeset
603
86
b7225991184b refactor for tests
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 85
diff changeset
604 void readSendData(int dataLen) throws IOException, DataFormatException {
90
462bca4c8cec ByteBuffer
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 88
diff changeset
605 LinkedList<ByteBuffer>bufs = new LinkedList<ByteBuffer>();
462bca4c8cec ByteBuffer
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 88
diff changeset
606 ByteBuffer header = ByteBuffer.allocate(16);
462bca4c8cec ByteBuffer
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 88
diff changeset
607 readFully(header.array(),0,16);
462bca4c8cec ByteBuffer
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 88
diff changeset
608 header.limit(16);
462bca4c8cec ByteBuffer
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 88
diff changeset
609 if (header.get(0)==RfbProto.FramebufferUpdate) {
462bca4c8cec ByteBuffer
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 88
diff changeset
610 int encoding = header.getInt(12);
86
b7225991184b refactor for tests
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 85
diff changeset
611 if (encoding==RfbProto.EncodingZlib||encoding==RfbProto.EncodingZRLE) {
90
462bca4c8cec ByteBuffer
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 88
diff changeset
612 ByteBuffer len = ByteBuffer.allocate(4);
462bca4c8cec ByteBuffer
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 88
diff changeset
613 readFully(len.array(),0,4); len.limit(4);
462bca4c8cec ByteBuffer
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 88
diff changeset
614 ByteBuffer inputData = ByteBuffer.allocate(dataLen-20);
462bca4c8cec ByteBuffer
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 88
diff changeset
615 readFully(inputData.array(),0,inputData.capacity()); inputData.limit(dataLen-20);
462bca4c8cec ByteBuffer
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 88
diff changeset
616 LinkedList<ByteBuffer>inputs = new LinkedList<ByteBuffer>();
88
9b3b1e3e7db5 add test routine
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
617 inputs.add(inputData);
98
3db7ac2b10f7 JUnit test passed, but VNC stopped.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 97
diff changeset
618 unzip(inflater, inputs, 0, bufs);
87
a8c33757ac99 refactoring zip/unzip
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 86
diff changeset
619 bufs.addFirst(header);
86
b7225991184b refactor for tests
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 85
diff changeset
620 multicastqueue.put(bufs);
b7225991184b refactor for tests
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 85
diff changeset
621 is.reset();
b7225991184b refactor for tests
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 85
diff changeset
622 return ;
b7225991184b refactor for tests
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 85
diff changeset
623 }
b7225991184b refactor for tests
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 85
diff changeset
624 }
87
a8c33757ac99 refactoring zip/unzip
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 86
diff changeset
625 bufs.add(header);
a8c33757ac99 refactoring zip/unzip
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 86
diff changeset
626 if (dataLen>16) {
90
462bca4c8cec ByteBuffer
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 88
diff changeset
627 ByteBuffer b = ByteBuffer.allocate(dataLen-16);
462bca4c8cec ByteBuffer
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 88
diff changeset
628 readFully(b.array(),0,dataLen-16); b.limit(dataLen-16);
87
a8c33757ac99 refactoring zip/unzip
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 86
diff changeset
629 bufs.add(b);
a8c33757ac99 refactoring zip/unzip
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 86
diff changeset
630 }
86
b7225991184b refactor for tests
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 85
diff changeset
631 multicastqueue.put(bufs);
b7225991184b refactor for tests
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 85
diff changeset
632 is.reset();
b7225991184b refactor for tests
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 85
diff changeset
633
b7225991184b refactor for tests
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 85
diff changeset
634 // It may be compressed. We can inflate here to avoid repeating clients decompressing here,
b7225991184b refactor for tests
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 85
diff changeset
635 // but it may generate too many large data. It is better to do it in each client.
b7225991184b refactor for tests
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 85
diff changeset
636 // But we have do inflation for all input data, so we have to do it here.
b7225991184b refactor for tests
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 85
diff changeset
637 }
43
08317224ce21 create RFB 003.998
e085711
parents: 40
diff changeset
638
71
bf5ac06df675 modify AcceptThread
e085711
parents: 67
diff changeset
639 void newClient(AcceptThread acceptThread, final Socket newCli,
54
796f2b3b8665 modify MyRfbProto.java
e085711
parents: 51
diff changeset
640 final OutputStream os, final InputStream is) throws IOException {
796f2b3b8665 modify MyRfbProto.java
e085711
parents: 51
diff changeset
641 // createBimgFlag = true;
796f2b3b8665 modify MyRfbProto.java
e085711
parents: 51
diff changeset
642 // rfb.addSockTmp(newCli);
796f2b3b8665 modify MyRfbProto.java
e085711
parents: 51
diff changeset
643 // addSock(newCli);
90
462bca4c8cec ByteBuffer
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 88
diff changeset
644 final Client <LinkedList<ByteBuffer>> c = multicastqueue.newClient();
54
796f2b3b8665 modify MyRfbProto.java
e085711
parents: 51
diff changeset
645 Runnable sender = new Runnable() {
796f2b3b8665 modify MyRfbProto.java
e085711
parents: 51
diff changeset
646 public void run() {
80
712a047908df recompress output
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 78
diff changeset
647
100
ae4df9b07805 Test passed. VNC partial draw on ZRE.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 99
diff changeset
648 Deflater deflater = new Deflater();
54
796f2b3b8665 modify MyRfbProto.java
e085711
parents: 51
diff changeset
649 try {
65
5fca2bb52dc7 create checkMillis
e085711
parents: 62
diff changeset
650 /**
5fca2bb52dc7 create checkMillis
e085711
parents: 62
diff changeset
651 * initial connection of RFB protocol
5fca2bb52dc7 create checkMillis
e085711
parents: 62
diff changeset
652 */
54
796f2b3b8665 modify MyRfbProto.java
e085711
parents: 51
diff changeset
653 sendRfbVersion(os);
796f2b3b8665 modify MyRfbProto.java
e085711
parents: 51
diff changeset
654 readVersionMsg(is);
796f2b3b8665 modify MyRfbProto.java
e085711
parents: 51
diff changeset
655 sendSecurityType(os);
796f2b3b8665 modify MyRfbProto.java
e085711
parents: 51
diff changeset
656 readSecType(is);
796f2b3b8665 modify MyRfbProto.java
e085711
parents: 51
diff changeset
657 sendSecResult(os);
796f2b3b8665 modify MyRfbProto.java
e085711
parents: 51
diff changeset
658 readClientInit(is);
796f2b3b8665 modify MyRfbProto.java
e085711
parents: 51
diff changeset
659 sendInitData(os);
43
08317224ce21 create RFB 003.998
e085711
parents: 40
diff changeset
660
96
f0790bcf000d fix concurrent modification
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 95
diff changeset
661 Runnable reader = new Runnable() {
f0790bcf000d fix concurrent modification
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 95
diff changeset
662 public void run() {
f0790bcf000d fix concurrent modification
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 95
diff changeset
663 byte b[] = new byte[4096];
f0790bcf000d fix concurrent modification
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 95
diff changeset
664 for(;;) {
f0790bcf000d fix concurrent modification
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 95
diff changeset
665 try {
f0790bcf000d fix concurrent modification
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 95
diff changeset
666 int c = is.read(b);
f0790bcf000d fix concurrent modification
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 95
diff changeset
667 if (c<=0) throw new IOException();
f0790bcf000d fix concurrent modification
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 95
diff changeset
668 System.out.println("client read "+c);
f0790bcf000d fix concurrent modification
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 95
diff changeset
669 } catch (IOException e) {
f0790bcf000d fix concurrent modification
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 95
diff changeset
670 try {
f0790bcf000d fix concurrent modification
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 95
diff changeset
671 os.close();
f0790bcf000d fix concurrent modification
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 95
diff changeset
672 is.close();
f0790bcf000d fix concurrent modification
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 95
diff changeset
673 } catch (IOException e1) {
f0790bcf000d fix concurrent modification
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 95
diff changeset
674 }
f0790bcf000d fix concurrent modification
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 95
diff changeset
675 return;
f0790bcf000d fix concurrent modification
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 95
diff changeset
676 }
f0790bcf000d fix concurrent modification
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 95
diff changeset
677 }
f0790bcf000d fix concurrent modification
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 95
diff changeset
678 }
f0790bcf000d fix concurrent modification
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 95
diff changeset
679 };
f0790bcf000d fix concurrent modification
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 95
diff changeset
680 new Thread(reader).start();
f0790bcf000d fix concurrent modification
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 95
diff changeset
681
54
796f2b3b8665 modify MyRfbProto.java
e085711
parents: 51
diff changeset
682 for (;;) {
90
462bca4c8cec ByteBuffer
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 88
diff changeset
683 LinkedList<ByteBuffer> bufs = c.poll();
96
f0790bcf000d fix concurrent modification
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 95
diff changeset
684 int inputIndex = 0;
f0790bcf000d fix concurrent modification
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 95
diff changeset
685 ByteBuffer header = bufs.get(inputIndex++);
f0790bcf000d fix concurrent modification
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 95
diff changeset
686 if (header==null) continue;
90
462bca4c8cec ByteBuffer
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 88
diff changeset
687 if (header.get(0)==RfbProto.FramebufferUpdate) {
96
f0790bcf000d fix concurrent modification
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 95
diff changeset
688 System.out.println("client "+ clients);
90
462bca4c8cec ByteBuffer
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 88
diff changeset
689 int encoding = header.getInt(12);
80
712a047908df recompress output
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 78
diff changeset
690 if (encoding==RfbProto.EncodingZlib||encoding==RfbProto.EncodingZRLE) {
90
462bca4c8cec ByteBuffer
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 88
diff changeset
691 LinkedList<ByteBuffer> outs = new LinkedList<ByteBuffer>();
96
f0790bcf000d fix concurrent modification
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 95
diff changeset
692 int len2 = zip(deflater, bufs, inputIndex, outs);
90
462bca4c8cec ByteBuffer
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 88
diff changeset
693 ByteBuffer blen = ByteBuffer.allocate(4); blen.putInt(len2); blen.flip();
462bca4c8cec ByteBuffer
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 88
diff changeset
694 outs.addFirst(blen);
87
a8c33757ac99 refactoring zip/unzip
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 86
diff changeset
695 outs.addFirst(header);
86
b7225991184b refactor for tests
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 85
diff changeset
696 while(!outs.isEmpty()) {
90
462bca4c8cec ByteBuffer
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 88
diff changeset
697 ByteBuffer out= outs.poll();
462bca4c8cec ByteBuffer
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 88
diff changeset
698 os.write(out.array(),out.position(),out.limit());
84
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
699 }
80
712a047908df recompress output
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 78
diff changeset
700 }
87
a8c33757ac99 refactoring zip/unzip
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 86
diff changeset
701 os.flush();
95
285dd4d6dacf gziped partial drawing.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 94
diff changeset
702 continue;
87
a8c33757ac99 refactoring zip/unzip
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 86
diff changeset
703 }
90
462bca4c8cec ByteBuffer
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 88
diff changeset
704 os.write(header.array(),header.position(),header.limit());
96
f0790bcf000d fix concurrent modification
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 95
diff changeset
705 while(inputIndex < bufs.size()) {
f0790bcf000d fix concurrent modification
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 95
diff changeset
706 ByteBuffer b = bufs.get(inputIndex++);
90
462bca4c8cec ByteBuffer
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 88
diff changeset
707 os.write(b.array(), b.position(), b.limit());
84
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 83
diff changeset
708 }
85
b384db76c28a a little progress...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 84
diff changeset
709 os.flush();
54
796f2b3b8665 modify MyRfbProto.java
e085711
parents: 51
diff changeset
710 }
796f2b3b8665 modify MyRfbProto.java
e085711
parents: 51
diff changeset
711 } catch (IOException e) {
96
f0790bcf000d fix concurrent modification
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 95
diff changeset
712 try {
f0790bcf000d fix concurrent modification
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 95
diff changeset
713 os.close();
f0790bcf000d fix concurrent modification
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 95
diff changeset
714 } catch (IOException e1) {
f0790bcf000d fix concurrent modification
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 95
diff changeset
715 }
87
a8c33757ac99 refactoring zip/unzip
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 86
diff changeset
716 /* if socket closed cliList.remove(newCli); */
54
796f2b3b8665 modify MyRfbProto.java
e085711
parents: 51
diff changeset
717 }
796f2b3b8665 modify MyRfbProto.java
e085711
parents: 51
diff changeset
718 }
796f2b3b8665 modify MyRfbProto.java
e085711
parents: 51
diff changeset
719 };
80
712a047908df recompress output
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 78
diff changeset
720 clients++;
54
796f2b3b8665 modify MyRfbProto.java
e085711
parents: 51
diff changeset
721 new Thread(sender).start();
796f2b3b8665 modify MyRfbProto.java
e085711
parents: 51
diff changeset
722
796f2b3b8665 modify MyRfbProto.java
e085711
parents: 51
diff changeset
723 }
66
7632606406cb create sendCheckMillis
e085711
parents: 65
diff changeset
724
7632606406cb create sendCheckMillis
e085711
parents: 65
diff changeset
725
88
9b3b1e3e7db5 add test routine
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
726
9b3b1e3e7db5 add test routine
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
727 @Test
9b3b1e3e7db5 add test routine
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
728 public void test1() {
9b3b1e3e7db5 add test routine
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
729 try {
90
462bca4c8cec ByteBuffer
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 88
diff changeset
730 LinkedList<ByteBuffer> in = new LinkedList<ByteBuffer>();
462bca4c8cec ByteBuffer
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 88
diff changeset
731 LinkedList<ByteBuffer> out = new LinkedList<ByteBuffer>();
462bca4c8cec ByteBuffer
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 88
diff changeset
732 LinkedList<ByteBuffer> out2 = new LinkedList<ByteBuffer>();
88
9b3b1e3e7db5 add test routine
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
733 for(int i=0;i<10;i++) {
90
462bca4c8cec ByteBuffer
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 88
diff changeset
734 in.add(ByteBuffer.wrap("test1".getBytes()));
462bca4c8cec ByteBuffer
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 88
diff changeset
735 in.add(ByteBuffer.wrap("test2".getBytes()));
462bca4c8cec ByteBuffer
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 88
diff changeset
736 in.add(ByteBuffer.wrap("test3".getBytes()));
462bca4c8cec ByteBuffer
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 88
diff changeset
737 in.add(ByteBuffer.wrap("test4".getBytes()));
88
9b3b1e3e7db5 add test routine
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
738 }
92
aa7df396e04d Test on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
739 LinkedList<ByteBuffer> in1 = clone(in);
90
462bca4c8cec ByteBuffer
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 88
diff changeset
740
88
9b3b1e3e7db5 add test routine
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
741 Deflater deflater = new Deflater();
96
f0790bcf000d fix concurrent modification
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 95
diff changeset
742 zip(deflater,in,0,out);
92
aa7df396e04d Test on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
743 // LinkedList<ByteBuffer> out3 = clone(out); zipped result is depend on deflator's state
98
3db7ac2b10f7 JUnit test passed, but VNC stopped.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 97
diff changeset
744 unzip(inflater, out, 0,out2);
99
0c5762c3a8dd Test and VNC not working... Memory Overflow...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 98
diff changeset
745 inflater.reset();
92
aa7df396e04d Test on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
746 equalByteBuffers(in1, out2);
aa7df396e04d Test on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
747 LinkedList<ByteBuffer> out4 = new LinkedList<ByteBuffer>();
96
f0790bcf000d fix concurrent modification
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 95
diff changeset
748 zip(deflater,out2,0,out4);
92
aa7df396e04d Test on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
749 LinkedList<ByteBuffer> out5 = new LinkedList<ByteBuffer>();
98
3db7ac2b10f7 JUnit test passed, but VNC stopped.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 97
diff changeset
750 unzip(inflater,out4,0, out5);
99
0c5762c3a8dd Test and VNC not working... Memory Overflow...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 98
diff changeset
751 int len = equalByteBuffers(in1,out5);
92
aa7df396e04d Test on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
752
99
0c5762c3a8dd Test and VNC not working... Memory Overflow...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 98
diff changeset
753 System.out.println("Test Ok. "+len);
88
9b3b1e3e7db5 add test routine
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
754 } catch (Exception e) {
9b3b1e3e7db5 add test routine
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
755 assertEquals(0,1);
9b3b1e3e7db5 add test routine
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
756 }
9b3b1e3e7db5 add test routine
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
757 }
9b3b1e3e7db5 add test routine
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 87
diff changeset
758
92
aa7df396e04d Test on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
759 private LinkedList<ByteBuffer> clone(LinkedList<ByteBuffer> in) {
aa7df396e04d Test on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
760 LinkedList<ByteBuffer> copy = new LinkedList<ByteBuffer>();
aa7df396e04d Test on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
761 for(ByteBuffer b: in) {
aa7df396e04d Test on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
762 ByteBuffer c = b.duplicate();
aa7df396e04d Test on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
763 copy.add(c);
aa7df396e04d Test on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
764 }
aa7df396e04d Test on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
765 return copy;
aa7df396e04d Test on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
766 }
aa7df396e04d Test on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
767
93
40c22e507655 unzip/zip Test passed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 92
diff changeset
768
40c22e507655 unzip/zip Test passed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 92
diff changeset
769
99
0c5762c3a8dd Test and VNC not working... Memory Overflow...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 98
diff changeset
770 public int equalByteBuffers(LinkedList<ByteBuffer> in,
92
aa7df396e04d Test on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
771 LinkedList<ByteBuffer> out2) {
99
0c5762c3a8dd Test and VNC not working... Memory Overflow...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 98
diff changeset
772 int len = 0;
93
40c22e507655 unzip/zip Test passed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 92
diff changeset
773 Iterable<Byte> i = byteBufferIterator(in);
40c22e507655 unzip/zip Test passed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 92
diff changeset
774 Iterator<Byte> o = byteBufferIterator(out2).iterator();
40c22e507655 unzip/zip Test passed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 92
diff changeset
775
40c22e507655 unzip/zip Test passed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 92
diff changeset
776 for(int b: i) {
99
0c5762c3a8dd Test and VNC not working... Memory Overflow...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 98
diff changeset
777 len ++;
93
40c22e507655 unzip/zip Test passed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 92
diff changeset
778 if (o.hasNext()) {
40c22e507655 unzip/zip Test passed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 92
diff changeset
779 int c = o.next();
40c22e507655 unzip/zip Test passed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 92
diff changeset
780 assertEquals(b,c);
40c22e507655 unzip/zip Test passed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 92
diff changeset
781 } else
40c22e507655 unzip/zip Test passed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 92
diff changeset
782 assertEquals(0,1);
40c22e507655 unzip/zip Test passed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 92
diff changeset
783 }
40c22e507655 unzip/zip Test passed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 92
diff changeset
784 if (o.hasNext()) assertEquals(0,1);
40c22e507655 unzip/zip Test passed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 92
diff changeset
785 // System.out.println();
99
0c5762c3a8dd Test and VNC not working... Memory Overflow...
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 98
diff changeset
786 return len;
93
40c22e507655 unzip/zip Test passed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 92
diff changeset
787 }
40c22e507655 unzip/zip Test passed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 92
diff changeset
788
40c22e507655 unzip/zip Test passed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 92
diff changeset
789 private Iterable<Byte> byteBufferIterator(final LinkedList<ByteBuffer> in) {
40c22e507655 unzip/zip Test passed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 92
diff changeset
790 return new Iterable<Byte>() {
40c22e507655 unzip/zip Test passed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 92
diff changeset
791 public Iterator<Byte> iterator() {
40c22e507655 unzip/zip Test passed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 92
diff changeset
792 return new Iterator<Byte>() {
40c22e507655 unzip/zip Test passed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 92
diff changeset
793 int bytes = 0;
40c22e507655 unzip/zip Test passed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 92
diff changeset
794 int buffers = 0;
40c22e507655 unzip/zip Test passed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 92
diff changeset
795 public boolean hasNext() {
40c22e507655 unzip/zip Test passed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 92
diff changeset
796 if (buffers>=in.size()) return false;
40c22e507655 unzip/zip Test passed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 92
diff changeset
797 ByteBuffer b = in.getFirst();
40c22e507655 unzip/zip Test passed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 92
diff changeset
798 return bytes<b.remaining();
92
aa7df396e04d Test on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
799 }
93
40c22e507655 unzip/zip Test passed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 92
diff changeset
800 public Byte next() {
40c22e507655 unzip/zip Test passed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 92
diff changeset
801 ByteBuffer bf =in.get(buffers);
40c22e507655 unzip/zip Test passed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 92
diff changeset
802 byte b = bf.get(bytes++);
40c22e507655 unzip/zip Test passed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 92
diff changeset
803 if (bf.remaining()<=bytes) {
40c22e507655 unzip/zip Test passed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 92
diff changeset
804 buffers++;
40c22e507655 unzip/zip Test passed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 92
diff changeset
805 bytes = 0;
40c22e507655 unzip/zip Test passed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 92
diff changeset
806 }
40c22e507655 unzip/zip Test passed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 92
diff changeset
807 // System.out.print(b);
40c22e507655 unzip/zip Test passed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 92
diff changeset
808 return b;
40c22e507655 unzip/zip Test passed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 92
diff changeset
809 }
40c22e507655 unzip/zip Test passed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 92
diff changeset
810 public void remove() {
40c22e507655 unzip/zip Test passed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 92
diff changeset
811 }
40c22e507655 unzip/zip Test passed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 92
diff changeset
812 };
92
aa7df396e04d Test on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
813 }
93
40c22e507655 unzip/zip Test passed.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 92
diff changeset
814 };
92
aa7df396e04d Test on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
815 }
aa7df396e04d Test on going
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 91
diff changeset
816
54
796f2b3b8665 modify MyRfbProto.java
e085711
parents: 51
diff changeset
817 }
66
7632606406cb create sendCheckMillis
e085711
parents: 65
diff changeset
818
7632606406cb create sendCheckMillis
e085711
parents: 65
diff changeset
819