15
|
1 import java.io.BufferedReader;
|
10
|
2 import java.io.IOException;
|
15
|
3 import java.io.InputStreamReader;
|
10
|
4 import java.net.ServerSocket;
|
|
5 import java.net.Socket;
|
|
6 import java.util.LinkedList;
|
|
7
|
|
8
|
|
9 class MyRfbProto extends RfbProto {
|
|
10
|
18
|
11 private int messageType;
|
|
12 private int rectangles;
|
|
13 private int encoding;
|
|
14
|
10
|
15 private ServerSocket servSock;
|
|
16 private byte initData[];
|
|
17 private LinkedList <Socket> cliList;
|
|
18
|
13
|
19 MyRfbProto(String h, int p, VncViewer v ) throws IOException {
|
10
|
20 super(h, p, v);
|
|
21 cliList = new LinkedList <Socket>();
|
|
22 }
|
|
23
|
13
|
24 MyRfbProto(String h, int p) throws IOException {
|
|
25 super(h, p);
|
|
26 cliList = new LinkedList <Socket>();
|
|
27 }
|
|
28
|
|
29
|
10
|
30 void initServSock(int port) throws IOException{
|
|
31 servSock = new ServerSocket(port);
|
|
32 }
|
|
33
|
|
34 void setSoTimeout(int num) throws IOException {
|
|
35 servSock.setSoTimeout(num);
|
|
36 }
|
|
37
|
|
38 Socket accept() throws IOException {
|
|
39 return servSock.accept();
|
|
40 }
|
|
41
|
|
42 void addSock(Socket sock){
|
|
43 cliList.add(sock);
|
|
44 }
|
|
45
|
|
46 void mark(int len) throws IOException {
|
|
47 is.mark(len);
|
|
48 }
|
|
49
|
|
50 void reset() throws IOException {
|
|
51 is.reset();
|
18
|
52 }
|
10
|
53
|
|
54 boolean markSupported() {
|
|
55 return is.markSupported();
|
|
56 }
|
|
57
|
|
58 void readServerInit() throws IOException {
|
|
59
|
|
60 mark(255);
|
|
61 skipBytes(20);
|
|
62 int nlen = readU32();
|
|
63 int blen = 20+4+nlen;
|
|
64 initData = new byte[blen];
|
|
65 reset();
|
|
66
|
|
67 mark(blen);
|
|
68 readFully(initData);
|
|
69 reset();
|
|
70
|
|
71 framebufferWidth = readU16();
|
|
72 framebufferHeight = readU16();
|
|
73 bitsPerPixel = readU8();
|
|
74 depth = readU8();
|
|
75 bigEndian = (readU8() != 0);
|
|
76 trueColour = (readU8() != 0);
|
|
77 redMax = readU16();
|
|
78 greenMax = readU16();
|
|
79 blueMax = readU16();
|
|
80 redShift = readU8();
|
|
81 greenShift = readU8();
|
|
82 blueShift = readU8();
|
|
83 byte[] pad = new byte[3];
|
|
84 readFully(pad);
|
|
85 int nameLength = readU32();
|
|
86 byte[] name = new byte[nameLength];
|
|
87 readFully(name);
|
|
88 desktopName = new String(name);
|
|
89
|
|
90 // Read interaction capabilities (TightVNC protocol extensions)
|
|
91 if (protocolTightVNC) {
|
|
92 int nServerMessageTypes = readU16();
|
|
93 int nClientMessageTypes = readU16();
|
|
94 int nEncodingTypes = readU16();
|
|
95 readU16();
|
|
96 readCapabilityList(serverMsgCaps, nServerMessageTypes);
|
|
97 readCapabilityList(clientMsgCaps, nClientMessageTypes);
|
|
98 readCapabilityList(encodingCaps, nEncodingTypes);
|
|
99 }
|
|
100
|
|
101 inNormalProtocol = true;
|
|
102 }
|
|
103
|
|
104 void sendInitData(Socket sock) throws IOException{
|
|
105 sock.getOutputStream().write(initData);
|
|
106 }
|
|
107
|
17
|
108 // void sendData(byte b[]) throws IOException{
|
|
109 void sendData(byte b[]){
|
|
110 try{
|
|
111 for(Socket cli : cliList){
|
|
112 try{
|
|
113 cli.getOutputStream().write(b, 0, b.length);
|
|
114 }catch(IOException e){
|
|
115 // if socket closed
|
|
116 // cliList.remove(cli);
|
|
117 cliList.remove(cli);
|
|
118 }
|
|
119 }
|
18
|
120 System.out.println("cliSize="+cliSize());
|
17
|
121 }catch(Exception e){
|
|
122 System.out.println("cliSize 0");
|
|
123 }
|
10
|
124 }
|
15
|
125 boolean ready() throws IOException {
|
|
126 BufferedReader br = new BufferedReader(new InputStreamReader(is));
|
|
127 return br.ready();
|
|
128 }
|
10
|
129
|
|
130 int cliSize(){
|
|
131 return cliList.size();
|
|
132 }
|
15
|
133 void printNumBytesRead(){
|
|
134 System.out.println("numBytesRead="+numBytesRead);
|
|
135 }
|
|
136 void bufResetSend(int size) throws IOException {
|
|
137 reset();
|
|
138 int len = size;
|
|
139 if(available() < size )
|
|
140 len = available();
|
|
141 byte buffer[] = new byte[len];
|
|
142 readFully(buffer);
|
|
143 sendData(buffer);
|
|
144 }
|
18
|
145 void regiFramebufferUpdate()throws IOException{
|
|
146 mark(16);
|
|
147 messageType = readU8();
|
|
148 skipBytes(1);
|
|
149 rectangles = readU16();
|
|
150 skipBytes(8);
|
|
151 encoding = readU32();
|
|
152 reset();
|
15
|
153 }
|
18
|
154 void printFramebufferUpdate(){
|
|
155
|
|
156 System.out.println("messageType=" + messageType);
|
|
157 System.out.println("rectangles="+rectangles);
|
|
158 System.out.println("encoding=" + encoding);
|
|
159 }
|
15
|
160
|
10
|
161
|
|
162 }
|