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