Mercurial > hg > Members > nobuyasu > tightVNCProxy
comparison src/myVncProxy/MyRfbProto.java @ 75:6e703f1000e7
merge
author | Yu Taninari <e085734@ie.u-ryukyu.ac.jp> |
---|---|
date | Thu, 28 Jul 2011 17:52:48 +0900 |
parents | 6fc4272db7e2 f695bc56eb4f |
children | 347c153f74c7 |
comparison
equal
deleted
inserted
replaced
74:4423c9c5ab5b | 75:6e703f1000e7 |
---|---|
22 import java.util.concurrent.ExecutorService; | 22 import java.util.concurrent.ExecutorService; |
23 import java.util.concurrent.Executors; | 23 import java.util.concurrent.Executors; |
24 import java.io.OutputStream; | 24 import java.io.OutputStream; |
25 | 25 |
26 class MyRfbProto extends RfbProto { | 26 class MyRfbProto extends RfbProto { |
27 | |
28 final static String versionMsg_3_998 = "RFB 003.998\n"; | 27 final static String versionMsg_3_998 = "RFB 003.998\n"; |
28 /** | |
29 * CheckMillis is one of new msgType for RFB 3.998. | |
30 */ | |
31 final static int CheckMillis = 4; | |
32 boolean printStatusFlag = false; | |
33 long startCheckTime; | |
29 | 34 |
30 private int messageType; | 35 private int messageType; |
31 private int rectangles; | 36 private int rectangles; |
32 private int rectX; | 37 private int rectX; |
33 private int rectY; | 38 private int rectY; |
318 rectH = readU16(); | 323 rectH = readU16(); |
319 encoding = readU32(); | 324 encoding = readU32(); |
320 if (encoding == 16) | 325 if (encoding == 16) |
321 zLen = readU32(); | 326 zLen = readU32(); |
322 reset(); | 327 reset(); |
328 /* | |
329 int dataLen; | |
330 switch (encoding) { | |
331 case RfbProto.EncodingRaw: | |
332 dataLen = rectW * rectH * 4 + 16; | |
333 mark(dataLen); | |
334 break; | |
335 case RfbProto.EncodingCopyRect: | |
336 dataLen = 16 + 4; | |
337 mark(dataLen); | |
338 break; | |
339 case RfbProto.EncodingRRE: | |
340 case RfbProto.EncodingCoRRE: | |
341 case RfbProto.EncodingHextile: | |
342 | |
343 case RfbProto.EncodingZlib: | |
344 case RfbProto.EncodingTight: | |
345 case RfbProto.EncodingZRLE: | |
346 dataLen = zLen + 20; | |
347 mark(dataLen); | |
348 break; | |
349 default: | |
350 dataLen = 1000000; | |
351 mark(dataLen); | |
352 } | |
353 | |
354 */ | |
355 | |
323 } | 356 } |
324 | 357 |
325 int checkAndMark() throws IOException { | 358 int checkAndMark() throws IOException { |
326 int dataLen; | 359 int dataLen; |
327 switch (encoding) { | 360 switch (encoding) { |
328 case RfbProto.EncodingRaw: | 361 case RfbProto.EncodingRaw: |
329 dataLen = rectW * rectH * 4 + 16; | 362 dataLen = rectW * rectH * 4 + 16; |
330 mark(dataLen); | 363 mark(dataLen); |
331 break; | 364 break; |
365 case RfbProto.EncodingCopyRect: | |
366 dataLen = 16 + 4; | |
367 mark(dataLen); | |
368 break; | |
369 case RfbProto.EncodingRRE: | |
370 case RfbProto.EncodingCoRRE: | |
371 case RfbProto.EncodingHextile: | |
372 case RfbProto.EncodingZlib: | |
373 case RfbProto.EncodingTight: | |
332 case RfbProto.EncodingZRLE: | 374 case RfbProto.EncodingZRLE: |
333 dataLen = zLen + 20; | 375 dataLen = zLen + 20; |
334 mark(dataLen); | 376 mark(dataLen); |
335 break; | 377 break; |
336 default: | 378 default: |
337 dataLen = 1000000; | 379 dataLen = 1000000; |
338 mark(dataLen); | 380 mark(dataLen); |
339 } | 381 } |
340 return dataLen; | 382 return dataLen; |
341 } | 383 } |
384 | |
342 void readSendData(int dataLen) throws IOException { | 385 void readSendData(int dataLen) throws IOException { |
343 byte buffer[] = new byte[dataLen]; | 386 byte buffer[] = new byte[dataLen]; |
344 readFully(buffer); | 387 readFully(buffer); |
345 multicastqueue.put(buffer); | 388 multicastqueue.put(buffer); |
346 reset(); | 389 reset(); |
390 | |
347 /* | 391 /* |
348 for (Socket cli : cliList) { | 392 for (Socket cli : cliList) { |
349 try { | 393 try { |
350 OutputStream out = cli.getOutputStream(); | 394 OutputStream out = cli.getOutputStream(); |
351 executor.execute(new SendThread(out, buffer)); | 395 executor.execute(new SendThread(out, buffer)); |
412 | 456 |
413 BufferedImage createBimg() throws IOException { | 457 BufferedImage createBimg() throws IOException { |
414 BufferedImage bimg = ImageIO.read(new ByteArrayInputStream(pngBytes)); | 458 BufferedImage bimg = ImageIO.read(new ByteArrayInputStream(pngBytes)); |
415 return bimg; | 459 return bimg; |
416 } | 460 } |
417 | 461 /* |
418 void readPngData() throws IOException { | 462 void readPngData() throws IOException { |
419 pngBytes = new byte[is.available()]; | 463 pngBytes = new byte[is.available()]; |
420 readFully(pngBytes); | 464 readFully(pngBytes); |
421 } | 465 } |
422 | 466 */ |
423 void printFramebufferUpdate() { | 467 void printFramebufferUpdate() { |
424 | 468 |
425 System.out.println("messageType=" + messageType); | 469 System.out.println("messageType=" + messageType); |
426 System.out.println("rectangles=" + rectangles); | 470 System.out.println("rectangles=" + rectangles); |
427 System.out.println("encoding=" + encoding); | 471 System.out.println("encoding=" + encoding); |
431 + 16); | 475 + 16); |
432 break; | 476 break; |
433 default: | 477 default: |
434 } | 478 } |
435 } | 479 } |
480 | |
481 void readCheckMillis() throws IOException { | |
482 byte[] b = new byte[2]; | |
483 readFully(b); | |
484 } | |
485 | |
486 void startCheckMillis() { | |
487 byte[] b = new byte[2]; | |
488 b[0] = (byte) CheckMillis; | |
489 b[1] = (byte) 0; | |
490 startCheckTime = System.currentTimeMillis(); | |
491 System.out.println("startChckTime = "+ startCheckTime); | |
492 multicastqueue.put(b); | |
493 } | |
494 | |
495 void endCheckMills() { | |
496 long accTime = System.currentTimeMillis(); | |
497 long time = accTime - startCheckTime; | |
498 System.out.println("checkMillis: " + time); | |
499 } | |
500 | |
501 void printStatus() { | |
502 System.out.println(); | |
503 } | |
504 | |
505 synchronized void changeStatusFlag() { | |
506 printStatusFlag = true; | |
507 } | |
508 | |
509 void printMills() { | |
510 if(printStatusFlag) { | |
511 | |
512 changeStatusFlag(); | |
513 } else { | |
514 changeStatusFlag(); | |
515 } | |
516 } | |
517 | |
436 | 518 |
437 void newClient(AcceptThread acceptThread, final Socket newCli, | 519 void newClient(AcceptThread acceptThread, final Socket newCli, |
438 final OutputStream os, final InputStream is) throws IOException { | 520 final OutputStream os, final InputStream is) throws IOException { |
439 // createBimgFlag = true; | 521 // createBimgFlag = true; |
440 // rfb.addSockTmp(newCli); | 522 // rfb.addSockTmp(newCli); |
441 // addSock(newCli); | 523 // addSock(newCli); |
442 final Client<byte[]> c = multicastqueue.newClient(); | 524 final Client<byte[]> c = multicastqueue.newClient(); |
443 Runnable sender = new Runnable() { | 525 Runnable sender = new Runnable() { |
444 public void run() { | 526 public void run() { |
445 try { | 527 try { |
446 // 初期接続確立の部分 | 528 /** |
529 * initial connection of RFB protocol | |
530 */ | |
447 sendRfbVersion(os); | 531 sendRfbVersion(os); |
448 readVersionMsg(is); | 532 readVersionMsg(is); |
449 sendSecurityType(os); | 533 sendSecurityType(os); |
450 readSecType(is); | 534 readSecType(is); |
451 sendSecResult(os); | 535 sendSecResult(os); |
455 for (;;) { | 539 for (;;) { |
456 byte[] b = c.poll(); | 540 byte[] b = c.poll(); |
457 os.write(b, 0, b.length); | 541 os.write(b, 0, b.length); |
458 } | 542 } |
459 } catch (IOException e) { | 543 } catch (IOException e) { |
460 //接続が切れた処理 | 544 /** |
461 //lockしないと駄目 | 545 * if socket closed |
546 */ | |
462 // cliList.remove(newCli); | 547 // cliList.remove(newCli); |
463 } | 548 } |
464 | 549 |
465 } | 550 } |
466 | 551 |
467 }; | 552 }; |
468 new Thread(sender).start(); | 553 new Thread(sender).start(); |
469 | 554 |
470 } | 555 } |
556 | |
557 void sendCheckMillis() { | |
558 | |
559 Runnable stdin = new Runnable() { | |
560 public void run() { | |
561 int c; | |
562 try { | |
563 while( (c = System.in.read()) != -1 ) { | |
564 switch(c) { | |
565 case 's': | |
566 break; | |
567 default: | |
568 startCheckMillis(); | |
569 break; | |
570 } | |
571 } | |
572 }catch(IOException e){ | |
573 System.out.println(e); | |
574 } | |
575 } | |
576 }; | |
577 | |
578 new Thread(stdin).start(); | |
579 } | |
580 | |
471 } | 581 } |
582 | |
583 |