annotate src/MyRfbProto.java @ 18:ccad9909e0e2

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