annotate src/myVncProxy/MyRfbProto.java @ 109:3f73ebf918bd

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