7
|
1 import java.io.IOException;
|
10
|
2 import java.net.ServerSocket;
|
7
|
3 import java.net.Socket;
|
8
|
4 import java.nio.ByteBuffer;
|
10
|
5 import java.util.LinkedList;
|
8
|
6
|
7
|
7
|
|
8 class MyRfbProto extends RfbProto {
|
8
|
9
|
10
|
10 private ServerSocket servSock;
|
8
|
11 private byte initData[];
|
10
|
12 private LinkedList <Socket> cliList;
|
|
13 boolean MYVNC = true;
|
|
14
|
8
|
15
|
7
|
16 MyRfbProto(String h, int p, VncViewer v) throws IOException {
|
|
17 super(h, p, v);
|
10
|
18 cliList = new LinkedList <Socket>();
|
|
19 }
|
|
20
|
|
21 void initServSock(int port) throws IOException{
|
|
22 servSock = new ServerSocket(port);
|
7
|
23 }
|
|
24
|
10
|
25 void setSoTimeout(int num) throws IOException {
|
|
26 servSock.setSoTimeout(num);
|
|
27 }
|
|
28
|
|
29 Socket accept() throws IOException {
|
|
30 return servSock.accept();
|
|
31 }
|
|
32
|
|
33 void addSock(Socket sock){
|
|
34 cliList.add(sock);
|
|
35 }
|
|
36
|
7
|
37 void mark(int len) throws IOException {
|
|
38 is.mark(len);
|
|
39 }
|
|
40
|
|
41 void reset() throws IOException {
|
|
42 is.reset();
|
|
43 }
|
|
44
|
8
|
45 boolean markSupported() {
|
7
|
46 return is.markSupported();
|
|
47 }
|
8
|
48
|
|
49 void readServerInit() throws IOException {
|
|
50
|
|
51 mark(255);
|
|
52 skipBytes(20);
|
|
53 int nlen = readU32();
|
10
|
54 int blen = 20+4+nlen;
|
|
55 initData = new byte[blen];
|
|
56 reset();
|
|
57
|
|
58 mark(blen);
|
8
|
59 readFully(initData);
|
|
60 reset();
|
|
61
|
7
|
62 framebufferWidth = readU16();
|
|
63 framebufferHeight = readU16();
|
|
64 bitsPerPixel = readU8();
|
|
65 depth = readU8();
|
|
66 bigEndian = (readU8() != 0);
|
|
67 trueColour = (readU8() != 0);
|
|
68 redMax = readU16();
|
|
69 greenMax = readU16();
|
|
70 blueMax = readU16();
|
|
71 redShift = readU8();
|
|
72 greenShift = readU8();
|
|
73 blueShift = readU8();
|
8
|
74 byte[] pad = new byte[3];
|
|
75 readFully(pad);
|
|
76 int nameLength = readU32();
|
|
77 byte[] name = new byte[nameLength];
|
|
78 readFully(name);
|
|
79 desktopName = new String(name);
|
7
|
80
|
8
|
81 // Read interaction capabilities (TightVNC protocol extensions)
|
|
82 if (protocolTightVNC) {
|
|
83 int nServerMessageTypes = readU16();
|
|
84 int nClientMessageTypes = readU16();
|
|
85 int nEncodingTypes = readU16();
|
|
86 readU16();
|
|
87 readCapabilityList(serverMsgCaps, nServerMessageTypes);
|
|
88 readCapabilityList(clientMsgCaps, nClientMessageTypes);
|
|
89 readCapabilityList(encodingCaps, nEncodingTypes);
|
|
90 }
|
|
91
|
|
92 inNormalProtocol = true;
|
7
|
93 }
|
|
94
|
9
|
95 void sendInitData(Socket sock) throws IOException{
|
10
|
96 sock.getOutputStream().write(initData);
|
8
|
97 }
|
10
|
98
|
|
99 void sendData(byte b[]) throws IOException{
|
|
100 for(Socket cli : cliList)
|
|
101 cli.getOutputStream().write(b, 0, b.length);
|
|
102 }
|
|
103
|
|
104 int cliSize(){
|
|
105 return cliList.size();
|
|
106 }
|
7
|
107
|
|
108 }
|