Mercurial > hg > Members > nobuyasu > tightVNCClient
diff src/myVncClient/MyRfbProto.java @ 17:f9ecb0315303
add package
author | e085711 |
---|---|
date | Sun, 24 Apr 2011 16:55:29 +0900 |
parents | src/MyRfbProto.java@745e0e1ff401 |
children | 4881586aead9 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/myVncClient/MyRfbProto.java Sun Apr 24 16:55:29 2011 +0900 @@ -0,0 +1,163 @@ +package myVncClient; +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.net.ServerSocket; +import java.net.Socket; +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 <Socket> cliList; + + MyRfbProto(String h, int p, VncViewer v ) throws IOException { + super(h, p, v); + cliList = new LinkedList <Socket>(); + } + + MyRfbProto(String h, int p) throws IOException { + super(h, p); + cliList = new LinkedList <Socket>(); + } + + + 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{ + 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); + } + + +}