annotate src/myVncProxy/MyRfbProto.java @ 86:b7225991184b

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