# HG changeset patch # User e085711 # Date 1302888069 -32400 # Node ID 2840c7a259f10e93f21dc12b23366d94400665d7 # Parent c0ad3ecdf827204becf4f227aab0600ddcc39be5 add acceptThread diff -r c0ad3ecdf827 -r 2840c7a259f1 src/MyRfbProto.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/MyRfbProto.java Sat Apr 16 02:21:09 2011 +0900 @@ -0,0 +1,108 @@ +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); + } + + void reset() throws IOException { + is.reset(); + } + + boolean markSupported() { + return is.markSupported(); + } + + void readServerInit() throws IOException { + + mark(255); + skipBytes(20); + int nlen = readU32(); + int blen = 20+4+nlen; + initData = new byte[blen]; + reset(); + + mark(blen); + readFully(initData); + reset(); + + framebufferWidth = readU16(); + framebufferHeight = readU16(); + bitsPerPixel = readU8(); + depth = readU8(); + bigEndian = (readU8() != 0); + trueColour = (readU8() != 0); + redMax = readU16(); + greenMax = readU16(); + blueMax = readU16(); + redShift = readU8(); + greenShift = readU8(); + blueShift = readU8(); + byte[] pad = new byte[3]; + readFully(pad); + int nameLength = readU32(); + byte[] name = new byte[nameLength]; + readFully(name); + desktopName = new String(name); + + // Read interaction capabilities (TightVNC protocol extensions) + if (protocolTightVNC) { + int nServerMessageTypes = readU16(); + int nClientMessageTypes = readU16(); + int nEncodingTypes = readU16(); + readU16(); + readCapabilityList(serverMsgCaps, nServerMessageTypes); + readCapabilityList(clientMsgCaps, nClientMessageTypes); + readCapabilityList(encodingCaps, nEncodingTypes); + } + + inNormalProtocol = true; + } + + void sendInitData(Socket sock) throws IOException{ + 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 c0ad3ecdf827 -r 2840c7a259f1 src/VncCanvas.java --- a/src/VncCanvas.java Sat Apr 16 01:19:18 2011 +0900 +++ b/src/VncCanvas.java Sat Apr 16 02:21:09 2011 +0900 @@ -379,9 +379,11 @@ long count = 0; +/* + Thread accept = new Thread(new acceptThread(rfb)); + accept.start(); +*/ while (true) { - rfb.accept(); - if (rfb.MYVNC) { if (rfb.cliSize() > 0) { diff -r c0ad3ecdf827 -r 2840c7a259f1 src/VncViewer.java --- a/src/VncViewer.java Sat Apr 16 01:19:18 2011 +0900 +++ b/src/VncViewer.java Sat Apr 16 02:21:09 2011 +0900 @@ -56,7 +56,7 @@ String[] mainArgs; -// RfbProto rfb; + // RfbProto rfb; MyRfbProto rfb; Thread rfbThread; @@ -325,7 +325,7 @@ showConnectionStatus("Connecting to " + host + ", port " + port + "..."); -// rfb = new RfbProto(host, port, this); + // rfb = new RfbProto(host, port, this); rfb = new MyRfbProto(host, port, this); showConnectionStatus("Connected to server"); @@ -449,8 +449,16 @@ if (rfb.MYVNC) { rfb.initServSock(5550); - rfb.setSoTimeout(10); -// rfb.accept(); + // rfb.setSoTimeout(10); + + try { + Socket newCli = rfb.accept(); + rfb.sendInitData(newCli); + rfb.addSock(newCli); + } catch (IOException e) { + } + + } System.out.println("Desktop name is " + rfb.desktopName); diff -r c0ad3ecdf827 -r 2840c7a259f1 src/acceptThread.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/acceptThread.java Sat Apr 16 02:21:09 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) { + + } + } + } +}