Mercurial > hg > Members > nobuyasu > tightVNCProxy
comparison src/myVncProxy/MyRfbProto.java @ 61:626cf8cc002c
modify MyRfbProto.java
author | e085711 |
---|---|
date | Sat, 09 Jul 2011 14:08:28 +0900 |
parents | 3ccedb44aaa0 |
children | 7795e2b5d3ef |
comparison
equal
deleted
inserted
replaced
60:3ccedb44aaa0 | 61:626cf8cc002c |
---|---|
33 private int rectY; | 33 private int rectY; |
34 private int rectW; | 34 private int rectW; |
35 private int rectH; | 35 private int rectH; |
36 private int encoding; | 36 private int encoding; |
37 private int zLen; | 37 private int zLen; |
38 private int dataLen; | |
39 | 38 |
40 private ServerSocket servSock; | 39 private ServerSocket servSock; |
41 private int acceptPort; | 40 private int acceptPort; |
42 private byte initData[]; | 41 private byte initData[]; |
43 private LinkedList<Socket> cliListTmp; | 42 private LinkedList<Socket> cliListTmp; |
54 MyRfbProto(String h, int p, VncViewer v) throws IOException { | 53 MyRfbProto(String h, int p, VncViewer v) throws IOException { |
55 super(h, p, v); | 54 super(h, p, v); |
56 cliList = new LinkedList<Socket>(); | 55 cliList = new LinkedList<Socket>(); |
57 cliListTmp = new LinkedList<Socket>(); | 56 cliListTmp = new LinkedList<Socket>(); |
58 createBimgFlag = false; | 57 createBimgFlag = false; |
59 sendThreads = new LinkedList<Thread>(); | 58 // sendThreads = new LinkedList<Thread>(); |
60 // executor = Executors.newCachedThreadPool(); | 59 // executor = Executors.newCachedThreadPool(); |
61 // executor = Executors.newSingleThreadExecutor(); | 60 // executor = Executors.newSingleThreadExecutor(); |
62 } | 61 } |
63 | 62 |
64 MyRfbProto(String h, int p) throws IOException { | 63 MyRfbProto(String h, int p) throws IOException { |
65 super(h, p); | 64 super(h, p); |
66 cliList = new LinkedList<Socket>(); | 65 cliList = new LinkedList<Socket>(); |
67 cliListTmp = new LinkedList<Socket>(); | 66 cliListTmp = new LinkedList<Socket>(); |
68 createBimgFlag = false; | 67 createBimgFlag = false; |
69 sendThreads = new LinkedList<Thread>(); | 68 // sendThreads = new LinkedList<Thread>(); |
70 // executor = Executors.newCachedThreadPool(); | 69 // executor = Executors.newCachedThreadPool(); |
71 // executor = Executors.newSingleThreadExecutor(); | 70 // executor = Executors.newSingleThreadExecutor(); |
72 } | 71 } |
73 | 72 |
74 // over write | 73 // over write |
305 byte buffer[] = new byte[len]; | 304 byte buffer[] = new byte[len]; |
306 readFully(buffer); | 305 readFully(buffer); |
307 sendData(buffer); | 306 sendData(buffer); |
308 } | 307 } |
309 | 308 |
310 void readSendData() throws IOException { | 309 |
311 byte buffer[] = new byte[dataLen]; | |
312 readFully(buffer); | |
313 reset(); | |
314 | |
315 for (Socket cli : cliList) { | |
316 try { | |
317 OutputStream out = cli.getOutputStream(); | |
318 executor.execute(new SendThread(out, buffer)); | |
319 } catch (IOException e) { | |
320 // if client socket closed | |
321 cliListTmp.remove(cli); | |
322 } catch (Exception e) { | |
323 | |
324 } | |
325 | |
326 } | |
327 } | |
328 | |
329 void regiFramebufferUpdate() throws IOException { | 310 void regiFramebufferUpdate() throws IOException { |
330 mark(20); | 311 mark(20); |
331 messageType = readU8(); | 312 messageType = readU8(); |
332 skipBytes(1); | 313 skipBytes(1); |
333 rectangles = readU16(); | 314 rectangles = readU16(); |
339 if (encoding == 16) | 320 if (encoding == 16) |
340 zLen = readU32(); | 321 zLen = readU32(); |
341 reset(); | 322 reset(); |
342 } | 323 } |
343 | 324 |
344 void checkAndMark() throws IOException { | 325 int checkAndMark() throws IOException { |
326 int dataLen; | |
345 switch (encoding) { | 327 switch (encoding) { |
346 case RfbProto.EncodingRaw: | 328 case RfbProto.EncodingRaw: |
347 dataLen = rectW * rectH * 4 + 16; | 329 dataLen = rectW * rectH * 4 + 16; |
348 mark(dataLen); | 330 mark(dataLen); |
349 break; | 331 break; |
350 case RfbProto.EncodingZRLE: | 332 case RfbProto.EncodingZRLE: |
351 dataLen = zLen + 20; | 333 dataLen = zLen + 20; |
352 mark(dataLen); | 334 mark(dataLen); |
353 break; | 335 break; |
354 default: | 336 default: |
337 dataLen = 1000000; | |
355 mark(1000000); | 338 mark(1000000); |
356 } | 339 } |
340 return dataLen; | |
341 } | |
342 void readSendData(int dataLen) throws IOException { | |
343 byte buffer[] = new byte[dataLen]; | |
344 readFully(buffer); | |
345 multicastqueue.put(buffer); | |
346 reset(); | |
347 /* | |
348 for (Socket cli : cliList) { | |
349 try { | |
350 OutputStream out = cli.getOutputStream(); | |
351 executor.execute(new SendThread(out, buffer)); | |
352 } catch (IOException e) { | |
353 // if client socket closed | |
354 cliListTmp.remove(cli); | |
355 } catch (Exception e) { | |
356 | |
357 } | |
358 | |
359 } | |
360 */ | |
361 } | |
362 void sendDataToClient() throws IOException { | |
363 regiFramebufferUpdate(); | |
364 int dataLen = checkAndMark(); | |
365 readSendData(dataLen); | |
357 } | 366 } |
358 | 367 |
359 BufferedImage createBufferedImage(Image img) { | 368 BufferedImage createBufferedImage(Image img) { |
360 BufferedImage bimg = new BufferedImage(img.getWidth(null), | 369 BufferedImage bimg = new BufferedImage(img.getWidth(null), |
361 img.getHeight(null), BufferedImage.TYPE_INT_RGB); | 370 img.getHeight(null), BufferedImage.TYPE_INT_RGB); |