# HG changeset patch # User e085711 # Date 1308119433 -32400 # Node ID 49eed04b9b3bceb35700b52a32811f61cf705d4c # Parent 1d3baf14cafb3ae566ea46ee1143101ddd6d26dd add SendThread, modify MyRfbProto.java diff -r 1d3baf14cafb -r 49eed04b9b3b src/myVncClient/MyRfbProto.java --- a/src/myVncClient/MyRfbProto.java Wed May 18 11:39:26 2011 +0900 +++ b/src/myVncClient/MyRfbProto.java Wed Jun 15 15:30:33 2011 +0900 @@ -15,6 +15,9 @@ import javax.imageio.ImageIO; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.io.OutputStream; class MyRfbProto extends RfbProto { @@ -26,21 +29,29 @@ private int rectH; private int encoding; private int zLen; + private int dataLen; private ServerSocket servSock; private int acceptPort; private byte initData[]; private LinkedList cliListTmp; private LinkedList cliList; + private LinkedList sendThreads; boolean createBimgFlag; - + + ExecutorService executor; + + byte[] pngBytes; - + MyRfbProto(String h, int p, VncViewer v ) throws IOException { super(h, p, v); cliList = new LinkedList (); cliListTmp = new LinkedList (); createBimgFlag = false; + sendThreads = new LinkedList (); +// executor = Executors.newCachedThreadPool(); + executor = Executors.newSingleThreadExecutor(); } MyRfbProto(String h, int p) throws IOException { @@ -48,6 +59,9 @@ cliList = new LinkedList (); cliListTmp = new LinkedList (); createBimgFlag = false; + sendThreads = new LinkedList (); +// executor = Executors.newCachedThreadPool(); + executor = Executors.newSingleThreadExecutor(); } void initServSock(int port) throws IOException{ @@ -67,7 +81,7 @@ } } - System.out.println("acceptport="+i); + System.out.println("accept port = "+i); } int getAcceptPort(){ return acceptPort; @@ -145,12 +159,6 @@ inNormalProtocol = true; } - void readPngData()throws IOException{ - // Dataの大きさを読み込む - int length = readU32(); - pngBytes = new byte[length]; - readFully(pngBytes); - } void sendInitData(Socket sock) throws IOException{ sock.getOutputStream().write(initData); @@ -187,6 +195,8 @@ } cliListTmp.clear(); } + + boolean ready() throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(is)); @@ -208,6 +218,24 @@ readFully(buffer); sendData(buffer); } + void readSendData()throws IOException{ + byte buffer[] = new byte[dataLen]; + readFully(buffer); + reset(); + + for(Socket cli : cliList){ + try{ + OutputStream out = cli.getOutputStream(); + executor.execute(new SendThread(out, buffer)); + }catch(IOException e){ + // if client socket closed + cliListTmp.remove(cli); + }catch(Exception e){ + + } + + } + } void regiFramebufferUpdate()throws IOException{ mark(20); messageType = readU8(); @@ -225,10 +253,12 @@ void checkAndMark() throws IOException{ switch(encoding){ case RfbProto.EncodingRaw: - mark(rectW * rectH * 4 + 16); + dataLen = rectW * rectH * 4 + 16; + mark(dataLen); break; case RfbProto.EncodingZRLE: - mark(zLen); + dataLen = zLen+20; + mark(dataLen); break; default: mark(1000000); @@ -279,6 +309,11 @@ BufferedImage bimg = ImageIO.read(new ByteArrayInputStream(pngBytes)); return bimg; } + void readPngData()throws IOException{ + int length = readU32(); + pngBytes = new byte[length]; + readFully(pngBytes); + } void printFramebufferUpdate(){ System.out.println("messageType=" + messageType); diff -r 1d3baf14cafb -r 49eed04b9b3b src/myVncClient/SendThread.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/myVncClient/SendThread.java Wed Jun 15 15:30:33 2011 +0900 @@ -0,0 +1,30 @@ +package myVncClient; +import java.net.Socket; +import java.io.IOException; +import java.io.OutputStream; + + +public class SendThread implements Runnable { + + Socket sock; + OutputStream out; + byte b[]; + + SendThread(Socket _sock, byte _b[]){ + sock = _sock; + b = _b; + } + SendThread(OutputStream _out, byte _b[]){ + out = _out; + b = _b; + } + + public void run() { + try{ + out.write(b, 0, b.length); +// sock.getOutputStream().write(b, 0, b.length); + }catch(IOException e){ + + } + } +} diff -r 1d3baf14cafb -r 49eed04b9b3b src/myVncClient/VncCanvas.java --- a/src/myVncClient/VncCanvas.java Wed May 18 11:39:26 2011 +0900 +++ b/src/myVncClient/VncCanvas.java Wed Jun 15 15:30:33 2011 +0900 @@ -393,7 +393,7 @@ rfb.regiFramebufferUpdate(); rfb.checkAndMark(); -// rfb.printFramebufferUpdate(); +// rfb.readSendData(); int bufSize = (int)rfb.getNumBytesRead(); @@ -551,6 +551,7 @@ // System.out.println("bufSize="+bufSize); rfb.bufResetSend(bufSize); + if(rfb.createBimgFlag){ // bimg = createBufferedImage(rawPixelsImage); bimg = createBufferedImage(memImage); @@ -559,10 +560,6 @@ rfb.sendPngImage(); rfb.createBimgFlag = false; } - - - - } }