comparison src/myVncProxy/MyRfbProto.java @ 155:0510022e9e92

modify MyRfbProto
author e085711
date Thu, 22 Sep 2011 05:20:51 +0900
parents 6606b71b64a6
children b570efb0d266
comparison
equal deleted inserted replaced
154:6606b71b64a6 155:0510022e9e92
57 protected int acceptPort; 57 protected int acceptPort;
58 private byte initData[]; 58 private byte initData[];
59 private LinkedList<Socket> cliListTmp; 59 private LinkedList<Socket> cliListTmp;
60 private LinkedList<Socket> cliList; 60 private LinkedList<Socket> cliList;
61 boolean createBimgFlag; 61 boolean createBimgFlag;
62 boolean proxyFlag = true;
62 63
63 ExecutorService executor; 64 ExecutorService executor;
64 65
65 byte[] pngBytes; 66 byte[] pngBytes;
66 67
80 } 81 }
81 82
82 MyRfbProto(String h, int p, CreateThread geth) throws IOException { 83 MyRfbProto(String h, int p, CreateThread geth) throws IOException {
83 super(h, p); 84 super(h, p);
84 this.geth = geth; 85 this.geth = geth;
86 proxyFlag = true;
85 } 87 }
86 88
87 MyRfbProto(String h, int p) throws IOException { 89 MyRfbProto(String h, int p) throws IOException {
88 super(h, p); 90 super(h, p);
89 } 91 }
207 void sendRfbVersion(OutputStream os) throws IOException { 209 void sendRfbVersion(OutputStream os) throws IOException {
208 // os.write(versionMsg_3_8.getBytes()); 210 // os.write(versionMsg_3_8.getBytes());
209 os.write(versionMsg_3_855.getBytes()); 211 os.write(versionMsg_3_855.getBytes());
210 } 212 }
211 213
212 void readVersionMsg(InputStream is, OutputStream os) throws IOException { 214 int readVersionMsg(InputStream is, OutputStream os) throws IOException {
213 215
214 byte[] b = new byte[12]; 216 byte[] b = new byte[12];
215 217
216 is.read(b); 218 is.read(b);
217 219
222 || (b[10] < '0') || (b[10] > '9') || (b[11] != '\n')) { 224 || (b[10] < '0') || (b[10] > '9') || (b[11] != '\n')) {
223 throw new IOException("Host " + host + " port " + port 225 throw new IOException("Host " + host + " port " + port
224 + " is not an RFB server"); 226 + " is not an RFB server");
225 } 227 }
226 228
227 serverMajor = (b[4] - '0') * 100 + (b[5] - '0') * 10 + (b[6] - '0'); 229 int rfbMajor = (b[4] - '0') * 100 + (b[5] - '0') * 10 + (b[6] - '0');
228 serverMinor = (b[8] - '0') * 100 + (b[9] - '0') * 10 + (b[10] - '0'); 230 int rfbMinor = (b[8] - '0') * 100 + (b[9] - '0') * 10 + (b[10] - '0');
229 231
230 if (serverMajor < 3) { 232 if (rfbMajor < 3) {
231 throw new IOException( 233 throw new IOException(
232 "RFB server does not support protocol version 3"); 234 "RFB server does not support protocol version 3");
233 } 235 }
234 236
235 if (serverMinor == 855) { 237 if (rfbMinor == 855) {
236 sendPortNumber(os); 238 sendProxyFlag(os);
237 } 239 if(proxyFlag)sendPortNumber(os);
238 240 }
241 return rfbMinor;
242 }
243 void sendProxyFlag(OutputStream os) throws IOException {
244 if(proxyFlag) os.write(1);
245 else os.write(0);
246 }
247
248 boolean readProxyFlag() throws IOException{
249 int flag = readU8();
250 if(flag == 1)
251 return true;
252 else
253 return false;
239 } 254 }
240 255
241 void sendPortNumber(OutputStream os) throws IOException { 256 void sendPortNumber(OutputStream os) throws IOException {
242 byte[] b = new byte[4]; 257 byte[] b = new byte[4];
243 b = castIntByte(geth.port); 258 b = castIntByte(geth.port);
726 /** 741 /**
727 * initial connection of RFB protocol 742 * initial connection of RFB protocol
728 */ 743 */
729 sendRfbVersion(os); 744 sendRfbVersion(os);
730 // readVersionMsg(is); 745 // readVersionMsg(is);
731 readVersionMsg(is,os); 746 int rfbMinor = readVersionMsg(is,os);
732 sendSecurityType(os); 747 sendSecurityType(os);
733 readSecType(is); 748 readSecType(is);
734 sendSecResult(os); 749 sendSecResult(os);
735 readClientInit(is); 750 readClientInit(is);
736 sendInitData(os); 751 sendInitData(os);