annotate src/myVncProxy/MyRfbProto.java @ 122:2ff8d5a226c9

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