Mercurial > hg > Members > nobuyasu > tightVNCProxy
changeset 130:cb00150c223e
implement sendEchoPort
author | e085711 |
---|---|
date | Tue, 30 Aug 2011 05:39:12 +0900 |
parents | e3dddee7b934 |
children | 2a90459a05f0 |
files | src/myVncProxy/CreateThread.java src/myVncProxy/MyRfbProto.java src/myVncProxy/OptionsNoFrame.java src/myVncProxy/ProxyVncCanvas.java src/myVncProxy/RfbProto.java src/myVncProxy/VncProxyService.java |
diffstat | 6 files changed, 100 insertions(+), 29 deletions(-) [+] |
line wrap: on
line diff
--- a/src/myVncProxy/CreateThread.java Mon Aug 08 16:54:34 2011 +0900 +++ b/src/myVncProxy/CreateThread.java Tue Aug 30 05:39:12 2011 +0900 @@ -4,15 +4,23 @@ import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintStream; +import java.net.BindException; import java.net.ServerSocket; import java.net.Socket; public class CreateThread implements Runnable { ServerSocket echoServer; AcceptClient acceptClient; - + int port; + public CreateThread(AcceptClient _acc) { acceptClient = _acc; + port = 9999; + } + + public CreateThread(AcceptClient _acc , int port) { + acceptClient = _acc; + this.port = port; } void newEchoClient(final BufferedReader is,final PrintStream os) { @@ -24,11 +32,34 @@ new Thread(echoSender).start(); } - public void run() { - + void selectPort(int p) { + int port = p; while (true) { try { - echoServer = new ServerSocket(9999); + initServSock(port); + break; + } catch (BindException e) { + port++; + continue; + } catch (IOException e) { + + } + } + System.out.println("accept port = " + port); + } + + void initServSock(int port) throws IOException { + echoServer = new ServerSocket(port); + this.port = port; + } + + + public void run() { + selectPort(port); + + while (true) { + try { +// echoServer = new ServerSocket(9999); Socket clientSocket = echoServer.accept(); BufferedReader is = new BufferedReader(new InputStreamReader( clientSocket.getInputStream()));
--- a/src/myVncProxy/MyRfbProto.java Mon Aug 08 16:54:34 2011 +0900 +++ b/src/myVncProxy/MyRfbProto.java Tue Aug 30 05:39:12 2011 +0900 @@ -70,7 +70,8 @@ private int clients = 0; private Inflater inflater = new Inflater(); private Deflater deflater = new Deflater(); - + private CreateThread geth; + public MyRfbProto() throws IOException { } @@ -79,6 +80,11 @@ super(h, p, v); } + MyRfbProto(String h, int p, CreateThread geth) throws IOException { + super(h, p); + this.geth = geth; + } + MyRfbProto(String h, int p) throws IOException { super(h, p); } @@ -226,6 +232,16 @@ "RFB server does not support protocol version 3"); } + if (serverMinor == 998) { + sendPortNumber(); + } + + } + + void sendPortNumber() throws IOException { + byte[] b = new byte[4]; + b = castIntByte(geth.port); + os.write(b); } void sendSecurityType(OutputStream os) throws IOException { @@ -313,24 +329,24 @@ switch (encoding) { case RfbProto.EncodingRaw: dataLen = rectW * rectH * 4 + 16; - is.mark(dataLen); +// is.mark(dataLen); break; case RfbProto.EncodingCopyRect: dataLen = 16 + 4; - is.mark(dataLen); +// is.mark(dataLen); break; case RfbProto.EncodingRRE: case RfbProto.EncodingCoRRE: case RfbProto.EncodingHextile: case RfbProto.EncodingTight: dataLen = zLen + 20; - is.mark(dataLen); +// is.mark(dataLen); break; case RfbProto.EncodingZlib: case RfbProto.EncodingZRLE: case RfbProto.EncodingZRLEE: dataLen = zLen + 20; - is.mark(dataLen); +// is.mark(dataLen); break; case RfbProto.EncodingXCursor: case RfbProto.EncodingRichCursor: @@ -338,11 +354,11 @@ int u8Array = (int)Math.floor((rectW + 7)/8) * rectH; dataLen = pixArray + u8Array; printFramebufferUpdate(); - is.mark(dataLen); +// is.mark(dataLen); break; default: dataLen = 1000000; - is.mark(dataLen); +// is.mark(dataLen); } return dataLen; } @@ -350,6 +366,7 @@ void sendDataToClient() throws Exception { regiFramebufferUpdate(); + printFramebufferUpdate(); int dataLen = checkAndMark(); readSendData(dataLen); } @@ -419,6 +436,10 @@ default: } } + int returnMsgtype() { + return messageType; + } + void readSpeedCheck() throws IOException { byte[] b = new byte[1]; @@ -603,10 +624,10 @@ bufs.addFirst(header); multicastqueue.put(bufs); - is.reset(); + +// is.reset(); return ; } - } bufs.add(header); if (dataLen>16) { ByteBuffer b = ByteBuffer.allocate(dataLen-16); @@ -615,6 +636,8 @@ } multicastqueue.put(bufs); is.reset(); + } + is.reset(); // It may be compressed. We can inflate here to avoid repeating clients decompressing here, // but it may generate too many large data. It is better to do it in each client.
--- a/src/myVncProxy/OptionsNoFrame.java Mon Aug 08 16:54:34 2011 +0900 +++ b/src/myVncProxy/OptionsNoFrame.java Tue Aug 30 05:39:12 2011 +0900 @@ -74,14 +74,14 @@ // Constructor. Set up the labels and choices from the names and values // arrays. // - +/* OptionsNoFrame(VncProxyService v) { viewer = v; preferredEncoding = -1; } - - OptionsNoFrame(VncProxyService v, VncCanvas vc) { -// OptionsNoFrame(VncProxyService v) { +*/ +// OptionsNoFrame(VncProxyService v, VncCanvas vc) { + OptionsNoFrame(VncProxyService v) { viewer = v; for (int i = 0; i < names.length; i++) {
--- a/src/myVncProxy/ProxyVncCanvas.java Mon Aug 08 16:54:34 2011 +0900 +++ b/src/myVncProxy/ProxyVncCanvas.java Tue Aug 30 05:39:12 2011 +0900 @@ -101,7 +101,7 @@ for (int i = 0; i < 256; i++) colors[i] = new Color(cm8.getRGB(i)); -// setPixelFormat(); + setPixelFormat(); inputEnabled = false; // Keyboard listener is enabled even in view-only mode, to catch @@ -211,7 +211,7 @@ } public void setPixelFormat() throws IOException { -/* + if (viewer.options.eightBitColors) { rfb.writeSetPixelFormat(8, 8, false, true, 7, 7, 3, 0, 3, 6); bytesPixel = 1; @@ -220,7 +220,7 @@ 0); bytesPixel = 4; } -*/ + updateFramebufferSize(); } @@ -367,6 +367,14 @@ * read Data from parents and send Data to Client. */ rfb.sendDataToClient(); + + if(rfb.returnMsgtype() == RfbProto.FramebufferUpdate ) { + boolean fullUpdateNeeded = false; + int w = rfb.framebufferWidth; + int h = rfb.framebufferHeight; + rfb.writeFramebufferUpdateRequest(0, 0, w, h, !fullUpdateNeeded); + continue; + } long numBytesRead = rfb.getNumBytesRead(); @@ -379,7 +387,11 @@ rfb.readSpeedCheck(); break; case RfbProto.FramebufferUpdate: - + if(msgType == RfbProto.FramebufferUpdate){ + rfb.is.reset(); + break; + } + if (statNumUpdates == viewer.debugStatsExcludeUpdates && !statsRestarted) { resetStats(); @@ -524,9 +536,11 @@ default: throw new Exception("Unknown RFB message type " + msgType); } + + int bufSize = (int)(rfb.getNumBytesRead() - numBytesRead); -// System.out.println("bufSize="+bufSize); + System.out.println("bufSize="+bufSize); // rfb.bufResetSend(bufSize);
--- a/src/myVncProxy/RfbProto.java Mon Aug 08 16:54:34 2011 +0900 +++ b/src/myVncProxy/RfbProto.java Tue Aug 30 05:39:12 2011 +0900 @@ -293,7 +293,7 @@ protocolTightVNC = false; initCapabilities(); } - + // // Negotiate the authentication scheme. //
--- a/src/myVncProxy/VncProxyService.java Mon Aug 08 16:54:34 2011 +0900 +++ b/src/myVncProxy/VncProxyService.java Tue Aug 30 05:39:12 2011 +0900 @@ -64,6 +64,9 @@ int debugStatsExcludeUpdates; int debugStatsMeasureUpdates; + int echoPort = 9999; + + void checkArgs(String[] argv){ if(argv.length > 3){ @@ -199,7 +202,7 @@ void connectAndAuthenticate() throws Exception { acc = new AcceptClient(mainArgs[0]); - geth = new CreateThread(acc); + geth = new CreateThread(acc , echoPort); Thread thread = new Thread(geth); thread.start(); @@ -209,7 +212,9 @@ showConnectionStatus("Connecting to " + host + ", port " + port + "..."); // rfb = new RfbProto(host, port, this); - rfb = new MyRfbProto(host, port); +// rfb = new MyRfbProto(host, port); + rfb = new MyRfbProto(host, port, geth); + showConnectionStatus("Connected to server"); rfb.readVersionMsg(); @@ -355,22 +360,20 @@ encodings[nEncodings++] = preferredEncoding; -/* + if (options.useCopyRect) { encodings[nEncodings++] = RfbProto.EncodingCopyRect; } if (preferredEncoding != RfbProto.EncodingTight) { encodings[nEncodings++] = RfbProto.EncodingTight; } -*/ + if (preferredEncoding != RfbProto.EncodingZRLE) { encodings[nEncodings++] = RfbProto.EncodingZRLE; } -/* if (preferredEncoding != RfbProto.EncodingHextile) { encodings[nEncodings++] = RfbProto.EncodingHextile; } -*/ if (preferredEncoding != RfbProto.EncodingZlib) { encodings[nEncodings++] = RfbProto.EncodingZlib; }