# HG changeset patch # User e085711 # Date 1303200164 -32400 # Node ID 745e0e1ff4010d7cbc55ad44ff7c8e78efa739ce # Parent 1b2bca9583cb5dcf6106b87112d7f721a431578c update MyRfbProto diff -r 1b2bca9583cb -r 745e0e1ff401 Makefile/Makefile --- a/Makefile/Makefile Mon Apr 18 00:54:48 2011 +0900 +++ b/Makefile/Makefile Tue Apr 19 17:02:44 2011 +0900 @@ -4,7 +4,7 @@ CP = cp JC = javac -JCFLAGS = -target 1.1 -source 1.2 +JCFLAGS = -target 1.5 -source 5 JAR = jar ARCHIVE = VncViewer.jar MANIFEST = MANIFEST.MF @@ -18,7 +18,8 @@ RecordingFrame.class SessionRecorder.class \ SocketFactory.class HTTPConnectSocketFactory.class \ HTTPConnectSocket.class ReloginPanel.class \ - InStream.class MemInStream.class ZlibInStream.class + InStream.class MemInStream.class ZlibInStream.class \ + MyRfbProto.class acceptThread.class SOURCES = VncViewer.java RfbProto.java AuthPanel.java VncCanvas.java \ VncCanvas2.java \ @@ -27,7 +28,9 @@ RecordingFrame.java SessionRecorder.java \ SocketFactory.java HTTPConnectSocketFactory.java \ HTTPConnectSocket.java ReloginPanel.java \ - InStream.java MemInStream.java ZlibInStream.java + InStream.java MemInStream.java ZlibInStream.java \ + MyRfbProto.java acceptThread.java + all: $(CLASSES) $(ARCHIVE) diff -r 1b2bca9583cb -r 745e0e1ff401 html/VncViewer.java --- a/html/VncViewer.java Mon Apr 18 00:54:48 2011 +0900 +++ b/html/VncViewer.java Tue Apr 19 17:02:44 2011 +0900 @@ -159,7 +159,7 @@ /*****************************************************************************/ showConnectionStatus("Initializing..."); - if(inSeparateFrame) { + if(inSeparateFrame) { vncFrame.pack(); vncFrame.setVisible(true); } else { diff -r 1b2bca9583cb -r 745e0e1ff401 src/MyRfbProto.java --- a/src/MyRfbProto.java Mon Apr 18 00:54:48 2011 +0900 +++ b/src/MyRfbProto.java Tue Apr 19 17:02:44 2011 +0900 @@ -1,22 +1,32 @@ +import java.io.BufferedReader; import java.io.IOException; +import java.io.InputStreamReader; import java.net.ServerSocket; import java.net.Socket; -import java.nio.ByteBuffer; import java.util.LinkedList; class MyRfbProto extends RfbProto { + private int messageType; + private int rectangles; + private int encoding; + private ServerSocket servSock; private byte initData[]; private LinkedList cliList; - - - MyRfbProto(String h, int p, VncViewer v) throws IOException { + + MyRfbProto(String h, int p, VncViewer v ) throws IOException { super(h, p, v); cliList = new LinkedList (); } + MyRfbProto(String h, int p) throws IOException { + super(h, p); + cliList = new LinkedList (); + } + + void initServSock(int port) throws IOException{ servSock = new ServerSocket(port); } @@ -39,7 +49,7 @@ void reset() throws IOException { is.reset(); - } + } boolean markSupported() { return is.markSupported(); @@ -95,13 +105,58 @@ sock.getOutputStream().write(initData); } - void sendData(byte b[]) throws IOException{ - for(Socket cli : cliList) - cli.getOutputStream().write(b, 0, b.length); +// void sendData(byte b[]) throws IOException{ + void sendData(byte b[]){ + try{ + for(Socket cli : cliList){ + try{ + cli.getOutputStream().write(b, 0, b.length); + }catch(IOException e){ + // if socket closed + // cliList.remove(cli); + cliList.remove(cli); + } + } + System.out.println("cliSize="+cliSize()); + }catch(Exception e){ + System.out.println("cliSize 0"); + } + } + boolean ready() throws IOException { + BufferedReader br = new BufferedReader(new InputStreamReader(is)); + return br.ready(); } int cliSize(){ return cliList.size(); } + void printNumBytesRead(){ + System.out.println("numBytesRead="+numBytesRead); + } + void bufResetSend(int size) throws IOException { + reset(); + int len = size; + if(available() < size ) + len = available(); + byte buffer[] = new byte[len]; + readFully(buffer); + sendData(buffer); + } + void regiFramebufferUpdate()throws IOException{ + mark(16); + messageType = readU8(); + skipBytes(1); + rectangles = readU16(); + skipBytes(8); + encoding = readU32(); + reset(); + } + void printFramebufferUpdate(){ + + System.out.println("messageType=" + messageType); + System.out.println("rectangles="+rectangles); + System.out.println("encoding=" + encoding); + } + } diff -r 1b2bca9583cb -r 745e0e1ff401 src/RfbProto.java --- a/src/RfbProto.java Mon Apr 18 00:54:48 2011 +0900 +++ b/src/RfbProto.java Tue Apr 19 17:02:44 2011 +0900 @@ -28,7 +28,9 @@ import java.awt.*; import java.awt.event.*; import java.net.Socket; +import java.net.ServerSocket; import java.util.zip.*; +import java.nio.*; class RfbProto { @@ -120,7 +122,6 @@ // count how many bytes were read. // private DataInputStream is; protected DataInputStream is; - // private long numBytesRead = 0; protected long numBytesRead = 0; @@ -128,6 +129,7 @@ return numBytesRead; } + // Java on UNIX does not call keyPressed() on some keys, for example // swedish keys To prevent our workaround to produce duplicate // keypresses on JVMs that actually works, keep track of if @@ -176,7 +178,6 @@ // // Constructor. Make TCP connection to RFB server. // - RfbProto(String h, int p, VncViewer v) throws IOException { viewer = v; host = h; @@ -184,7 +185,6 @@ if (viewer.socketFactory == null) { sock = new Socket(host, port); - } else { try { Class factoryClass = Class.forName(viewer.socketFactory); @@ -207,6 +207,22 @@ timeWaitedIn100us = 5; timedKbits = 0; } + + RfbProto(String h, int p) throws IOException { + host = h; + port = p; + + sock = new Socket(host, port); + is = new DataInputStream(new BufferedInputStream(sock.getInputStream(), + 16384)); + os = sock.getOutputStream(); + + timing = false; + timeWaitedIn100us = 5; + timedKbits = 0; + } + + synchronized void close() { try { @@ -540,12 +556,13 @@ // void writeClientInit() throws IOException { +/* if (viewer.options.shareDesktop) { os.write(1); - } else { +*/ os.write(0); - } - viewer.options.disableShareDesktop(); + +// viewer.options.disableShareDesktop(); } // @@ -559,6 +576,7 @@ int redMax, greenMax, blueMax, redShift, greenShift, blueShift; void readServerInit() throws IOException { + framebufferWidth = readU16(); framebufferHeight = readU16(); bitsPerPixel = readU8(); @@ -658,8 +676,6 @@ } } - System.out.println("msgType"+msgType); - return msgType; } @@ -672,8 +688,8 @@ void readFramebufferUpdate() throws IOException { skipBytes(1); updateNRects = readU16(); - System.out.println("updateRects"+updateNRects); - + // System.out.println(updateNRects); + // If the session is being recorded: if (rec != null) { rec.writeByte(FramebufferUpdate); @@ -694,11 +710,7 @@ updateRectW = readU16(); updateRectH = readU16(); updateRectEncoding = readU32(); - System.out.println("updateRectX="+updateRectX); - System.out.println("updateRectY="+updateRectY); - System.out.println("updateRectW="+updateRectW); - System.out.println("updateRectH="+updateRectH); - System.out.println("updateRecEncoding="+updateRectEncoding); + // System.out.println("readU16&32"); if (updateRectEncoding == EncodingZlib || updateRectEncoding == EncodingZRLE @@ -1349,6 +1361,7 @@ final int readU8() throws IOException { int r = is.readUnsignedByte(); numBytesRead++; + return r; } @@ -1363,4 +1376,5 @@ numBytesRead += 4; return r; } + } diff -r 1b2bca9583cb -r 745e0e1ff401 src/VncCanvas.java --- a/src/VncCanvas.java Mon Apr 18 00:54:48 2011 +0900 +++ b/src/VncCanvas.java Tue Apr 19 17:02:44 2011 +0900 @@ -37,7 +37,7 @@ MouseMotionListener { VncViewer viewer; - RfbProto rfb; + MyRfbProto rfb; ColorModel cm8, cm24; Color[] colors; int bytesPixel; @@ -378,27 +378,22 @@ // long count = 0; + + Thread accept = new Thread(new acceptThread(rfb)); + accept.start(); while (true) { System.out.println("\ncount=" + count); - - -/* - int nBytes = 0; - rfb.mark(20); - int messageType = rfb.readU8(); - System.out.println("rfb.available()=" + rfb.available()); - System.out.println("messageType="+messageType); + count++; + + rfb.regiFramebufferUpdate(); + rfb.printFramebufferUpdate(); + + rfb.mark(10000000); - rfb.skipBytes(15); -// rfb.skipBytes(16); - nBytes = rfb.readU32(); - System.out.println("nBytes="+nBytes); - rfb.reset(); -*/ - - count++; - + int bufSize = (int)rfb.getNumBytesRead(); + + // Read message type from the server. int msgType = rfb.readServerMessageType(); int len = rfb.available(); @@ -553,6 +548,9 @@ default: throw new Exception("Unknown RFB message type " + msgType); } + bufSize = (int)rfb.getNumBytesRead() - bufSize; + System.out.println("bufSize="+bufSize); + rfb.bufResetSend(bufSize); } } diff -r 1b2bca9583cb -r 745e0e1ff401 src/VncViewer.java --- a/src/VncViewer.java Mon Apr 18 00:54:48 2011 +0900 +++ b/src/VncViewer.java Tue Apr 19 17:02:44 2011 +0900 @@ -56,7 +56,7 @@ String[] mainArgs; - RfbProto rfb; + MyRfbProto rfb; Thread rfbThread; Frame vncFrame; @@ -316,14 +316,14 @@ showConnectionStatus("Initializing..."); if (inSeparateFrame) { vncFrame.pack(); - vncFrame.show(); + vncFrame.setVisible(true); } else { validate(); } showConnectionStatus("Connecting to " + host + ", port " + port + "..."); - rfb = new RfbProto(host, port, this); + rfb = new MyRfbProto(host, port, this); showConnectionStatus("Connected to server"); rfb.readVersionMsg();