Mercurial > hg > Members > riono > TreeVNC_ja_comment
annotate src/main/java/jp/ac/u_ryukyu/treevnc/TreeRFBProto.java @ 398:b3ef6d14b2b7
Select Mode to start Panel
author | innparusu |
---|---|
date | Mon, 12 Oct 2015 19:50:54 +0900 |
parents | 704ac9e79e25 |
children | 28d67bbfa9f1 |
rev | line source |
---|---|
32 | 1 package jp.ac.u_ryukyu.treevnc; |
28 | 2 |
3 import java.io.IOException; | |
206 | 4 import java.io.OutputStream; |
232
6ee4cdca104c
send value of port and localhost in checkdelay framebufferupdate, and get this.
oc
parents:
231
diff
changeset
|
5 import java.io.UnsupportedEncodingException; |
291 | 6 import java.net.*; |
28 | 7 import java.nio.ByteBuffer; |
109 | 8 import java.nio.ByteOrder; |
369 | 9 import java.util.Enumeration; |
232
6ee4cdca104c
send value of port and localhost in checkdelay framebufferupdate, and get this.
oc
parents:
231
diff
changeset
|
10 import java.util.Iterator; |
28 | 11 import java.util.LinkedList; |
12 import java.util.concurrent.atomic.AtomicInteger; | |
118
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
13 import java.util.zip.DataFormatException; |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
14 import java.util.zip.Deflater; |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
15 import java.util.zip.Inflater; |
150 | 16 |
28 | 17 import com.glavsoft.exceptions.TransportException; |
107 | 18 import com.glavsoft.rfb.client.ClientToServerMessage; |
96 | 19 import com.glavsoft.rfb.encoding.EncodingType; |
264 | 20 import com.glavsoft.rfb.encoding.decoder.FramebufferUpdateRectangle; |
28 | 21 import com.glavsoft.rfb.protocol.Protocol; |
22 import com.glavsoft.rfb.protocol.ProtocolContext; | |
23 import com.glavsoft.transport.Reader; | |
24 import com.glavsoft.transport.Writer; | |
389 | 25 import com.glavsoft.viewer.ConnectionPresenter; |
153 | 26 import com.glavsoft.viewer.ViewerInterface; |
174 | 27 import com.glavsoft.viewer.swing.ConnectionParams; |
28 | 28 |
124 | 29 |
207 | 30 public class TreeRFBProto { |
231 | 31 |
223 | 32 final static int FramebufferUpdateRequest = 3; |
33 final static int CheckDelay = 11; | |
34 protected final static int FramebufferUpdate = 0; | |
35 protected ProtocolContext context; | |
36 private int clients = 0; | |
37 public MulticastQueue<LinkedList<ByteBuffer>> multicastqueue = new MulticastQueue<LinkedList<ByteBuffer>>(); | |
38 private RequestScreenThread rThread; | |
39 public int acceptPort = 0; | |
174 | 40 private String myAddress; |
223 | 41 private long counter = 0; // packet serial number |
118
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
42 public ServerSocket servSock; |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
43 private static final int INFLATE_BUFSIZE = 1024 * 100; |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
44 private Inflater inflater = new Inflater(); |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
45 private Deflater deflater = new Deflater(); |
174 | 46 ViewerInterface viewer; |
341 | 47 private short id = 0; // my tree node id ( = 0 in root ), -1 means no parent |
174 | 48 private TreeVncCommandChannelListener acceptThread; |
49 private TreeRootFinderListener getCast; | |
176 | 50 private CreateConnectionParam cp; |
205
614db20d8fab
try to separate Network management
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
204
diff
changeset
|
51 private TreeVNCNetwork nets = new TreeVNCNetwork(); |
223 | 52 private TreeVncRootSelectionPanel rootSelectionPanel; |
53 private String vncInterface; | |
231 | 54 public LinkedList<TreeVNCNode> nodeList; |
267 | 55 |
56 protected boolean readyReconnect = false; | |
57 private boolean cuiVersion; | |
58 private boolean permitChangeScreen = true; | |
59 private boolean leader; | |
60 private boolean hasViewer = false; | |
61 private boolean normalTermination; | |
62 private boolean isTreeManager; | |
63 public boolean showTreeNode = false; | |
240 | 64 public boolean checkDelay = false; |
241 | 65 public boolean addSerialNum = false; |
257 | 66 public boolean fixingSize = false; |
267 | 67 public boolean filterSingleDisplay = false; |
68 | |
257 | 69 public int frameSizeWidth; |
70 public int frameSizeHeight; | |
71 public int fixingSizeWidth; | |
72 public int fixingSizeHeight; | |
73 | |
306 | 74 private int singleWidth = 0; |
75 private int singleHeight = 0; | |
301 | 76 |
293 | 77 private DatagramSocket socket = null; |
275 | 78 |
306 | 79 private byte[] originalInitData = null; |
345
47e351909227
add stop children sender when change server.
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
342
diff
changeset
|
80 private boolean childrenMulticast = true; |
306 | 81 |
327
293c35aa902b
add error message, add assure stream close, delete firstTime value in TreeRFBProto.
oc
parents:
325
diff
changeset
|
82 public TreeRFBProto(boolean isTreeManager, ViewerInterface viewer) { |
223 | 83 rThread = new RequestScreenThread(this); |
84 nets.setMyRfb(this); | |
85 this.isTreeManager = isTreeManager; | |
327
293c35aa902b
add error message, add assure stream close, delete firstTime value in TreeRFBProto.
oc
parents:
325
diff
changeset
|
86 this.viewer = viewer; |
302 | 87 // this.socket = createSocket(); |
327
293c35aa902b
add error message, add assure stream close, delete firstTime value in TreeRFBProto.
oc
parents:
325
diff
changeset
|
88 if(isTreeManager()) { |
293c35aa902b
add error message, add assure stream close, delete firstTime value in TreeRFBProto.
oc
parents:
325
diff
changeset
|
89 getCast = new TreeRootFinderListener(viewer); |
293c35aa902b
add error message, add assure stream close, delete firstTime value in TreeRFBProto.
oc
parents:
325
diff
changeset
|
90 Thread treeRootFindThread = new Thread(getCast, "tree-root-find-listener"); |
293c35aa902b
add error message, add assure stream close, delete firstTime value in TreeRFBProto.
oc
parents:
325
diff
changeset
|
91 treeRootFindThread.start(); |
293c35aa902b
add error message, add assure stream close, delete firstTime value in TreeRFBProto.
oc
parents:
325
diff
changeset
|
92 } |
223 | 93 } |
94 | |
95 public boolean isTreeManager() { | |
96 return isTreeManager; | |
97 } | |
207 | 98 |
378 | 99 public boolean isAddSerialNum() { |
100 return addSerialNum; | |
101 } | |
102 | |
223 | 103 public ProtocolContext getContext() { |
104 return context; | |
105 } | |
106 | |
107 /** | |
108 * handle new client accept | |
109 * it also handle TreeVNC Command | |
110 * @param os | |
111 * @param is | |
112 * @throws IOException | |
113 * @throws TransportException | |
114 */ | |
384 | 115 public void newClient(final Writer os, final Reader is) { |
223 | 116 final int myId = clients; |
117 final MulticastQueue.Client<LinkedList<ByteBuffer>> c = multicastqueue.newClient(); | |
118 final AtomicInteger writerRunning = new AtomicInteger(); | |
119 writerRunning.set(1); | |
120 /** | |
121 * Timeout thread. If a client is suspended, it has top of queue | |
122 * indefinitely, which caused memory overflow. After the timeout, we | |
123 * poll the queue and discard it. Start long wait if writer is running. | |
124 */ | |
125 final Runnable timer = new Runnable() { | |
126 public void run() { | |
127 int count = 0; | |
128 for (;;) { | |
129 long timeout = 50000 / 8; | |
130 try { | |
131 synchronized (this) { | |
132 int state, flag; | |
133 writerRunning.set(0); | |
134 wait(timeout); | |
135 flag = 0; | |
136 while ((state = writerRunning.get()) == 0) { | |
137 c.poll(); // discard, should be timeout | |
138 count++; | |
139 if (flag == 0) { | |
140 System.out.println("Discarding " + myId | |
141 + " count=" + count); | |
142 flag = 1; | |
143 } | |
144 wait(10); // if this is too short, writer cannot | |
145 // take the poll, if this is too | |
146 // long, memory will overflow... | |
147 } | |
148 if (flag == 1) | |
328
1a2ab6bd5ba3
add function lost child node, remove deadChild nodeList.
oc
parents:
327
diff
changeset
|
149 System.out.println("Resuming " + myId + " count=" + count); |
223 | 150 if (state != 1) { |
151 System.out.println("Client died " + myId); | |
328
1a2ab6bd5ba3
add function lost child node, remove deadChild nodeList.
oc
parents:
327
diff
changeset
|
152 System.out.println("task stop"); |
330 | 153 |
154 String rootHostName = null; | |
155 int rootHostPort = 0; | |
156 String myHostName = null; | |
157 int myHostPort = 0; | |
158 | |
385 | 159 if (!isTreeManager) { |
330 | 160 rootHostName = getConnectionParam().getHostName(); |
161 rootHostPort = getConnectionParam().getPort(); | |
162 myHostName = getMyAddress(); | |
163 myHostPort = getAcceptPort(); | |
385 | 164 TreeVncProtocol echo = new TreeVncProtocol(rootHostName, rootHostPort); |
165 echo.lostChild(myHostName, myHostPort, myId); | |
330 | 166 } |
385 | 167 clients--; |
223 | 168 break; |
169 } | |
170 } | |
171 } catch (InterruptedException e) { | |
325 | 172 e.printStackTrace(); |
173 System.out.println("timer thread interrupt."); | |
223 | 174 } |
175 } | |
176 } | |
177 }; | |
178 new Thread(timer, "timer-discard-multicastqueue").start(); | |
179 /** | |
180 * handle command from lower node | |
181 */ | |
182 final Runnable reader = new Runnable() { | |
122
e2416a246c95
noScreenChange flag on command line ( should be on panel also )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
120
diff
changeset
|
183 public void run() { |
223 | 184 for (;;) { |
185 try { | |
186 final byte b[] = new byte[4096]; | |
187 final int c = is.readByte(b); | |
188 if (c <= 0) | |
189 throw new IOException(); | |
290
c10e0dee7bbb
add READY_SHARE_SOUND msg, add function of receive READY_SHARE_SOUND msg, add sendSound thread.
oc
parents:
287
diff
changeset
|
190 // case of root node. |
223 | 191 if (isTreeManager()) { |
192 if (b[0] == ClientToServerMessage.SERVER_CHANGE_REQUEST) { | |
335 | 193 viewer.setVisible(false); |
223 | 194 if (permitChangeScreen()) { |
195 ByteBuffer buf = ByteBuffer.wrap(b); | |
196 buf.order(ByteOrder.BIG_ENDIAN); | |
325 | 197 buf.get(); // padding |
257 | 198 buf.get(); |
199 short id = buf.getShort(); | |
200 int length = buf.getInt(); | |
325 | 201 if (length == 0) |
202 continue; | |
257 | 203 byte[] byteAddress = new byte[length]; |
204 buf.get(byteAddress); | |
325 | 205 String newHostName = new String(byteAddress, "UTF-8"); |
257 | 206 int frameSizeWidth = buf.getInt(); |
207 int frameSizeHeight = buf.getInt(); | |
340 | 208 int port = buf.getInt(); |
209 System.out.println("Root server change request :" + newHostName + " : " + port); | |
382 | 210 changeVNCServer(viewer, newHostName, port, frameSizeWidth, frameSizeHeight, id, is, os); |
223 | 211 } else { |
212 continue; | |
213 } | |
290
c10e0dee7bbb
add READY_SHARE_SOUND msg, add function of receive READY_SHARE_SOUND msg, add sendSound thread.
oc
parents:
287
diff
changeset
|
214 } else if (b[0] == ClientToServerMessage.READY_SHARE_SOUND) { |
293 | 215 int rtpPort = selectPort(ConnectionParams.DEFAULT_RTP_PORT); |
216 InetAddress hostname = InetAddress.getLocalHost(); | |
217 ReceiveSound receiveSound = new ReceiveSound(socket); | |
218 Thread receiveSoundThread = new Thread(receiveSound, "receive-sound"); | |
219 receiveSoundThread.start(); | |
230 | 220 } else if (b[0] == ClientToServerMessage.CHECK_DELAY_REPLY) { |
221 ByteBuffer buf = ByteBuffer.wrap(b); | |
222 buf.order(ByteOrder.BIG_ENDIAN); | |
234 | 223 buf.getShort(); |
224 Long time = buf.getLong(); | |
225 int port = buf.getInt(); | |
226 int addressLength = buf.getInt(); | |
227 byte[] byteAddress = new byte[addressLength]; | |
228 buf.get(byteAddress); | |
229 String address = new String(byteAddress, "UTF-8"); | |
235 | 230 int nodeNum = getNodeNum(port, address); |
230 | 231 Long delay = System.currentTimeMillis() - time; |
244 | 232 double halfDelay = (double) delay / 2; |
252 | 233 System.out.println(System.currentTimeMillis() + " : receive checkDelay : nodeNum" + nodeNum + ", port : " + port + ", address : " + address + ", delay : " + halfDelay); |
223 | 234 } |
325 | 235 // case of client node. |
223 | 236 } else if (b[0] == ClientToServerMessage.SERVER_CHANGE_REQUEST) { |
295 | 237 ClientToServerMessage serverChangeRequest = new ClientToServerMessage() { |
113
bce2ef0a2e79
use ProtocolContext.sendMessage for upward command
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
112
diff
changeset
|
238 @Override |
bce2ef0a2e79
use ProtocolContext.sendMessage for upward command
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
112
diff
changeset
|
239 public void send(Writer writer) |
bce2ef0a2e79
use ProtocolContext.sendMessage for upward command
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
112
diff
changeset
|
240 throws TransportException { |
325 | 241 writer.write(b, 0, c); |
113
bce2ef0a2e79
use ProtocolContext.sendMessage for upward command
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
112
diff
changeset
|
242 } |
223 | 243 }; |
295 | 244 context.sendMessage(serverChangeRequest); |
301 | 245 } else if (b[0] == ClientToServerMessage.REQUEST_SINGLE_DISPLAY_SIZE) { |
295 | 246 ClientToServerMessage requestSingeDisplayWidth = new ClientToServerMessage() { |
280
9c5874d0f37e
fix adjustHdSizeButton button, this button send REQUEST_SINGLE_DISPLAY_WIDTH
oc
parents:
277
diff
changeset
|
247 @Override |
9c5874d0f37e
fix adjustHdSizeButton button, this button send REQUEST_SINGLE_DISPLAY_WIDTH
oc
parents:
277
diff
changeset
|
248 public void send(Writer writer) |
9c5874d0f37e
fix adjustHdSizeButton button, this button send REQUEST_SINGLE_DISPLAY_WIDTH
oc
parents:
277
diff
changeset
|
249 throws TransportException { |
9c5874d0f37e
fix adjustHdSizeButton button, this button send REQUEST_SINGLE_DISPLAY_WIDTH
oc
parents:
277
diff
changeset
|
250 writer.write(b, 0, c); |
9c5874d0f37e
fix adjustHdSizeButton button, this button send REQUEST_SINGLE_DISPLAY_WIDTH
oc
parents:
277
diff
changeset
|
251 } |
9c5874d0f37e
fix adjustHdSizeButton button, this button send REQUEST_SINGLE_DISPLAY_WIDTH
oc
parents:
277
diff
changeset
|
252 }; |
295 | 253 context.sendMessage(requestSingeDisplayWidth); |
290
c10e0dee7bbb
add READY_SHARE_SOUND msg, add function of receive READY_SHARE_SOUND msg, add sendSound thread.
oc
parents:
287
diff
changeset
|
254 } else if (b[0] == ClientToServerMessage.READY_SHARE_SOUND) { |
c10e0dee7bbb
add READY_SHARE_SOUND msg, add function of receive READY_SHARE_SOUND msg, add sendSound thread.
oc
parents:
287
diff
changeset
|
255 ClientToServerMessage readyShareSound = new ClientToServerMessage() { |
c10e0dee7bbb
add READY_SHARE_SOUND msg, add function of receive READY_SHARE_SOUND msg, add sendSound thread.
oc
parents:
287
diff
changeset
|
256 @Override |
c10e0dee7bbb
add READY_SHARE_SOUND msg, add function of receive READY_SHARE_SOUND msg, add sendSound thread.
oc
parents:
287
diff
changeset
|
257 public void send(Writer writer) |
c10e0dee7bbb
add READY_SHARE_SOUND msg, add function of receive READY_SHARE_SOUND msg, add sendSound thread.
oc
parents:
287
diff
changeset
|
258 throws TransportException { |
325 | 259 writer.write(b, 0, c); |
290
c10e0dee7bbb
add READY_SHARE_SOUND msg, add function of receive READY_SHARE_SOUND msg, add sendSound thread.
oc
parents:
287
diff
changeset
|
260 } |
c10e0dee7bbb
add READY_SHARE_SOUND msg, add function of receive READY_SHARE_SOUND msg, add sendSound thread.
oc
parents:
287
diff
changeset
|
261 }; |
c10e0dee7bbb
add READY_SHARE_SOUND msg, add function of receive READY_SHARE_SOUND msg, add sendSound thread.
oc
parents:
287
diff
changeset
|
262 context.sendMessage(readyShareSound); |
230 | 263 } else if (b[0] == ClientToServerMessage.CHECK_DELAY_REPLY) { |
264 ClientToServerMessage checkDelayReply = new ClientToServerMessage() { | |
265 @Override | |
266 public void send(Writer writer) | |
267 throws TransportException { | |
325 | 268 writer.write(b, 0, c); |
230 | 269 } |
270 }; | |
271 context.sendMessage(checkDelayReply); | |
223 | 272 } |
273 } catch (Exception e) { | |
274 try { | |
275 writerRunning.set(2); | |
276 os.close(); | |
277 is.close(); | |
278 break; | |
367 | 279 } catch (Exception e1) { |
280 System.out.println("cannot close ClientToServerMessage "+e1); | |
281 | |
223 | 282 } |
367 | 283 System.out.println("cannot read ClientToServerMessage "+e); |
284 | |
223 | 285 return; |
286 } | |
325 | 287 |
288 /* | |
289 // あとで検討 | |
290 } catch (TransportException e) { | |
291 | |
292 } | |
293 */ | |
223 | 294 } |
295 } | |
296 }; | |
297 /** | |
298 * send packets to a client (one thread for each client ) | |
299 */ | |
300 Runnable sender = new Runnable() { | |
301 public void run() { | |
302 writerRunning.set(1); | |
303 try { | |
345
47e351909227
add stop children sender when change server.
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
342
diff
changeset
|
304 requestThreadNotify(); // send full screen request via fullScreenRequestThread |
384 | 305 |
223 | 306 // after this, we discard upward packet. |
239 | 307 new Thread(reader, "upward-packet-processing").start(); |
345
47e351909227
add stop children sender when change server.
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
342
diff
changeset
|
308 |
223 | 309 for (;;) { |
310 LinkedList<ByteBuffer> bufs = c.poll(); | |
311 int inputIndex = 0; | |
312 ByteBuffer header = bufs.get(inputIndex); | |
313 if (header == null) | |
314 continue; | |
315 writeToClient(os, bufs, inputIndex); | |
316 writerRunning.set(1); // yes my client is awaking. | |
345
47e351909227
add stop children sender when change server.
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
342
diff
changeset
|
317 if (!childrenMulticast) { |
47e351909227
add stop children sender when change server.
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
342
diff
changeset
|
318 for (;;) { |
47e351909227
add stop children sender when change server.
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
342
diff
changeset
|
319 LinkedList<ByteBuffer> flag = c.poll(); |
47e351909227
add stop children sender when change server.
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
342
diff
changeset
|
320 if (flag.size() == 0) { |
47e351909227
add stop children sender when change server.
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
342
diff
changeset
|
321 break; |
47e351909227
add stop children sender when change server.
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
342
diff
changeset
|
322 } |
47e351909227
add stop children sender when change server.
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
342
diff
changeset
|
323 } |
47e351909227
add stop children sender when change server.
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
342
diff
changeset
|
324 } |
223 | 325 } |
326 } catch (Exception e) { | |
327 try { | |
328 writerRunning.set(2); | |
329 os.close(); | |
330 } catch (IOException e1) { | |
331 System.out.println("root writer close faild :" + e1); | |
332 } | |
333 System.out.println("root writer faild :" + e); | |
334 /* if socket closed cliList.remove(newCli); */ | |
335 } | |
336 } | |
337 public void writeToClient(final Writer os, | |
338 LinkedList<ByteBuffer> bufs, int inputIndex) | |
339 throws TransportException { | |
354 | 340 while (inputIndex < bufs.size()) { |
223 | 341 ByteBuffer b = bufs.get(inputIndex++); |
342 os.write(b.array(), b.position(), b.limit()); | |
343 } | |
344 os.flush(); | |
345 multicastqueue.heapAvailable(); | |
346 } | |
347 }; | |
348 clients++; | |
349 new Thread(sender, "writer-to-lower-node").start(); | |
350 } | |
157
7cea8789387b
thread base command listening loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
153
diff
changeset
|
351 |
122
e2416a246c95
noScreenChange flag on command line ( should be on panel also )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
120
diff
changeset
|
352 public boolean permitChangeScreen() { |
e2416a246c95
noScreenChange flag on command line ( should be on panel also )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
120
diff
changeset
|
353 return permitChangeScreen; |
e2416a246c95
noScreenChange flag on command line ( should be on panel also )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
120
diff
changeset
|
354 } |
223 | 355 |
122
e2416a246c95
noScreenChange flag on command line ( should be on panel also )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
120
diff
changeset
|
356 |
e2416a246c95
noScreenChange flag on command line ( should be on panel also )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
120
diff
changeset
|
357 public void setPermitChangeScreen(boolean v) { |
223 | 358 permitChangeScreen = v; |
122
e2416a246c95
noScreenChange flag on command line ( should be on panel also )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
120
diff
changeset
|
359 } |
223 | 360 |
361 public void requestThreadNotify() { | |
362 rThread.reStart(); | |
363 } | |
364 | |
365 | |
28 | 366 public void setProtocolContext(Protocol workingProtocol) { |
367 context = workingProtocol; | |
368 } | |
29 | 369 |
134
128cce60c43c
where to connect command
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
370 public Socket accept() throws IOException { |
128cce60c43c
where to connect command
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
371 return servSock.accept(); |
128cce60c43c
where to connect command
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
372 } |
31 | 373 |
118
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
374 public int selectPort(int p) { |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
375 int port = p; |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
376 while (true) { |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
377 try { |
134
128cce60c43c
where to connect command
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
378 servSock = new ServerSocket(port); |
128cce60c43c
where to connect command
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
379 acceptPort = port; |
181 | 380 myAddress = "127.0.0.1"; |
207 | 381 nets.getNetworkInterfaces(); |
118
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
382 break; |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
383 } catch (BindException e) { |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
384 port++; |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
385 continue; |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
386 } catch (IOException e) { |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
387 |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
388 } |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
389 } |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
390 System.out.println("accept port = " + port); |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
391 return port; |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
392 } |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
393 |
33
9d3478d11d3b
Add the processing of client
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents:
32
diff
changeset
|
394 |
9d3478d11d3b
Add the processing of client
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents:
32
diff
changeset
|
395 |
331
42fcc9419498
add error message, add lostParent case by fail to connectTo.
oc
parents:
330
diff
changeset
|
396 public void writeFramebufferUpdateRequest(int x, int y, int w, int h, boolean incremental) { |
223 | 397 byte[] b = new byte[10]; |
398 | |
399 b[0] = (byte) FramebufferUpdateRequest; // 3 is FrameBufferUpdateRequest | |
400 b[1] = (byte) (incremental ? 1 : 0); | |
401 b[2] = (byte) ((x >> 8) & 0xff); | |
402 b[3] = (byte) (x & 0xff); | |
403 b[4] = (byte) ((y >> 8) & 0xff); | |
404 b[5] = (byte) (y & 0xff); | |
405 b[6] = (byte) ((w >> 8) & 0xff); | |
406 b[7] = (byte) (w & 0xff); | |
407 b[8] = (byte) ((h >> 8) & 0xff); | |
408 b[9] = (byte) (h & 0xff); | |
409 } | |
33
9d3478d11d3b
Add the processing of client
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents:
32
diff
changeset
|
410 |
223 | 411 public void setViewer(ViewerInterface v) { |
412 viewer = v; | |
413 } | |
414 | |
415 public ViewerInterface getViewer() { | |
416 return viewer; | |
417 } | |
418 | |
419 | |
420 void sendInitData(OutputStream os) throws IOException { | |
421 os.write(context.getInitData()); | |
422 } | |
423 | |
424 | |
425 public void setTerminationType(boolean setType) { | |
426 normalTermination = setType; | |
427 } | |
428 | |
429 public boolean getTerminationType() { | |
430 return normalTermination; | |
431 } | |
43 | 432 |
206 | 433 |
223 | 434 public void addHostToSelectionPanel(int port, String hostname,String myHostName) { |
435 if (rootSelectionPanel != null) { | |
436 rootSelectionPanel.checkBox(Integer.toString(port) + ":" + hostname + ":" + myHostName); | |
437 rootSelectionPanel.setButton(); | |
384 | 438 rootSelectionPanel.visible(); |
223 | 439 } |
440 } | |
43 | 441 |
223 | 442 public void createRootSelectionPanel(CreateConnectionParam cp) { |
398 | 443 rootSelectionPanel = new TreeVncRootSelectionPanel(null); |
223 | 444 rootSelectionPanel.setCp(cp); |
445 } | |
446 | |
134
128cce60c43c
where to connect command
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
447 public void close() { |
223 | 448 // none |
449 } | |
450 | |
451 public int getAcceptPort() { | |
452 return acceptPort; | |
453 } | |
454 | |
455 public boolean getReadyReconnect() { | |
456 return readyReconnect; | |
457 } | |
65 | 458 |
459 | |
223 | 460 public boolean getCuiVersion() { |
461 return cuiVersion; | |
384 | 462 } |
66 | 463 |
223 | 464 public void setCuiVersion(boolean flag) { |
465 cuiVersion = flag; | |
466 } | |
467 | |
468 public void readCheckDelay(Reader reader) throws TransportException { | |
469 | |
470 } | |
134
128cce60c43c
where to connect command
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
471 |
223 | 472 public synchronized void vncConnected(boolean ready) { |
345
47e351909227
add stop children sender when change server.
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
342
diff
changeset
|
473 enableChildrenTransmission(); |
369 | 474 readyReconnect = ready; |
475 if (ready) { | |
476 notifyAll(); | |
223 | 477 } |
345
47e351909227
add stop children sender when change server.
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
342
diff
changeset
|
478 } |
47e351909227
add stop children sender when change server.
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
342
diff
changeset
|
479 |
369 | 480 public void printNetworkInterface() { |
345
47e351909227
add stop children sender when change server.
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
342
diff
changeset
|
481 Socket vncSocket = viewer.getVNCSocket(); |
47e351909227
add stop children sender when change server.
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
342
diff
changeset
|
482 NetworkInterface ni = nets.getInterface(vncSocket); |
47e351909227
add stop children sender when change server.
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
342
diff
changeset
|
483 if (ni!=null) { |
47e351909227
add stop children sender when change server.
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
342
diff
changeset
|
484 vncInterface = ni.getName(); |
369 | 485 System.out.print("VNCNetworkInterface :" + vncInterface); |
370 | 486 if(false) { |
487 Enumeration<InetAddress> addresses = ni.getInetAddresses(); | |
488 while (addresses.hasMoreElements()) { | |
489 InetAddress adr = addresses.nextElement(); | |
490 System.out.print(" " + adr); | |
491 } | |
369 | 492 } |
493 System.out.println(); | |
345
47e351909227
add stop children sender when change server.
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
342
diff
changeset
|
494 } |
47e351909227
add stop children sender when change server.
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
342
diff
changeset
|
495 } |
94
75879c316796
synchronized wait for Rfb initialization in change server.
oc
parents:
89
diff
changeset
|
496 |
223 | 497 public void sendDesktopSizeChange(short id) { |
498 LinkedList<ByteBuffer> desktopSize = new LinkedList<ByteBuffer>(); | |
499 int width = context.getFbWidth(); | |
500 int height = context.getFbHeight(); | |
304 | 501 if (filterSingleDisplay) { |
353 | 502 originalInitData = createOriginalInitData(singleWidth, singleHeight, context.getRemoteDesktopName()); |
350 | 503 // desktopSize.add(new ChengeDesktopSize(singleWidth, singleHeight, EncodingType.INIT_DATA, originalInitData, id).getMessage()); |
504 desktopSize.add(new ChengeDesktopSize(width, height, EncodingType.INIT_DATA, context.getInitData(), id).getMessage()); | |
305 | 505 } else { |
506 desktopSize.add(new ChengeDesktopSize(width, height, EncodingType.INIT_DATA, context.getInitData(), id).getMessage()); | |
304 | 507 } |
380 | 508 if (addSerialNum) { |
509 addSerialNumber(desktopSize); | |
510 } | |
223 | 511 multicastqueue.put(desktopSize); |
512 } | |
98 | 513 |
306 | 514 public byte[] createOriginalInitData(int singleWidth, int singleHeight, String remoteDesktopName) { |
515 TreeVncCommandChannelListener treeVncCommandChannelListener = new TreeVncCommandChannelListener(this, acceptPort); | |
516 byte[] originalInitData = treeVncCommandChannelListener.createOriginalInitData(singleWidth, singleHeight, remoteDesktopName); | |
517 return originalInitData; | |
518 } | |
519 | |
223 | 520 public void addSerialNumber(LinkedList<ByteBuffer> bufs) { |
242 | 521 ByteBuffer serialNum = multicastqueue.allocate(4+8); // addSerialNum flag + SerialNum |
380 | 522 serialNum.putInt(1); |
223 | 523 serialNum.putLong(counter++); |
524 serialNum.flip(); | |
525 bufs.addFirst(serialNum); | |
526 } | |
102
1f7ee648e1f6
inflator in MyRfbProtoProxy should be renew to accept new VNC server socket.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
99
diff
changeset
|
527 |
1f7ee648e1f6
inflator in MyRfbProtoProxy should be renew to accept new VNC server socket.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
99
diff
changeset
|
528 |
1f7ee648e1f6
inflator in MyRfbProtoProxy should be renew to accept new VNC server socket.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
99
diff
changeset
|
529 public void resetDecoder() { |
1f7ee648e1f6
inflator in MyRfbProtoProxy should be renew to accept new VNC server socket.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
99
diff
changeset
|
530 context.resetDecoder(); |
1f7ee648e1f6
inflator in MyRfbProtoProxy should be renew to accept new VNC server socket.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
99
diff
changeset
|
531 } |
1f7ee648e1f6
inflator in MyRfbProtoProxy should be renew to accept new VNC server socket.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
99
diff
changeset
|
532 |
1f7ee648e1f6
inflator in MyRfbProtoProxy should be renew to accept new VNC server socket.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
99
diff
changeset
|
533 public void stopReceiverTask() { |
345
47e351909227
add stop children sender when change server.
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
342
diff
changeset
|
534 if (context!=null) { |
102
1f7ee648e1f6
inflator in MyRfbProtoProxy should be renew to accept new VNC server socket.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
99
diff
changeset
|
535 context.cleanUpSession(null); |
345
47e351909227
add stop children sender when change server.
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
342
diff
changeset
|
536 context.getRfb().clearChildrenTransmission(); |
47e351909227
add stop children sender when change server.
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
342
diff
changeset
|
537 } |
118
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
538 // cleanup zlib decoder for new VNCServer |
202 | 539 if (isTreeManager()) |
118
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
540 inflater = new Inflater(); |
102
1f7ee648e1f6
inflator in MyRfbProtoProxy should be renew to accept new VNC server socket.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
99
diff
changeset
|
541 } |
113
bce2ef0a2e79
use ProtocolContext.sendMessage for upward command
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
112
diff
changeset
|
542 |
345
47e351909227
add stop children sender when change server.
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
342
diff
changeset
|
543 public void clearChildrenTransmission() { |
355 | 544 // discarding does not work now. |
545 | |
546 /* | |
345
47e351909227
add stop children sender when change server.
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
342
diff
changeset
|
547 // set discard flag |
354 | 548 childrenMulticast = false; |
345
47e351909227
add stop children sender when change server.
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
342
diff
changeset
|
549 // put gurd erement to restart multicastqueue. |
354 | 550 multicastqueue.put(new LinkedList<ByteBuffer>()); |
355 | 551 */ |
345
47e351909227
add stop children sender when change server.
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
342
diff
changeset
|
552 } |
47e351909227
add stop children sender when change server.
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
342
diff
changeset
|
553 |
47e351909227
add stop children sender when change server.
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
342
diff
changeset
|
554 public void enableChildrenTransmission() { |
47e351909227
add stop children sender when change server.
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
342
diff
changeset
|
555 // a child senderTask may skip this flag |
47e351909227
add stop children sender when change server.
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
342
diff
changeset
|
556 // durling write waiting. in this case, remaining bufferes are sent. |
47e351909227
add stop children sender when change server.
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
342
diff
changeset
|
557 childrenMulticast = true; |
47e351909227
add stop children sender when change server.
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
342
diff
changeset
|
558 } |
47e351909227
add stop children sender when change server.
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
342
diff
changeset
|
559 |
113
bce2ef0a2e79
use ProtocolContext.sendMessage for upward command
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
112
diff
changeset
|
560 public String getMyAddress() { |
174 | 561 return myAddress; |
113
bce2ef0a2e79
use ProtocolContext.sendMessage for upward command
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
112
diff
changeset
|
562 } |
118
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
563 |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
564 /** |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
565 * gzip byte arrays |
384 | 566 * |
118
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
567 * @param deflater |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
568 * @param inputs |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
569 * byte data[] |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
570 * @param inputIndex |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
571 * @param outputs |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
572 * byte data[] |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
573 * @return byte length in last byte array |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
574 * @throws IOException |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
575 */ |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
576 public int zip(Deflater deflater, LinkedList<ByteBuffer> inputs, |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
577 int inputIndex, LinkedList<ByteBuffer> outputs) throws IOException { |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
578 int len = 0; |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
579 ByteBuffer c1 = multicastqueue.allocate(INFLATE_BUFSIZE); |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
580 while (inputIndex < inputs.size()) { |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
581 ByteBuffer b1 = inputs.get(inputIndex++); |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
582 deflater.setInput(b1.array(), b1.position(), b1.remaining()); |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
583 /** |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
584 * If we finish() stream and reset() it, Deflater start new gzip |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
585 * stream, this makes continuous zlib reader unhappy. if we remove |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
586 * finish(), Deflater.deflate() never flushes its output. The |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
587 * original zlib deflate has flush flag. I'm pretty sure this a kind |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
588 * of bug of Java library. |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
589 */ |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
590 if (inputIndex == inputs.size()) |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
591 deflater.finish(); |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
592 int len1 = 0; |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
593 do { |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
594 len1 = deflater.deflate(c1.array(), c1.position(), |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
595 c1.remaining()); |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
596 if (len1 > 0) { |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
597 len += len1; |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
598 c1.position(c1.position() + len1); |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
599 if (c1.remaining() == 0) { |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
600 c1.flip(); |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
601 outputs.addLast(c1); |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
602 c1 = multicastqueue.allocate(INFLATE_BUFSIZE); |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
603 } |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
604 } |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
605 } while (len1 > 0 || !deflater.needsInput()); // &&!deflater.finished()); |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
606 } |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
607 if (c1.position() != 0) { |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
608 c1.flip(); |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
609 outputs.addLast(c1); |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
610 } |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
611 deflater.reset(); |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
612 return len; |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
613 } |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
614 |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
615 /** |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
616 * gunzip byte arrays |
384 | 617 * |
118
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
618 * @param inflater |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
619 * @param inputs |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
620 * byte data[] |
182 | 621 * @param bytes |
118
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
622 * byte data[] |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
623 * @return number of total bytes |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
624 * @throws IOException |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
625 */ |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
626 public int unzip(Inflater inflater, LinkedList<ByteBuffer> inputs, |
335 | 627 int inputIndex, byte[] bytes, int bufSize) throws DataFormatException { |
182 | 628 int position = 0; |
629 int limit = bytes.length; | |
118
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
630 while (inputIndex < inputs.size()) { |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
631 ByteBuffer input = inputs.get(inputIndex++); |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
632 inflater.setInput(input.array(), input.position(), input.limit()); |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
633 // if (inputIndex==inputs.size()) if inflater/deflater has symmetry, |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
634 // we need this |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
635 // inflater.end(); but this won't work |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
636 do { |
318 | 637 int len0; |
638 len0 = inflater.inflate(bytes, position, limit-position); | |
639 if (len0 > 0) { | |
640 position += len0; | |
641 if (position > limit) throw new DataFormatException(); | |
118
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
642 } |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
643 } while (!inflater.needsInput()); |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
644 } |
182 | 645 return position; |
118
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
646 } |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
647 |
135
ada4d850a820
lostParent and notFoundParenet
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
134
diff
changeset
|
648 /** |
345
47e351909227
add stop children sender when change server.
one@firefly.cr.ie.u-ryukyu.ac.jp
parents:
342
diff
changeset
|
649 * Multicast framebufferUpdate to children. |
135
ada4d850a820
lostParent and notFoundParenet
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
134
diff
changeset
|
650 * read FrameBuffferUpdate. If it is ZLE, make it ZLEE which is self contained compressed packet. |
ada4d850a820
lostParent and notFoundParenet
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
134
diff
changeset
|
651 * put the packet to the multicastqueue. Then normal rendering engine read the same stream using is.reset(). |
ada4d850a820
lostParent and notFoundParenet
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
134
diff
changeset
|
652 * @param dataLen |
ada4d850a820
lostParent and notFoundParenet
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
134
diff
changeset
|
653 * @param reader |
ada4d850a820
lostParent and notFoundParenet
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
134
diff
changeset
|
654 * @throws TransportException |
384 | 655 * @throws UnsupportedEncodingException |
135
ada4d850a820
lostParent and notFoundParenet
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
134
diff
changeset
|
656 */ |
264 | 657 public void readSendData(int dataLen, Reader reader, byte[] bytes, FramebufferUpdateRectangle rect) |
232
6ee4cdca104c
send value of port and localhost in checkdelay framebufferupdate, and get this.
oc
parents:
231
diff
changeset
|
658 throws TransportException, UnsupportedEncodingException { |
118
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
659 LinkedList<ByteBuffer> bufs = new LinkedList<ByteBuffer>(); |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
660 ByteBuffer header = multicastqueue.allocate(16); |
242 | 661 ByteBuffer serial = multicastqueue.allocate(4+8); |
378 | 662 if (!isTreeManager() && addSerialNum) { |
242 | 663 reader.readBytes(serial.array(),0,4+8); |
664 serial.limit(4+8); | |
182 | 665 } |
185 | 666 reader.mark(dataLen); |
118
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
667 reader.readBytes(header.array(), 0, 16); |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
668 header.limit(16); |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
669 if (header.get(0) == FramebufferUpdate) { |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
670 int encoding = header.getInt(12); |
384 | 671 |
118
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
672 if (encoding == EncodingType.ZRLE.getId() |
229
5eb8aa65f387
fix checkdelay number-of-rectangle, and send checkdelay to lower node.
oc
parents:
227
diff
changeset
|
673 || encoding == EncodingType.ZLIB.getId()) { |
186
f76ee760c2d2
dead lock on command line root
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
185
diff
changeset
|
674 // recompress into ZREE |
f76ee760c2d2
dead lock on command line root
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
185
diff
changeset
|
675 // uncompressed result is remain in bytes |
118
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
676 ByteBuffer len = multicastqueue.allocate(4); |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
677 reader.readBytes(len.array(), 0, 4); |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
678 len.limit(4); |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
679 ByteBuffer inputData = multicastqueue.allocate(dataLen - 20); |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
680 reader.readBytes(inputData.array(), 0, inputData.capacity()); |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
681 inputData.limit(dataLen - 20); |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
682 LinkedList<ByteBuffer> inputs = new LinkedList<ByteBuffer>(); |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
683 inputs.add(inputData); |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
684 header.putInt(12, EncodingType.ZRLEE.getId()); // means |
223 | 685 // recompress |
686 // every time | |
118
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
687 // using new Deflecter every time is incompatible with the |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
688 // protocol, clients have to be modified. |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
689 Deflater nDeflater = deflater; // new Deflater(); |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
690 LinkedList<ByteBuffer> out = new LinkedList<ByteBuffer>(); |
380 | 691 try { |
182 | 692 unzip(inflater, inputs, 0, bytes, INFLATE_BUFSIZE); |
118
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
693 // dump32(inputs); |
182 | 694 out.add(ByteBuffer.wrap(bytes)); |
118
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
695 int len2 = zip(nDeflater, out, 0, bufs); |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
696 ByteBuffer blen = multicastqueue.allocate(4); |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
697 blen.putInt(len2); |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
698 blen.flip(); |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
699 bufs.addFirst(blen); |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
700 bufs.addFirst(header); |
380 | 701 if (addSerialNum) { |
702 addSerialNumber(bufs); | |
703 } | |
270 | 704 if (filterSingleDisplay) { |
275 | 705 if (rect.x < singleWidth) { |
270 | 706 multicastqueue.put(bufs); |
707 } | |
708 } else { | |
709 multicastqueue.put(bufs); | |
710 } | |
118
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
711 } catch (IOException e) { |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
712 throw new TransportException(e); |
335 | 713 } catch (DataFormatException e) { |
714 throw new TransportException(e); | |
118
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
715 } |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
716 return; |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
717 } |
233 | 718 |
186
f76ee760c2d2
dead lock on command line root
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
185
diff
changeset
|
719 // ZRLEE is already compressed |
118
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
720 bufs.add(header); |
380 | 721 if (addSerialNum) { |
722 this.addSerialNumber(bufs); | |
723 } | |
118
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
724 if (dataLen > 16) { |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
725 ByteBuffer b = multicastqueue.allocate(dataLen - 16); |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
726 reader.readBytes(b.array(), 0, dataLen - 16); |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
727 b.limit(dataLen - 16); |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
728 bufs.add(b); |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
729 } |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
730 multicastqueue.put(bufs); |
233 | 731 |
118
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
732 return; |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
733 } |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
734 // It may be compressed. We can inflate here to avoid repeating clients |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
735 // decompressing here, |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
736 // but it may generate too many large data. It is better to do it in |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
737 // each client. |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
738 // But we have do inflation for all input data, so we have to do it |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
739 // here. |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
740 } |
124 | 741 |
223 | 742 public void setId(short id) { |
743 this.id = id; | |
744 } | |
169 | 745 |
223 | 746 public short getId() { |
747 return id; | |
748 } | |
169 | 749 |
174 | 750 public void setMyAddress(String myHostName) { |
751 this.myAddress = myHostName; | |
223 | 752 |
174 | 753 } |
754 | |
755 public void setLeader(boolean leader) { | |
756 this.leader = leader; | |
757 } | |
758 | |
759 public boolean isLeader() { | |
760 return leader; | |
761 } | |
762 | |
203 | 763 public void setTreeManager(String intf, TreeManagement clients) { |
223 | 764 nets.setTreeManager(intf, clients); |
174 | 765 } |
223 | 766 |
203 | 767 public TreeManagement getTreeManager(String intf) { |
231 | 768 TreeManagement tm = nets.getTreeManager(intf); |
769 this.nodeList = tm.getList(); | |
770 return tm; | |
174 | 771 } |
772 | |
773 /** | |
290
c10e0dee7bbb
add READY_SHARE_SOUND msg, add function of receive READY_SHARE_SOUND msg, add sendSound thread.
oc
parents:
287
diff
changeset
|
774 * change VNCServer is called when host change. |
382 | 775 * @param vncProxyService |
174 | 776 * @param hostName |
777 * HostAddress | |
359 | 778 * @param width |
382 | 779 * FrameWidth |
359 | 780 * @param height |
382 | 781 * FrameHeight |
351 | 782 * @param newVNCServerId |
382 | 783 * @param is |
784 * @param os | |
174 | 785 */ |
382 | 786 public void changeVNCServer(ViewerInterface vncProxyService, String hostName, int port, int width, int height, short newVNCServerId, Reader is, Writer os) |
325 | 787 throws IOException { |
257 | 788 |
359 | 789 this.frameSizeWidth = width; |
790 this.frameSizeHeight = height; | |
791 singleWidth = frameSizeWidth; | |
792 singleHeight = frameSizeHeight; | |
351 | 793 if (newVNCServerId == -1) { |
339
4713559f5838
if have a parent, send serverChangeRequest and whereToConnect
oc
parents:
335
diff
changeset
|
794 // change to the tree vnc root on other network. |
383 | 795 vncProxyService.changeToDirectConnectedServer(hostName, is, os); |
339
4713559f5838
if have a parent, send serverChangeRequest and whereToConnect
oc
parents:
335
diff
changeset
|
796 return; |
4713559f5838
if have a parent, send serverChangeRequest and whereToConnect
oc
parents:
335
diff
changeset
|
797 } |
342 | 798 // serverChangeの処理 |
369 | 799 vncProxyService.inhelitClients(vncProxyService, hostName, newVNCServerId); |
317 | 800 // after connecting VNC server, rfb send SEND_INIT_DATA command and wakes me up if necessary |
322 | 801 // stop reader stop |
174 | 802 } |
803 | |
804 /** | |
805 * start accepting children | |
806 * run rootFinderListener if necessary | |
807 */ | |
176 | 808 public void createConnectionAndStart(ViewerInterface v) { |
223 | 809 selectPort(ConnectionParams.DEFAULT_VNC_ROOT); |
176 | 810 startTreeVncCommandListener(); |
174 | 811 } |
812 | |
223 | 813 public void startTreeVncCommandListener() { |
176 | 814 acceptThread = new TreeVncCommandChannelListener(this, getAcceptPort()); |
223 | 815 Thread thread = new Thread(acceptThread, "TreeVNC-accept"); |
816 thread.start(); | |
176 | 817 } |
818 | |
174 | 819 public TreeVncCommandChannelListener getAcceptThread() { |
820 return acceptThread; | |
821 } | |
822 | |
176 | 823 public void setConnectionParam(CreateConnectionParam createConnectionParam) { |
824 cp = createConnectionParam; | |
825 } | |
826 | |
827 public CreateConnectionParam getConnectionParam() { | |
828 return cp; | |
829 } | |
830 | |
178
34b7558aeffa
remove TreeTask, StartTreeHandling
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
177
diff
changeset
|
831 public boolean hasViewer() { |
34b7558aeffa
remove TreeTask, StartTreeHandling
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
177
diff
changeset
|
832 return hasViewer; |
34b7558aeffa
remove TreeTask, StartTreeHandling
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
177
diff
changeset
|
833 } |
34b7558aeffa
remove TreeTask, StartTreeHandling
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
177
diff
changeset
|
834 |
34b7558aeffa
remove TreeTask, StartTreeHandling
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
177
diff
changeset
|
835 public void setHasViewer(boolean b) { |
34b7558aeffa
remove TreeTask, StartTreeHandling
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
177
diff
changeset
|
836 hasViewer = b; |
34b7558aeffa
remove TreeTask, StartTreeHandling
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
177
diff
changeset
|
837 } |
34b7558aeffa
remove TreeTask, StartTreeHandling
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
177
diff
changeset
|
838 |
223 | 839 public void setShowTree(boolean showTree) { |
240 | 840 this.showTreeNode = showTree; |
841 } | |
842 | |
843 public void setCheckDelay(boolean checkDelay) { | |
844 this.checkDelay = checkDelay; | |
223 | 845 } |
194 | 846 |
241 | 847 public void setAddSerialNum(boolean addSerialNum) { |
848 this.addSerialNum = addSerialNum; | |
849 } | |
850 | |
235 | 851 public int getNodeNum(int port, String address) { |
232
6ee4cdca104c
send value of port and localhost in checkdelay framebufferupdate, and get this.
oc
parents:
231
diff
changeset
|
852 int nodeNum = 0; |
384 | 853 |
232
6ee4cdca104c
send value of port and localhost in checkdelay framebufferupdate, and get this.
oc
parents:
231
diff
changeset
|
854 for (Iterator<TreeVNCNode> i = nodeList.iterator(); i.hasNext();) { |
6ee4cdca104c
send value of port and localhost in checkdelay framebufferupdate, and get this.
oc
parents:
231
diff
changeset
|
855 TreeVNCNode tvn = (TreeVNCNode)i.next(); |
235 | 856 if (port == tvn.port && address.equals(tvn.hostname)) { |
857 nodeNum = tvn.treeNum; | |
858 return nodeNum; | |
859 } | |
232
6ee4cdca104c
send value of port and localhost in checkdelay framebufferupdate, and get this.
oc
parents:
231
diff
changeset
|
860 } |
6ee4cdca104c
send value of port and localhost in checkdelay framebufferupdate, and get this.
oc
parents:
231
diff
changeset
|
861 return nodeNum; |
6ee4cdca104c
send value of port and localhost in checkdelay framebufferupdate, and get this.
oc
parents:
231
diff
changeset
|
862 } |
241 | 863 |
257 | 864 public void setFixingSize(boolean fixingSize) { |
865 this.fixingSize = fixingSize; | |
256 | 866 } |
267 | 867 |
868 public void setFilterSingleDisplay(boolean filterSingleDisplay) { | |
869 this.filterSingleDisplay = filterSingleDisplay; | |
870 } | |
281 | 871 |
293 | 872 private DatagramSocket createSocket() { |
873 | |
874 try { | |
875 if (socket == null) { | |
876 this.socket = new DatagramSocket(ConnectionParams.DEFAULT_RTP_PORT, InetAddress.getLocalHost()); | |
877 } | |
878 } catch (SocketException e) { | |
879 e.printStackTrace(); | |
880 } catch (UnknownHostException e) { | |
881 e.printStackTrace(); | |
882 } | |
883 return socket; | |
884 } | |
306 | 885 |
886 public void setSingleDisplaySize(int singleWidth, int singleHeight) { | |
887 this.singleWidth = singleWidth; | |
888 this.singleHeight = singleHeight; | |
889 } | |
890 | |
358 | 891 |
306 | 892 public int getSingleWidth() { |
893 return singleWidth; | |
894 } | |
895 | |
896 public int getSingleHeight() { | |
897 return singleHeight; | |
898 } | |
339
4713559f5838
if have a parent, send serverChangeRequest and whereToConnect
oc
parents:
335
diff
changeset
|
899 |
4713559f5838
if have a parent, send serverChangeRequest and whereToConnect
oc
parents:
335
diff
changeset
|
900 public boolean hasParent() { |
4713559f5838
if have a parent, send serverChangeRequest and whereToConnect
oc
parents:
335
diff
changeset
|
901 return id != -1; |
4713559f5838
if have a parent, send serverChangeRequest and whereToConnect
oc
parents:
335
diff
changeset
|
902 } |
384 | 903 |
904 /** | |
905 * server change to directed connected server | |
395
704ac9e79e25
Call startVNCConnectionWithSocket for directedServerChangeReqeust
innparusu
parents:
394
diff
changeset
|
906 * server maybe on the different network |
384 | 907 * so can not in whereToConnect message |
395
704ac9e79e25
Call startVNCConnectionWithSocket for directedServerChangeReqeust
innparusu
parents:
394
diff
changeset
|
908 * reuse dynamic connect socket us a new client |
384 | 909 * reother server exchange socket when serverChangeRequest with id -1 |
910 * @param previousReader | |
911 * @param previousWriter | |
912 */ | |
913 public void exchangeDirectConnectedServer(Reader previousReader, Writer previousWriter) { | |
914 String adr = viewer.getRfb().getMyAddress(); | |
915 ScreenChangeRequest scr = new ScreenChangeRequest(adr, ConnectionParams.DEFAULT_VNC_ROOT, (short) -1, singleWidth, singleHeight); | |
916 try { | |
917 scr.send(previousWriter); | |
918 } catch (TransportException e) { | |
919 e.printStackTrace(); | |
920 return; | |
921 } | |
922 newClient(previousWriter, previousReader); | |
923 } | |
389 | 924 |
925 /** | |
926 * Requested server is connected. stop old connection, replace old connection parameter such as | |
927 * context (PROTOCOL) | |
928 * start new connection and send INIT_DATA | |
929 * @param workingProtocol | |
930 * @param connectionPresenter | |
931 */ | |
932 public synchronized void newVNCConnection(Protocol workingProtocol, ConnectionPresenter connectionPresenter) { | |
933 ProtocolContext previousContext = getContext(); | |
934 stopReceiverTask(); | |
935 setProtocolContext(workingProtocol); | |
936 connectionPresenter.viewer.setConnectionPresenter(connectionPresenter); | |
937 connectionPresenter.viewer.getConnectionPresenter().addModel("ConnectionParamsModel", connectionPresenter.getConnectionParams()); | |
938 if (previousContext != null && isTreeManager() && hasParent()) { | |
939 Reader previousReader = previousContext.getReader(); | |
940 Writer previousWriter = previousContext.getWriter(); | |
941 exchangeDirectConnectedServer(previousReader, previousWriter); | |
942 } | |
943 enableChildrenTransmission(); | |
944 printNetworkInterface(); | |
945 sendDesktopSizeChange(connectionPresenter.getReconnectingId()); | |
946 } | |
240 | 947 } |