comparison src/MyRfbProto.java @ 10:2840c7a259f1

add acceptThread
author e085711
date Sat, 16 Apr 2011 02:21:09 +0900
parents
children a5d73cafc8fe
comparison
equal deleted inserted replaced
9:c0ad3ecdf827 10:2840c7a259f1
1 import java.io.IOException;
2 import java.net.ServerSocket;
3 import java.net.Socket;
4 import java.nio.ByteBuffer;
5 import java.util.LinkedList;
6
7
8 class MyRfbProto extends RfbProto {
9
10 private ServerSocket servSock;
11 private byte initData[];
12 private LinkedList <Socket> cliList;
13 boolean MYVNC = true;
14
15
16 MyRfbProto(String h, int p, VncViewer v) throws IOException {
17 super(h, p, v);
18 cliList = new LinkedList <Socket>();
19 }
20
21 void initServSock(int port) throws IOException{
22 servSock = new ServerSocket(port);
23 }
24
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
37 void mark(int len) throws IOException {
38 is.mark(len);
39 }
40
41 void reset() throws IOException {
42 is.reset();
43 }
44
45 boolean markSupported() {
46 return is.markSupported();
47 }
48
49 void readServerInit() throws IOException {
50
51 mark(255);
52 skipBytes(20);
53 int nlen = readU32();
54 int blen = 20+4+nlen;
55 initData = new byte[blen];
56 reset();
57
58 mark(blen);
59 readFully(initData);
60 reset();
61
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();
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);
80
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;
93 }
94
95 void sendInitData(Socket sock) throws IOException{
96 sock.getOutputStream().write(initData);
97 }
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 }
107
108 }