annotate src/myVncProxy/MyRfbProto.java @ 39:f399eec66846

send data:multi thread
author e085711
date Sun, 05 Jun 2011 22:30:46 +0900
parents 84c02a9ce3ea
children dd1321b67f95
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;
25
cded9fd297ab create png data
e085711
parents: 24
diff changeset
2 import java.awt.Graphics;
cded9fd297ab create png data
e085711
parents: 24
diff changeset
3 import java.awt.Image;
cded9fd297ab create png data
e085711
parents: 24
diff changeset
4 import java.awt.image.BufferedImage;
cded9fd297ab create png data
e085711
parents: 24
diff changeset
5 import java.io.BufferedOutputStream;
15
89e1c5f84407 faile ZRLE encode. success raw encode.
e085711
parents: 13
diff changeset
6 import java.io.BufferedReader;
25
cded9fd297ab create png data
e085711
parents: 24
diff changeset
7 import java.io.ByteArrayInputStream;
cded9fd297ab create png data
e085711
parents: 24
diff changeset
8 import java.io.ByteArrayOutputStream;
10
2840c7a259f1 add acceptThread
e085711
parents:
diff changeset
9 import java.io.IOException;
15
89e1c5f84407 faile ZRLE encode. success raw encode.
e085711
parents: 13
diff changeset
10 import java.io.InputStreamReader;
23
b51bb7bc0766 test update
e085711
parents: 20
diff changeset
11 import java.net.BindException;
10
2840c7a259f1 add acceptThread
e085711
parents:
diff changeset
12 import java.net.ServerSocket;
2840c7a259f1 add acceptThread
e085711
parents:
diff changeset
13 import java.net.Socket;
25
cded9fd297ab create png data
e085711
parents: 24
diff changeset
14 import java.nio.ByteBuffer;
10
2840c7a259f1 add acceptThread
e085711
parents:
diff changeset
15 import java.util.LinkedList;
2840c7a259f1 add acceptThread
e085711
parents:
diff changeset
16
25
cded9fd297ab create png data
e085711
parents: 24
diff changeset
17 import javax.imageio.ImageIO;
cded9fd297ab create png data
e085711
parents: 24
diff changeset
18
39
f399eec66846 send data:multi thread
e085711
parents: 38
diff changeset
19 import org.omg.CORBA.portable.OutputStream;
f399eec66846 send data:multi thread
e085711
parents: 38
diff changeset
20
10
2840c7a259f1 add acceptThread
e085711
parents:
diff changeset
21
2840c7a259f1 add acceptThread
e085711
parents:
diff changeset
22 class MyRfbProto extends RfbProto {
2840c7a259f1 add acceptThread
e085711
parents:
diff changeset
23
18
ccad9909e0e2 raw only version
e085711
parents: 17
diff changeset
24 private int messageType;
ccad9909e0e2 raw only version
e085711
parents: 17
diff changeset
25 private int rectangles;
23
b51bb7bc0766 test update
e085711
parents: 20
diff changeset
26 private int rectX;
b51bb7bc0766 test update
e085711
parents: 20
diff changeset
27 private int rectY;
b51bb7bc0766 test update
e085711
parents: 20
diff changeset
28 private int rectW;
b51bb7bc0766 test update
e085711
parents: 20
diff changeset
29 private int rectH;
18
ccad9909e0e2 raw only version
e085711
parents: 17
diff changeset
30 private int encoding;
27
13d4d3118cb8 create rfb.cliListTmp
e085711
parents: 26
diff changeset
31 private int zLen;
39
f399eec66846 send data:multi thread
e085711
parents: 38
diff changeset
32 private int dataLen;
18
ccad9909e0e2 raw only version
e085711
parents: 17
diff changeset
33
23
b51bb7bc0766 test update
e085711
parents: 20
diff changeset
34 private ServerSocket servSock;
b51bb7bc0766 test update
e085711
parents: 20
diff changeset
35 private int acceptPort;
10
2840c7a259f1 add acceptThread
e085711
parents:
diff changeset
36 private byte initData[];
27
13d4d3118cb8 create rfb.cliListTmp
e085711
parents: 26
diff changeset
37 private LinkedList <Socket> cliListTmp;
10
2840c7a259f1 add acceptThread
e085711
parents:
diff changeset
38 private LinkedList <Socket> cliList;
39
f399eec66846 send data:multi thread
e085711
parents: 38
diff changeset
39 private LinkedList <Thread> sendThreads;
27
13d4d3118cb8 create rfb.cliListTmp
e085711
parents: 26
diff changeset
40 boolean createBimgFlag;
10
2840c7a259f1 add acceptThread
e085711
parents:
diff changeset
41
25
cded9fd297ab create png data
e085711
parents: 24
diff changeset
42 byte[] pngBytes;
cded9fd297ab create png data
e085711
parents: 24
diff changeset
43
13
a5d73cafc8fe add ProxyVncCanvas and VncProxyService
e085711
parents: 10
diff changeset
44 MyRfbProto(String h, int p, VncViewer v ) throws IOException {
10
2840c7a259f1 add acceptThread
e085711
parents:
diff changeset
45 super(h, p, v);
2840c7a259f1 add acceptThread
e085711
parents:
diff changeset
46 cliList = new LinkedList <Socket>();
27
13d4d3118cb8 create rfb.cliListTmp
e085711
parents: 26
diff changeset
47 cliListTmp = new LinkedList <Socket>();
13d4d3118cb8 create rfb.cliListTmp
e085711
parents: 26
diff changeset
48 createBimgFlag = false;
39
f399eec66846 send data:multi thread
e085711
parents: 38
diff changeset
49 sendThreads = new LinkedList <Thread>();
10
2840c7a259f1 add acceptThread
e085711
parents:
diff changeset
50 }
2840c7a259f1 add acceptThread
e085711
parents:
diff changeset
51
13
a5d73cafc8fe add ProxyVncCanvas and VncProxyService
e085711
parents: 10
diff changeset
52 MyRfbProto(String h, int p) throws IOException {
a5d73cafc8fe add ProxyVncCanvas and VncProxyService
e085711
parents: 10
diff changeset
53 super(h, p);
a5d73cafc8fe add ProxyVncCanvas and VncProxyService
e085711
parents: 10
diff changeset
54 cliList = new LinkedList <Socket>();
27
13d4d3118cb8 create rfb.cliListTmp
e085711
parents: 26
diff changeset
55 cliListTmp = new LinkedList <Socket>();
13d4d3118cb8 create rfb.cliListTmp
e085711
parents: 26
diff changeset
56 createBimgFlag = false;
39
f399eec66846 send data:multi thread
e085711
parents: 38
diff changeset
57 sendThreads = new LinkedList <Thread>();
13
a5d73cafc8fe add ProxyVncCanvas and VncProxyService
e085711
parents: 10
diff changeset
58 }
24
87b29d6039a6 add package myVncProxy
e085711
parents: 23
diff changeset
59
10
2840c7a259f1 add acceptThread
e085711
parents:
diff changeset
60 void initServSock(int port) throws IOException{
2840c7a259f1 add acceptThread
e085711
parents:
diff changeset
61 servSock = new ServerSocket(port);
23
b51bb7bc0766 test update
e085711
parents: 20
diff changeset
62 acceptPort = port;
10
2840c7a259f1 add acceptThread
e085711
parents:
diff changeset
63 }
23
b51bb7bc0766 test update
e085711
parents: 20
diff changeset
64 void selectPort(){
b51bb7bc0766 test update
e085711
parents: 20
diff changeset
65 int i = 5550;
b51bb7bc0766 test update
e085711
parents: 20
diff changeset
66 while(true){
b51bb7bc0766 test update
e085711
parents: 20
diff changeset
67 try{
b51bb7bc0766 test update
e085711
parents: 20
diff changeset
68 initServSock(i);
b51bb7bc0766 test update
e085711
parents: 20
diff changeset
69 break;
b51bb7bc0766 test update
e085711
parents: 20
diff changeset
70 }catch(BindException e){
b51bb7bc0766 test update
e085711
parents: 20
diff changeset
71 i++;
b51bb7bc0766 test update
e085711
parents: 20
diff changeset
72 continue;
b51bb7bc0766 test update
e085711
parents: 20
diff changeset
73 }catch(IOException e){
10
2840c7a259f1 add acceptThread
e085711
parents:
diff changeset
74
23
b51bb7bc0766 test update
e085711
parents: 20
diff changeset
75 }
b51bb7bc0766 test update
e085711
parents: 20
diff changeset
76 }
28
2fd55d934ffa print accept port
e085711
parents: 27
diff changeset
77 System.out.println("accept port = "+i);
23
b51bb7bc0766 test update
e085711
parents: 20
diff changeset
78 }
b51bb7bc0766 test update
e085711
parents: 20
diff changeset
79 int getAcceptPort(){
b51bb7bc0766 test update
e085711
parents: 20
diff changeset
80 return acceptPort;
b51bb7bc0766 test update
e085711
parents: 20
diff changeset
81 }
10
2840c7a259f1 add acceptThread
e085711
parents:
diff changeset
82 void setSoTimeout(int num) throws IOException {
2840c7a259f1 add acceptThread
e085711
parents:
diff changeset
83 servSock.setSoTimeout(num);
2840c7a259f1 add acceptThread
e085711
parents:
diff changeset
84 }
2840c7a259f1 add acceptThread
e085711
parents:
diff changeset
85
2840c7a259f1 add acceptThread
e085711
parents:
diff changeset
86 Socket accept() throws IOException {
2840c7a259f1 add acceptThread
e085711
parents:
diff changeset
87 return servSock.accept();
2840c7a259f1 add acceptThread
e085711
parents:
diff changeset
88 }
2840c7a259f1 add acceptThread
e085711
parents:
diff changeset
89
2840c7a259f1 add acceptThread
e085711
parents:
diff changeset
90 void addSock(Socket sock){
2840c7a259f1 add acceptThread
e085711
parents:
diff changeset
91 cliList.add(sock);
2840c7a259f1 add acceptThread
e085711
parents:
diff changeset
92 }
27
13d4d3118cb8 create rfb.cliListTmp
e085711
parents: 26
diff changeset
93 void addSockTmp(Socket sock){
30
a0e1fc94d344 print out html file's text
e085711
parents: 28
diff changeset
94 System.out.println("connected "+sock.getInetAddress());
27
13d4d3118cb8 create rfb.cliListTmp
e085711
parents: 26
diff changeset
95 cliListTmp.add(sock);
13d4d3118cb8 create rfb.cliListTmp
e085711
parents: 26
diff changeset
96 }
10
2840c7a259f1 add acceptThread
e085711
parents:
diff changeset
97
2840c7a259f1 add acceptThread
e085711
parents:
diff changeset
98 void mark(int len) throws IOException {
2840c7a259f1 add acceptThread
e085711
parents:
diff changeset
99 is.mark(len);
2840c7a259f1 add acceptThread
e085711
parents:
diff changeset
100 }
2840c7a259f1 add acceptThread
e085711
parents:
diff changeset
101
2840c7a259f1 add acceptThread
e085711
parents:
diff changeset
102 void reset() throws IOException {
2840c7a259f1 add acceptThread
e085711
parents:
diff changeset
103 is.reset();
18
ccad9909e0e2 raw only version
e085711
parents: 17
diff changeset
104 }
10
2840c7a259f1 add acceptThread
e085711
parents:
diff changeset
105
2840c7a259f1 add acceptThread
e085711
parents:
diff changeset
106 boolean markSupported() {
2840c7a259f1 add acceptThread
e085711
parents:
diff changeset
107 return is.markSupported();
2840c7a259f1 add acceptThread
e085711
parents:
diff changeset
108 }
2840c7a259f1 add acceptThread
e085711
parents:
diff changeset
109
2840c7a259f1 add acceptThread
e085711
parents:
diff changeset
110 void readServerInit() throws IOException {
2840c7a259f1 add acceptThread
e085711
parents:
diff changeset
111
2840c7a259f1 add acceptThread
e085711
parents:
diff changeset
112 mark(255);
2840c7a259f1 add acceptThread
e085711
parents:
diff changeset
113 skipBytes(20);
2840c7a259f1 add acceptThread
e085711
parents:
diff changeset
114 int nlen = readU32();
2840c7a259f1 add acceptThread
e085711
parents:
diff changeset
115 int blen = 20+4+nlen;
2840c7a259f1 add acceptThread
e085711
parents:
diff changeset
116 initData = new byte[blen];
2840c7a259f1 add acceptThread
e085711
parents:
diff changeset
117 reset();
2840c7a259f1 add acceptThread
e085711
parents:
diff changeset
118
2840c7a259f1 add acceptThread
e085711
parents:
diff changeset
119 mark(blen);
2840c7a259f1 add acceptThread
e085711
parents:
diff changeset
120 readFully(initData);
2840c7a259f1 add acceptThread
e085711
parents:
diff changeset
121 reset();
2840c7a259f1 add acceptThread
e085711
parents:
diff changeset
122
2840c7a259f1 add acceptThread
e085711
parents:
diff changeset
123 framebufferWidth = readU16();
2840c7a259f1 add acceptThread
e085711
parents:
diff changeset
124 framebufferHeight = readU16();
2840c7a259f1 add acceptThread
e085711
parents:
diff changeset
125 bitsPerPixel = readU8();
2840c7a259f1 add acceptThread
e085711
parents:
diff changeset
126 depth = readU8();
2840c7a259f1 add acceptThread
e085711
parents:
diff changeset
127 bigEndian = (readU8() != 0);
2840c7a259f1 add acceptThread
e085711
parents:
diff changeset
128 trueColour = (readU8() != 0);
2840c7a259f1 add acceptThread
e085711
parents:
diff changeset
129 redMax = readU16();
2840c7a259f1 add acceptThread
e085711
parents:
diff changeset
130 greenMax = readU16();
2840c7a259f1 add acceptThread
e085711
parents:
diff changeset
131 blueMax = readU16();
2840c7a259f1 add acceptThread
e085711
parents:
diff changeset
132 redShift = readU8();
2840c7a259f1 add acceptThread
e085711
parents:
diff changeset
133 greenShift = readU8();
2840c7a259f1 add acceptThread
e085711
parents:
diff changeset
134 blueShift = readU8();
2840c7a259f1 add acceptThread
e085711
parents:
diff changeset
135 byte[] pad = new byte[3];
2840c7a259f1 add acceptThread
e085711
parents:
diff changeset
136 readFully(pad);
2840c7a259f1 add acceptThread
e085711
parents:
diff changeset
137 int nameLength = readU32();
2840c7a259f1 add acceptThread
e085711
parents:
diff changeset
138 byte[] name = new byte[nameLength];
2840c7a259f1 add acceptThread
e085711
parents:
diff changeset
139 readFully(name);
2840c7a259f1 add acceptThread
e085711
parents:
diff changeset
140 desktopName = new String(name);
2840c7a259f1 add acceptThread
e085711
parents:
diff changeset
141
2840c7a259f1 add acceptThread
e085711
parents:
diff changeset
142 // Read interaction capabilities (TightVNC protocol extensions)
2840c7a259f1 add acceptThread
e085711
parents:
diff changeset
143 if (protocolTightVNC) {
2840c7a259f1 add acceptThread
e085711
parents:
diff changeset
144 int nServerMessageTypes = readU16();
2840c7a259f1 add acceptThread
e085711
parents:
diff changeset
145 int nClientMessageTypes = readU16();
2840c7a259f1 add acceptThread
e085711
parents:
diff changeset
146 int nEncodingTypes = readU16();
2840c7a259f1 add acceptThread
e085711
parents:
diff changeset
147 readU16();
2840c7a259f1 add acceptThread
e085711
parents:
diff changeset
148 readCapabilityList(serverMsgCaps, nServerMessageTypes);
2840c7a259f1 add acceptThread
e085711
parents:
diff changeset
149 readCapabilityList(clientMsgCaps, nClientMessageTypes);
2840c7a259f1 add acceptThread
e085711
parents:
diff changeset
150 readCapabilityList(encodingCaps, nEncodingTypes);
2840c7a259f1 add acceptThread
e085711
parents:
diff changeset
151 }
2840c7a259f1 add acceptThread
e085711
parents:
diff changeset
152
2840c7a259f1 add acceptThread
e085711
parents:
diff changeset
153 inNormalProtocol = true;
2840c7a259f1 add acceptThread
e085711
parents:
diff changeset
154 }
2840c7a259f1 add acceptThread
e085711
parents:
diff changeset
155
2840c7a259f1 add acceptThread
e085711
parents:
diff changeset
156 void sendInitData(Socket sock) throws IOException{
2840c7a259f1 add acceptThread
e085711
parents:
diff changeset
157 sock.getOutputStream().write(initData);
2840c7a259f1 add acceptThread
e085711
parents:
diff changeset
158 }
2840c7a259f1 add acceptThread
e085711
parents:
diff changeset
159
17
4eda2dbb7fef ProxyVncCanvas version 0.2
e085711
parents: 15
diff changeset
160 void sendData(byte b[]){
4eda2dbb7fef ProxyVncCanvas version 0.2
e085711
parents: 15
diff changeset
161 try{
4eda2dbb7fef ProxyVncCanvas version 0.2
e085711
parents: 15
diff changeset
162 for(Socket cli : cliList){
4eda2dbb7fef ProxyVncCanvas version 0.2
e085711
parents: 15
diff changeset
163 try{
4eda2dbb7fef ProxyVncCanvas version 0.2
e085711
parents: 15
diff changeset
164 cli.getOutputStream().write(b, 0, b.length);
4eda2dbb7fef ProxyVncCanvas version 0.2
e085711
parents: 15
diff changeset
165 }catch(IOException e){
4eda2dbb7fef ProxyVncCanvas version 0.2
e085711
parents: 15
diff changeset
166 // if socket closed
4eda2dbb7fef ProxyVncCanvas version 0.2
e085711
parents: 15
diff changeset
167 cliList.remove(cli);
4eda2dbb7fef ProxyVncCanvas version 0.2
e085711
parents: 15
diff changeset
168 }
4eda2dbb7fef ProxyVncCanvas version 0.2
e085711
parents: 15
diff changeset
169 }
20
361016476783 not print out message version. ProxyVncCanvas
e085711
parents: 18
diff changeset
170 // System.out.println("cliSize="+cliSize());
17
4eda2dbb7fef ProxyVncCanvas version 0.2
e085711
parents: 15
diff changeset
171 }catch(Exception e){
4eda2dbb7fef ProxyVncCanvas version 0.2
e085711
parents: 15
diff changeset
172 }
27
13d4d3118cb8 create rfb.cliListTmp
e085711
parents: 26
diff changeset
173 }
13d4d3118cb8 create rfb.cliListTmp
e085711
parents: 26
diff changeset
174
13d4d3118cb8 create rfb.cliListTmp
e085711
parents: 26
diff changeset
175 void sendPngImage(){
13d4d3118cb8 create rfb.cliListTmp
e085711
parents: 26
diff changeset
176 try{
13d4d3118cb8 create rfb.cliListTmp
e085711
parents: 26
diff changeset
177 for(Socket cli : cliListTmp){
13d4d3118cb8 create rfb.cliListTmp
e085711
parents: 26
diff changeset
178 try{
13d4d3118cb8 create rfb.cliListTmp
e085711
parents: 26
diff changeset
179 sendPngData(cli);
13d4d3118cb8 create rfb.cliListTmp
e085711
parents: 26
diff changeset
180 addSock(cli);
13d4d3118cb8 create rfb.cliListTmp
e085711
parents: 26
diff changeset
181 }catch(IOException e){
13d4d3118cb8 create rfb.cliListTmp
e085711
parents: 26
diff changeset
182 // if socket closed
13d4d3118cb8 create rfb.cliListTmp
e085711
parents: 26
diff changeset
183 cliListTmp.remove(cli);
13d4d3118cb8 create rfb.cliListTmp
e085711
parents: 26
diff changeset
184 }
13d4d3118cb8 create rfb.cliListTmp
e085711
parents: 26
diff changeset
185 }
13d4d3118cb8 create rfb.cliListTmp
e085711
parents: 26
diff changeset
186 // System.out.println("cliSize="+cliSize());
13d4d3118cb8 create rfb.cliListTmp
e085711
parents: 26
diff changeset
187 }catch(Exception e){
13d4d3118cb8 create rfb.cliListTmp
e085711
parents: 26
diff changeset
188 }
13d4d3118cb8 create rfb.cliListTmp
e085711
parents: 26
diff changeset
189 cliListTmp.clear();
13d4d3118cb8 create rfb.cliListTmp
e085711
parents: 26
diff changeset
190 }
13d4d3118cb8 create rfb.cliListTmp
e085711
parents: 26
diff changeset
191
13d4d3118cb8 create rfb.cliListTmp
e085711
parents: 26
diff changeset
192
13d4d3118cb8 create rfb.cliListTmp
e085711
parents: 26
diff changeset
193
15
89e1c5f84407 faile ZRLE encode. success raw encode.
e085711
parents: 13
diff changeset
194 boolean ready() throws IOException {
89e1c5f84407 faile ZRLE encode. success raw encode.
e085711
parents: 13
diff changeset
195 BufferedReader br = new BufferedReader(new InputStreamReader(is));
89e1c5f84407 faile ZRLE encode. success raw encode.
e085711
parents: 13
diff changeset
196 return br.ready();
89e1c5f84407 faile ZRLE encode. success raw encode.
e085711
parents: 13
diff changeset
197 }
10
2840c7a259f1 add acceptThread
e085711
parents:
diff changeset
198
2840c7a259f1 add acceptThread
e085711
parents:
diff changeset
199 int cliSize(){
2840c7a259f1 add acceptThread
e085711
parents:
diff changeset
200 return cliList.size();
2840c7a259f1 add acceptThread
e085711
parents:
diff changeset
201 }
15
89e1c5f84407 faile ZRLE encode. success raw encode.
e085711
parents: 13
diff changeset
202 void printNumBytesRead(){
89e1c5f84407 faile ZRLE encode. success raw encode.
e085711
parents: 13
diff changeset
203 System.out.println("numBytesRead="+numBytesRead);
89e1c5f84407 faile ZRLE encode. success raw encode.
e085711
parents: 13
diff changeset
204 }
89e1c5f84407 faile ZRLE encode. success raw encode.
e085711
parents: 13
diff changeset
205 void bufResetSend(int size) throws IOException {
89e1c5f84407 faile ZRLE encode. success raw encode.
e085711
parents: 13
diff changeset
206 reset();
89e1c5f84407 faile ZRLE encode. success raw encode.
e085711
parents: 13
diff changeset
207 int len = size;
89e1c5f84407 faile ZRLE encode. success raw encode.
e085711
parents: 13
diff changeset
208 if(available() < size )
89e1c5f84407 faile ZRLE encode. success raw encode.
e085711
parents: 13
diff changeset
209 len = available();
89e1c5f84407 faile ZRLE encode. success raw encode.
e085711
parents: 13
diff changeset
210 byte buffer[] = new byte[len];
89e1c5f84407 faile ZRLE encode. success raw encode.
e085711
parents: 13
diff changeset
211 readFully(buffer);
89e1c5f84407 faile ZRLE encode. success raw encode.
e085711
parents: 13
diff changeset
212 sendData(buffer);
89e1c5f84407 faile ZRLE encode. success raw encode.
e085711
parents: 13
diff changeset
213 }
39
f399eec66846 send data:multi thread
e085711
parents: 38
diff changeset
214 void readSendData()throws IOException {
f399eec66846 send data:multi thread
e085711
parents: 38
diff changeset
215 byte buffer[] = new byte[dataLen];
f399eec66846 send data:multi thread
e085711
parents: 38
diff changeset
216 readFully(buffer);
f399eec66846 send data:multi thread
e085711
parents: 38
diff changeset
217 reset();
f399eec66846 send data:multi thread
e085711
parents: 38
diff changeset
218
f399eec66846 send data:multi thread
e085711
parents: 38
diff changeset
219 LinkedList <Thread> threads;
f399eec66846 send data:multi thread
e085711
parents: 38
diff changeset
220 threads = new LinkedList<Thread>();
f399eec66846 send data:multi thread
e085711
parents: 38
diff changeset
221
f399eec66846 send data:multi thread
e085711
parents: 38
diff changeset
222 for(Socket cli : cliList){
f399eec66846 send data:multi thread
e085711
parents: 38
diff changeset
223 // try{
f399eec66846 send data:multi thread
e085711
parents: 38
diff changeset
224 // OutputStream out = (OutputStream) cli.getOutputStream();
f399eec66846 send data:multi thread
e085711
parents: 38
diff changeset
225 // Thread th = new Thread(new SendThread(out, buffer));
f399eec66846 send data:multi thread
e085711
parents: 38
diff changeset
226 Thread th = new Thread(new SendThread(cli, buffer));
f399eec66846 send data:multi thread
e085711
parents: 38
diff changeset
227 threads.add(th);
f399eec66846 send data:multi thread
e085711
parents: 38
diff changeset
228 /*
f399eec66846 send data:multi thread
e085711
parents: 38
diff changeset
229 }catch(IOException e){
f399eec66846 send data:multi thread
e085711
parents: 38
diff changeset
230 // if socket closed
f399eec66846 send data:multi thread
e085711
parents: 38
diff changeset
231 cliListTmp.remove(cli);
f399eec66846 send data:multi thread
e085711
parents: 38
diff changeset
232 }catch(Exception e){
f399eec66846 send data:multi thread
e085711
parents: 38
diff changeset
233
f399eec66846 send data:multi thread
e085711
parents: 38
diff changeset
234 }
f399eec66846 send data:multi thread
e085711
parents: 38
diff changeset
235 */
f399eec66846 send data:multi thread
e085711
parents: 38
diff changeset
236 }
f399eec66846 send data:multi thread
e085711
parents: 38
diff changeset
237
f399eec66846 send data:multi thread
e085711
parents: 38
diff changeset
238 for(Thread thread : threads){
f399eec66846 send data:multi thread
e085711
parents: 38
diff changeset
239 thread.start();
f399eec66846 send data:multi thread
e085711
parents: 38
diff changeset
240 }
f399eec66846 send data:multi thread
e085711
parents: 38
diff changeset
241 try{
f399eec66846 send data:multi thread
e085711
parents: 38
diff changeset
242 for(Thread thread : threads){
f399eec66846 send data:multi thread
e085711
parents: 38
diff changeset
243 thread.join();
f399eec66846 send data:multi thread
e085711
parents: 38
diff changeset
244 }
f399eec66846 send data:multi thread
e085711
parents: 38
diff changeset
245 }catch(InterruptedException e){
f399eec66846 send data:multi thread
e085711
parents: 38
diff changeset
246
f399eec66846 send data:multi thread
e085711
parents: 38
diff changeset
247 }
f399eec66846 send data:multi thread
e085711
parents: 38
diff changeset
248
f399eec66846 send data:multi thread
e085711
parents: 38
diff changeset
249 }
18
ccad9909e0e2 raw only version
e085711
parents: 17
diff changeset
250 void regiFramebufferUpdate()throws IOException{
27
13d4d3118cb8 create rfb.cliListTmp
e085711
parents: 26
diff changeset
251 mark(20);
18
ccad9909e0e2 raw only version
e085711
parents: 17
diff changeset
252 messageType = readU8();
ccad9909e0e2 raw only version
e085711
parents: 17
diff changeset
253 skipBytes(1);
ccad9909e0e2 raw only version
e085711
parents: 17
diff changeset
254 rectangles = readU16();
23
b51bb7bc0766 test update
e085711
parents: 20
diff changeset
255 rectX = readU16();
b51bb7bc0766 test update
e085711
parents: 20
diff changeset
256 rectY = readU16();
b51bb7bc0766 test update
e085711
parents: 20
diff changeset
257 rectW = readU16();
b51bb7bc0766 test update
e085711
parents: 20
diff changeset
258 rectH = readU16();
27
13d4d3118cb8 create rfb.cliListTmp
e085711
parents: 26
diff changeset
259 encoding = readU32();
13d4d3118cb8 create rfb.cliListTmp
e085711
parents: 26
diff changeset
260 if(encoding == 16)
13d4d3118cb8 create rfb.cliListTmp
e085711
parents: 26
diff changeset
261 zLen = readU32();
23
b51bb7bc0766 test update
e085711
parents: 20
diff changeset
262 reset();
15
89e1c5f84407 faile ZRLE encode. success raw encode.
e085711
parents: 13
diff changeset
263 }
23
b51bb7bc0766 test update
e085711
parents: 20
diff changeset
264 void checkAndMark() throws IOException{
b51bb7bc0766 test update
e085711
parents: 20
diff changeset
265 switch(encoding){
b51bb7bc0766 test update
e085711
parents: 20
diff changeset
266 case RfbProto.EncodingRaw:
39
f399eec66846 send data:multi thread
e085711
parents: 38
diff changeset
267 dataLen = rectW * rectH * 4 + 16;
f399eec66846 send data:multi thread
e085711
parents: 38
diff changeset
268 mark(dataLen);
23
b51bb7bc0766 test update
e085711
parents: 20
diff changeset
269 break;
27
13d4d3118cb8 create rfb.cliListTmp
e085711
parents: 26
diff changeset
270 case RfbProto.EncodingZRLE:
39
f399eec66846 send data:multi thread
e085711
parents: 38
diff changeset
271 dataLen = zLen+20;
f399eec66846 send data:multi thread
e085711
parents: 38
diff changeset
272 mark(dataLen);
27
13d4d3118cb8 create rfb.cliListTmp
e085711
parents: 26
diff changeset
273 break;
23
b51bb7bc0766 test update
e085711
parents: 20
diff changeset
274 default:
38
84c02a9ce3ea add README
e085711
parents: 30
diff changeset
275 mark(1000000);
84c02a9ce3ea add README
e085711
parents: 30
diff changeset
276 }
23
b51bb7bc0766 test update
e085711
parents: 20
diff changeset
277 }
25
cded9fd297ab create png data
e085711
parents: 24
diff changeset
278 BufferedImage createBufferedImage(Image img){
cded9fd297ab create png data
e085711
parents: 24
diff changeset
279 BufferedImage bimg = new BufferedImage(img.getWidth(null), img.getHeight(null), BufferedImage.TYPE_INT_RGB );
27
13d4d3118cb8 create rfb.cliListTmp
e085711
parents: 26
diff changeset
280
25
cded9fd297ab create png data
e085711
parents: 24
diff changeset
281 Graphics g = bimg.getGraphics();
cded9fd297ab create png data
e085711
parents: 24
diff changeset
282 g.drawImage(img, 0, 0, null);
cded9fd297ab create png data
e085711
parents: 24
diff changeset
283 g.dispose();
cded9fd297ab create png data
e085711
parents: 24
diff changeset
284 return bimg;
cded9fd297ab create png data
e085711
parents: 24
diff changeset
285 }
cded9fd297ab create png data
e085711
parents: 24
diff changeset
286
cded9fd297ab create png data
e085711
parents: 24
diff changeset
287 void createPngBytes(BufferedImage bimg)throws IOException {
cded9fd297ab create png data
e085711
parents: 24
diff changeset
288 pngBytes = getImageBytes(bimg , "png");
cded9fd297ab create png data
e085711
parents: 24
diff changeset
289 }
cded9fd297ab create png data
e085711
parents: 24
diff changeset
290 byte[] getBytes(BufferedImage img)throws IOException {
cded9fd297ab create png data
e085711
parents: 24
diff changeset
291 byte[] b = getImageBytes(img, "png");
cded9fd297ab create png data
e085711
parents: 24
diff changeset
292 return b;
cded9fd297ab create png data
e085711
parents: 24
diff changeset
293 }
23
b51bb7bc0766 test update
e085711
parents: 20
diff changeset
294
25
cded9fd297ab create png data
e085711
parents: 24
diff changeset
295 byte[] getImageBytes(BufferedImage image, String imageFormat) throws IOException {
cded9fd297ab create png data
e085711
parents: 24
diff changeset
296 ByteArrayOutputStream bos = new ByteArrayOutputStream();
cded9fd297ab create png data
e085711
parents: 24
diff changeset
297 BufferedOutputStream os = new BufferedOutputStream(bos);
cded9fd297ab create png data
e085711
parents: 24
diff changeset
298 image.flush();
cded9fd297ab create png data
e085711
parents: 24
diff changeset
299 ImageIO.write(image, imageFormat, os);
cded9fd297ab create png data
e085711
parents: 24
diff changeset
300 os.flush();
cded9fd297ab create png data
e085711
parents: 24
diff changeset
301 os.close();
cded9fd297ab create png data
e085711
parents: 24
diff changeset
302 return bos.toByteArray();
cded9fd297ab create png data
e085711
parents: 24
diff changeset
303 }
cded9fd297ab create png data
e085711
parents: 24
diff changeset
304
cded9fd297ab create png data
e085711
parents: 24
diff changeset
305 void sendPngData(Socket sock)throws IOException{
26
0aa0e0bd742c succeed drawFirstImage()!!
e085711
parents: 25
diff changeset
306 byte[] dataLength = castIntByte(pngBytes.length);
0aa0e0bd742c succeed drawFirstImage()!!
e085711
parents: 25
diff changeset
307 sock.getOutputStream().write(dataLength);
25
cded9fd297ab create png data
e085711
parents: 24
diff changeset
308 sock.getOutputStream().write(pngBytes);
cded9fd297ab create png data
e085711
parents: 24
diff changeset
309 }
26
0aa0e0bd742c succeed drawFirstImage()!!
e085711
parents: 25
diff changeset
310 byte[] castIntByte(int len){
0aa0e0bd742c succeed drawFirstImage()!!
e085711
parents: 25
diff changeset
311 byte[] b = new byte[4];
0aa0e0bd742c succeed drawFirstImage()!!
e085711
parents: 25
diff changeset
312 b[0] = (byte)((len >>> 24 ) & 0xFF);
0aa0e0bd742c succeed drawFirstImage()!!
e085711
parents: 25
diff changeset
313 b[1] = (byte)((len >>> 16 ) & 0xFF);
0aa0e0bd742c succeed drawFirstImage()!!
e085711
parents: 25
diff changeset
314 b[2] = (byte)((len >>> 8 ) & 0xFF);
0aa0e0bd742c succeed drawFirstImage()!!
e085711
parents: 25
diff changeset
315 b[3] = (byte)((len >>> 0 ) & 0xFF);
0aa0e0bd742c succeed drawFirstImage()!!
e085711
parents: 25
diff changeset
316 return b;
0aa0e0bd742c succeed drawFirstImage()!!
e085711
parents: 25
diff changeset
317 }
25
cded9fd297ab create png data
e085711
parents: 24
diff changeset
318
cded9fd297ab create png data
e085711
parents: 24
diff changeset
319 BufferedImage createBimg()throws IOException{
cded9fd297ab create png data
e085711
parents: 24
diff changeset
320 BufferedImage bimg = ImageIO.read(new ByteArrayInputStream(pngBytes));
cded9fd297ab create png data
e085711
parents: 24
diff changeset
321 return bimg;
cded9fd297ab create png data
e085711
parents: 24
diff changeset
322 }
cded9fd297ab create png data
e085711
parents: 24
diff changeset
323 void readPngData()throws IOException{
cded9fd297ab create png data
e085711
parents: 24
diff changeset
324 pngBytes = new byte[is.available()];
cded9fd297ab create png data
e085711
parents: 24
diff changeset
325 readFully(pngBytes);
cded9fd297ab create png data
e085711
parents: 24
diff changeset
326 }
18
ccad9909e0e2 raw only version
e085711
parents: 17
diff changeset
327 void printFramebufferUpdate(){
ccad9909e0e2 raw only version
e085711
parents: 17
diff changeset
328
ccad9909e0e2 raw only version
e085711
parents: 17
diff changeset
329 System.out.println("messageType=" + messageType);
ccad9909e0e2 raw only version
e085711
parents: 17
diff changeset
330 System.out.println("rectangles="+rectangles);
ccad9909e0e2 raw only version
e085711
parents: 17
diff changeset
331 System.out.println("encoding=" + encoding);
23
b51bb7bc0766 test update
e085711
parents: 20
diff changeset
332 switch(encoding){
b51bb7bc0766 test update
e085711
parents: 20
diff changeset
333 case RfbProto.EncodingRaw:
b51bb7bc0766 test update
e085711
parents: 20
diff changeset
334 System.out.println("rectW * rectH * 4 + 16 =" + rectW * rectH * 4 + 16);
b51bb7bc0766 test update
e085711
parents: 20
diff changeset
335 break;
b51bb7bc0766 test update
e085711
parents: 20
diff changeset
336 default:
b51bb7bc0766 test update
e085711
parents: 20
diff changeset
337 }
18
ccad9909e0e2 raw only version
e085711
parents: 17
diff changeset
338 }
10
2840c7a259f1 add acceptThread
e085711
parents:
diff changeset
339 }