annotate src/myVncProxy/MyRfbProto.java @ 92:aa7df396e04d

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