annotate src/MyRfbProto.java @ 13:a5d73cafc8fe

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