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