Mercurial > hg > Members > nobuyasu > tightVNCProxy
changeset 27:13d4d3118cb8
create rfb.cliListTmp
author | e085711 |
---|---|
date | Tue, 26 Apr 2011 14:48:48 +0900 |
parents | 0aa0e0bd742c |
children | 2fd55d934ffa |
files | src/myVncProxy/MyRfbProto.java src/myVncProxy/ProxyVncCanvas.java src/myVncProxy/VncCanvas.java src/myVncProxy/VncProxyService.java src/myVncProxy/VncViewer.java src/myVncProxy/acceptThread.java |
diffstat | 6 files changed, 77 insertions(+), 46 deletions(-) [+] |
line wrap: on
line diff
--- a/src/myVncProxy/MyRfbProto.java Tue Apr 26 09:08:49 2011 +0900 +++ b/src/myVncProxy/MyRfbProto.java Tue Apr 26 14:48:48 2011 +0900 @@ -26,22 +26,29 @@ private int rectW; private int rectH; private int encoding; + private int zLen; private ServerSocket servSock; private int acceptPort; private byte initData[]; + private LinkedList <Socket> cliListTmp; private LinkedList <Socket> cliList; + boolean createBimgFlag; byte[] pngBytes; MyRfbProto(String h, int p, VncViewer v ) throws IOException { super(h, p, v); cliList = new LinkedList <Socket>(); + cliListTmp = new LinkedList <Socket>(); + createBimgFlag = false; } MyRfbProto(String h, int p) throws IOException { super(h, p); cliList = new LinkedList <Socket>(); + cliListTmp = new LinkedList <Socket>(); + createBimgFlag = false; } void initServSock(int port) throws IOException{ @@ -76,6 +83,9 @@ void addSock(Socket sock){ cliList.add(sock); } + void addSockTmp(Socket sock){ + cliListTmp.add(sock); + } void mark(int len) throws IOException { is.mark(len); @@ -140,8 +150,6 @@ } void sendData(byte b[]){ - - try{ for(Socket cli : cliList){ try{ @@ -154,7 +162,27 @@ // System.out.println("cliSize="+cliSize()); }catch(Exception e){ } - } + } + + void sendPngImage(){ + try{ + for(Socket cli : cliListTmp){ + try{ + sendPngData(cli); + addSock(cli); + }catch(IOException e){ + // if socket closed + cliListTmp.remove(cli); + } + } +// System.out.println("cliSize="+cliSize()); + }catch(Exception e){ + } + cliListTmp.clear(); + } + + + boolean ready() throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(is)); return br.ready(); @@ -176,7 +204,7 @@ sendData(buffer); } void regiFramebufferUpdate()throws IOException{ - mark(16); + mark(20); messageType = readU8(); skipBytes(1); rectangles = readU16(); @@ -184,7 +212,9 @@ rectY = readU16(); rectW = readU16(); rectH = readU16(); - encoding = readU32(); + encoding = readU32(); + if(encoding == 16) + zLen = readU32(); reset(); } void checkAndMark() throws IOException{ @@ -192,13 +222,16 @@ case RfbProto.EncodingRaw: mark(rectW * rectH * 4 + 16); break; + case RfbProto.EncodingZRLE: + mark(zLen); + break; default: - mark(1000000); + mark(1000000);//適当 } } BufferedImage createBufferedImage(Image img){ BufferedImage bimg = new BufferedImage(img.getWidth(null), img.getHeight(null), BufferedImage.TYPE_INT_RGB ); - + Graphics g = bimg.getGraphics(); g.drawImage(img, 0, 0, null); g.dispose(); @@ -224,13 +257,6 @@ } void sendPngData(Socket sock)throws IOException{ - System.out.println("pngBytes.length="+pngBytes.length); - -// ByteBuffer length = ByteBuffer.allocate(4); -// length.putInt(pngBytes.length); - -// byte b = 1; -// sock.getOutputStream().write(b); byte[] dataLength = castIntByte(pngBytes.length); sock.getOutputStream().write(dataLength); sock.getOutputStream().write(pngBytes);
--- a/src/myVncProxy/ProxyVncCanvas.java Tue Apr 26 09:08:49 2011 +0900 +++ b/src/myVncProxy/ProxyVncCanvas.java Tue Apr 26 14:48:48 2011 +0900 @@ -79,6 +79,7 @@ // True if we process keyboard and mouse events. boolean inputEnabled; + // @@ -93,7 +94,7 @@ maxHeight = maxHeight_; rfb = viewer.rfb; - + tightInflaters = new Inflater[4]; cm8 = new DirectColorModel(8, 7, (7 << 3), (3 << 6)); @@ -538,11 +539,19 @@ } bufSize = (int)rfb.getNumBytesRead() - bufSize; - System.out.println("bufSize="+bufSize); +// System.out.println("bufSize="+bufSize); rfb.bufResetSend(bufSize); - bimg = createBufferedImage(rawPixelsImage); - rfb.createPngBytes(bimg); + if(rfb.createBimgFlag){ + bimg = createBufferedImage(rawPixelsImage); + //bimg(BufferedImage) -> rfb.pngBytes(byte[]) + rfb.createPngBytes(bimg); + rfb.sendPngImage(); + rfb.createBimgFlag = false; + + + } + /* boolean result = false; try{
--- a/src/myVncProxy/VncCanvas.java Tue Apr 26 09:08:49 2011 +0900 +++ b/src/myVncProxy/VncCanvas.java Tue Apr 26 14:48:48 2011 +0900 @@ -101,7 +101,7 @@ // True if we process keyboard and mouse events. boolean inputEnabled; - + // // The constructors. // @@ -115,7 +115,7 @@ rfb = viewer.rfb; scalingFactor = viewer.options.scalingFactor; - + tightInflaters = new Inflater[4]; cm8 = new DirectColorModel(8, 7, (7 << 3), (3 << 6)); @@ -398,8 +398,6 @@ } catch (IOException e) { } */ - Thread accept = new Thread(new acceptThread(rfb)); - accept.start(); while (true) { @@ -566,16 +564,20 @@ System.out.println("bufSize="+bufSize); rfb.bufResetSend((int)bufSize); - bimg = createBufferedImage(rawPixelsImage); - rfb.createPngBytes(bimg); - - boolean result = false; - try{ - result = ImageIO.write(bimg, "png", new File("sample.png")); - }catch(Exception e){ - e.printStackTrace(); - result = false; + if(rfb.createBimgFlag){ + bimg = createBufferedImage(rawPixelsImage); + rfb.createPngBytes(bimg); + createBimgFlag = false; + boolean result = false; + try{ + result = ImageIO.write(bimg, "png", new File("sample.png")); + }catch(Exception e){ + e.printStackTrace(); + result = false; + } } + + } }
--- a/src/myVncProxy/VncProxyService.java Tue Apr 26 09:08:49 2011 +0900 +++ b/src/myVncProxy/VncProxyService.java Tue Apr 26 14:48:48 2011 +0900 @@ -18,6 +18,7 @@ // RfbProto rfb; MyRfbProto rfb; Thread rfbThread; + Thread accThread; Frame vncFrame; Container vncContainer; @@ -81,8 +82,8 @@ rfbThread = new Thread(this); rfbThread.start(); - Thread accept = new Thread(new acceptThread(rfb, vc)); - accept.start(); + accThread = new Thread(new acceptThread(rfb)); + accThread.start(); }
--- a/src/myVncProxy/VncViewer.java Tue Apr 26 09:08:49 2011 +0900 +++ b/src/myVncProxy/VncViewer.java Tue Apr 26 14:48:48 2011 +0900 @@ -60,6 +60,7 @@ // RfbProto rfb; MyRfbProto rfb; Thread rfbThread; + Thread accThread; Frame vncFrame; Container vncContainer; @@ -135,6 +136,8 @@ rfbThread = new Thread(this); rfbThread.start(); + accThread = new Thread(new acceptThread(rfb)); + accThread.start(); } public void update(Graphics g) {
--- a/src/myVncProxy/acceptThread.java Tue Apr 26 09:08:49 2011 +0900 +++ b/src/myVncProxy/acceptThread.java Tue Apr 26 14:48:48 2011 +0900 @@ -4,29 +4,19 @@ public class acceptThread implements Runnable { MyRfbProto rfb; - ProxyVncCanvas pvc; - VncCanvas vc; byte[] imageBytes; - + acceptThread(MyRfbProto _rfb ) { rfb = _rfb; } - acceptThread(MyRfbProto _rfb, ProxyVncCanvas _vc ) { - rfb = _rfb; - pvc = _vc; - } - acceptThread(MyRfbProto _rfb, VncCanvas _vc ) { - rfb = _rfb; - vc = _vc; - } public void run() { rfb.selectPort(); while (true) { try { Socket newCli = rfb.accept(); rfb.sendInitData(newCli); - rfb.sendPngData(newCli); - rfb.addSock(newCli); + rfb.createBimgFlag = true; + rfb.addSockTmp(newCli); } catch (IOException e) { e.printStackTrace(); System.out.println(e);