annotate src/myVncProxy/MyRfbProto.java @ 94:b551b7af0a8a

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