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