# HG changeset patch # User e085711 # Date 1302954024 -32400 # Node ID 9c7eab50c7088d26c9317d3377837741a01f89d6 # Parent 2237c4a0642744c6e61abbba3ff790dc1f36fae6 update MyRfbProto. add acceptThread diff -r 2237c4a06427 -r 9c7eab50c708 src/MyRfbProto.java --- a/src/MyRfbProto.java Sat Apr 16 00:22:17 2011 +0900 +++ b/src/MyRfbProto.java Sat Apr 16 20:40:24 2011 +0900 @@ -1,16 +1,39 @@ import java.io.IOException; +import java.net.ServerSocket; import java.net.Socket; import java.nio.ByteBuffer; +import java.util.LinkedList; class MyRfbProto extends RfbProto { + private ServerSocket servSock; private byte initData[]; + private LinkedList cliList; + boolean MYVNC = true; + MyRfbProto(String h, int p, VncViewer v) throws IOException { super(h, p, v); + cliList = new LinkedList (); + } + + void initServSock(int port) throws IOException{ + servSock = new ServerSocket(port); } + void setSoTimeout(int num) throws IOException { + servSock.setSoTimeout(num); + } + + Socket accept() throws IOException { + return servSock.accept(); + } + + void addSock(Socket sock){ + cliList.add(sock); + } + void mark(int len) throws IOException { is.mark(len); } @@ -28,7 +51,11 @@ mark(255); skipBytes(20); int nlen = readU32(); - initData = new byte[20+4+nlen]; + int blen = 20+4+nlen; + initData = new byte[blen]; + reset(); + + mark(blen); readFully(initData); reset(); @@ -66,8 +93,16 @@ } void sendInitData(Socket sock) throws IOException{ - sock.getOutputStream().write(initData); + sock.getOutputStream().write(initData); } - + + void sendData(byte b[]) throws IOException{ + for(Socket cli : cliList) + cli.getOutputStream().write(b, 0, b.length); + } + + int cliSize(){ + return cliList.size(); + } } diff -r 2237c4a06427 -r 9c7eab50c708 src/VncCanvas.java --- a/src/VncCanvas.java Sat Apr 16 00:22:17 2011 +0900 +++ b/src/VncCanvas.java Sat Apr 16 20:40:24 2011 +0900 @@ -429,6 +429,9 @@ int rx = rfb.updateRectX, ry = rfb.updateRectY; int rw = rfb.updateRectW, rh = rfb.updateRectH; + System.out.println("rx="+rx+" ry="+ry+" rw="+rw+" rh="+rh); + + if (rfb.updateRectEncoding == rfb.EncodingLastRect) break; diff -r 2237c4a06427 -r 9c7eab50c708 src/VncViewer.java --- a/src/VncViewer.java Sat Apr 16 00:22:17 2011 +0900 +++ b/src/VncViewer.java Sat Apr 16 20:40:24 2011 +0900 @@ -157,26 +157,13 @@ vncContainer.add(buttonPanel); } - /*****************************************************************************/ +/*****************************************************************************/ vncFrame.pack(); vncFrame.setVisible(true); try { rfb = new MyRfbProto(host, port, this); - - rfb.framebufferWidth = 1680; - rfb.framebufferHeight = 1050; - rfb.bitsPerPixel = 32; - rfb.depth = 32; - rfb.bigEndian = false; - rfb.trueColour = true; - rfb.redMax = 255; - rfb.greenMax = 255; - rfb.blueMax = 255; - rfb.redShift = 16; - rfb.greenShift = 8; - rfb.blueShift = 0; - rfb.inNormalProtocol = true; - + rfb.readServerInit(); + createCanvas(0, 0); } catch (IOException e) { System.out.println("Socket error"); @@ -186,7 +173,7 @@ gbc.weightx = 1.0; gbc.weighty = 1.0; - if (inSeparateFrame) { + if (inSeparateFrame) { // Create a panel which itself is resizeable and can hold // non-resizeable VncCanvas component at the top left corner. @@ -215,47 +202,9 @@ validate(); } - // */ - /*****************************************************************************/ +/*****************************************************************************/ - /* - * - * try { connectAndAuthenticate(); doProtocolInitialisation(); - * - * // FIXME: Use auto-scaling not only in a separate frame. if - * (options.autoScale && inSeparateFrame) { Dimension screenSize; try { - * screenSize = vncContainer.getToolkit().getScreenSize(); } catch - * (Exception e) { screenSize = new Dimension(0, 0); } - * createCanvas(screenSize.width - 32, screenSize.height - 32); } else { - * createCanvas(0, 0); } - * - * gbc.weightx = 1.0; gbc.weighty = 1.0; - * - * if (inSeparateFrame) { - * - * // Create a panel which itself is resizeable and can hold // - * non-resizeable VncCanvas component at the top left corner. Panel - * canvasPanel = new Panel(); canvasPanel.setLayout(new - * FlowLayout(FlowLayout.LEFT, 0, 0)); canvasPanel.add(vc); - * - * // Create a ScrollPane which will hold a panel with VncCanvas // - * inside. desktopScrollPane = new - * ScrollPane(ScrollPane.SCROLLBARS_AS_NEEDED); gbc.fill = - * GridBagConstraints.BOTH; gridbag.setConstraints(desktopScrollPane, - * gbc); desktopScrollPane.add(canvasPanel); - * - * // Finally, add our ScrollPane to the Frame window. - * vncFrame.add(desktopScrollPane); vncFrame.setTitle(rfb.desktopName); - * vncFrame.pack(); vc.resizeDesktopFrame(); - * - * } else { - * - * // Just add the VncCanvas component to the Applet. - * gridbag.setConstraints(vc, gbc); add(vc); validate(); - * - * } - */ - + try { if (showControls) diff -r 2237c4a06427 -r 9c7eab50c708 src/acceptThread.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/acceptThread.java Sat Apr 16 20:40:24 2011 +0900 @@ -0,0 +1,22 @@ +import java.net.Socket; +import java.io.IOException; + +public class acceptThread implements Runnable { + MyRfbProto rfb; + + acceptThread(MyRfbProto _rfb) { + rfb = _rfb; + } + + public void run() { + while (true) { + try { + Socket newCli = rfb.accept(); + rfb.sendInitData(newCli); + rfb.addSock(newCli); + } catch (IOException e) { + + } + } + } +}