Mercurial > hg > Applications > TreeVNC
annotate src/main/java/jp/ac/u_ryukyu/treevnc/TreeRFBProto.java @ 244:8cc07511b1d5
small fix checkDelay
author | oc |
---|---|
date | Thu, 16 Oct 2014 11:03:28 +0900 |
parents | 0ed7719c1800 |
children | 1819e9c5d0cd |
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; |
118
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
6 import java.net.BindException; |
201 | 7 import java.net.NetworkInterface; |
118
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
8 import java.net.ServerSocket; |
28 | 9 import java.net.Socket; |
174 | 10 import java.net.UnknownHostException; |
28 | 11 import java.nio.ByteBuffer; |
109 | 12 import java.nio.ByteOrder; |
232
6ee4cdca104c
send value of port and localhost in checkdelay framebufferupdate, and get this.
oc
parents:
231
diff
changeset
|
13 import java.util.Iterator; |
28 | 14 import java.util.LinkedList; |
15 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
|
16 import java.util.zip.DataFormatException; |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
17 import java.util.zip.Deflater; |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
18 import java.util.zip.Inflater; |
150 | 19 |
28 | 20 import com.glavsoft.exceptions.TransportException; |
107 | 21 import com.glavsoft.rfb.client.ClientToServerMessage; |
96 | 22 import com.glavsoft.rfb.encoding.EncodingType; |
28 | 23 import com.glavsoft.rfb.protocol.Protocol; |
24 import com.glavsoft.rfb.protocol.ProtocolContext; | |
25 import com.glavsoft.transport.Reader; | |
26 import com.glavsoft.transport.Writer; | |
153 | 27 import com.glavsoft.viewer.ViewerInterface; |
174 | 28 import com.glavsoft.viewer.swing.ConnectionParams; |
28 | 29 |
124 | 30 |
207 | 31 public class TreeRFBProto { |
231 | 32 |
223 | 33 final static int FramebufferUpdateRequest = 3; |
34 final static int CheckDelay = 11; | |
35 protected final static int FramebufferUpdate = 0; | |
36 protected ProtocolContext context; | |
37 private int clients = 0; | |
38 public MulticastQueue<LinkedList<ByteBuffer>> multicastqueue = new MulticastQueue<LinkedList<ByteBuffer>>(); | |
39 private RequestScreenThread rThread; | |
40 public int acceptPort = 0; | |
174 | 41 private String myAddress; |
223 | 42 protected boolean readyReconnect = false; |
43 private boolean cuiVersion; | |
44 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
|
45 public ServerSocket servSock; |
123 | 46 private boolean permitChangeScreen = true; |
118
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
47 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
|
48 private Inflater inflater = new Inflater(); |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
49 private Deflater deflater = new Deflater(); |
174 | 50 ViewerInterface viewer; |
223 | 51 private short id; // my tree node id ( = 0 in root ) |
174 | 52 private boolean leader; |
53 private TreeVncCommandChannelListener acceptThread; | |
177 | 54 private boolean firstTime = true; |
174 | 55 private TreeRootFinderListener getCast; |
176 | 56 private CreateConnectionParam cp; |
178
34b7558aeffa
remove TreeTask, StartTreeHandling
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
177
diff
changeset
|
57 private boolean hasViewer = false; |
223 | 58 public boolean showTreeNode = false; |
186
f76ee760c2d2
dead lock on command line root
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
185
diff
changeset
|
59 private boolean reconnecting; |
187 | 60 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
|
61 private TreeVNCNetwork nets = new TreeVNCNetwork(); |
223 | 62 private boolean normalTermination; |
63 private TreeVncRootSelectionPanel rootSelectionPanel; | |
64 private boolean isTreeManager; | |
65 private String vncInterface; | |
231 | 66 public LinkedList<TreeVNCNode> nodeList; |
240 | 67 public boolean checkDelay = false; |
241 | 68 public boolean addSerialNum = false; |
231 | 69 |
223 | 70 |
71 public TreeRFBProto(boolean isTreeManager) { | |
72 rThread = new RequestScreenThread(this); | |
73 nets.setMyRfb(this); | |
74 this.isTreeManager = isTreeManager; | |
75 } | |
76 | |
77 public boolean isTreeManager() { | |
78 return isTreeManager; | |
79 } | |
207 | 80 |
223 | 81 public ProtocolContext getContext() { |
82 return context; | |
83 } | |
84 | |
85 /** | |
86 * handle new client accept | |
87 * it also handle TreeVNC Command | |
88 * @param acceptThread | |
89 * @param newCli | |
90 * @param os | |
91 * @param is | |
92 * @throws IOException | |
93 * @throws TransportException | |
94 */ | |
95 public void newClient(final Socket newCli,final Writer os, final Reader is) { | |
124 | 96 |
223 | 97 final int myId = clients; |
98 final MulticastQueue.Client<LinkedList<ByteBuffer>> c = multicastqueue.newClient(); | |
99 final AtomicInteger writerRunning = new AtomicInteger(); | |
100 writerRunning.set(1); | |
101 /** | |
102 * Timeout thread. If a client is suspended, it has top of queue | |
103 * indefinitely, which caused memory overflow. After the timeout, we | |
104 * poll the queue and discard it. Start long wait if writer is running. | |
105 */ | |
106 final Runnable timer = new Runnable() { | |
107 public void run() { | |
108 int count = 0; | |
109 for (;;) { | |
110 long timeout = 50000 / 8; | |
111 try { | |
112 synchronized (this) { | |
113 int state, flag; | |
114 writerRunning.set(0); | |
115 wait(timeout); | |
116 flag = 0; | |
117 while ((state = writerRunning.get()) == 0) { | |
118 c.poll(); // discard, should be timeout | |
119 count++; | |
120 if (flag == 0) { | |
121 System.out.println("Discarding " + myId | |
122 + " count=" + count); | |
123 flag = 1; | |
124 } | |
125 wait(10); // if this is too short, writer cannot | |
126 // take the poll, if this is too | |
127 // long, memory will overflow... | |
128 } | |
129 if (flag == 1) | |
130 System.out.println("Resuming " + myId | |
131 + " count=" + count); | |
132 if (state != 1) { | |
133 System.out.println("Client died " + myId); | |
134 break; | |
135 } | |
136 } | |
137 } catch (InterruptedException e) { | |
138 } | |
139 } | |
140 } | |
141 }; | |
142 new Thread(timer, "timer-discard-multicastqueue").start(); | |
143 /** | |
144 * handle command from lower node | |
145 */ | |
146 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
|
147 public void run() { |
223 | 148 for (;;) { |
149 try { | |
150 final byte b[] = new byte[4096]; | |
151 final int c = is.readByte(b); | |
152 if (c <= 0) | |
153 throw new IOException(); | |
154 if (isTreeManager()) { | |
155 if (b[0] == ClientToServerMessage.SERVER_CHANGE_REQUEST) { | |
156 if (permitChangeScreen()) { | |
157 ByteBuffer buf = ByteBuffer.wrap(b); | |
158 buf.order(ByteOrder.BIG_ENDIAN); | |
159 short id = buf.getShort(2); | |
160 int length = buf.getInt(4); | |
161 if (length == 0) | |
162 continue; | |
163 String newHostName = new String(b, 8, length); | |
164 System.out.println("Root server change request :" + newHostName); | |
165 // please remove these numbers. | |
166 if (viewer != null) { | |
230 | 167 changeVNCServer(viewer, newHostName, 3200, 1980, id); |
223 | 168 } |
169 } else { | |
170 continue; | |
171 } | |
230 | 172 } else if (b[0] == ClientToServerMessage.CHECK_DELAY_REPLY) { |
173 ByteBuffer buf = ByteBuffer.wrap(b); | |
174 buf.order(ByteOrder.BIG_ENDIAN); | |
233 | 175 // getNodeNum(port, hostname, localhostname); |
234 | 176 buf.getShort(); |
177 Long time = buf.getLong(); | |
178 int port = buf.getInt(); | |
179 int addressLength = buf.getInt(); | |
180 byte[] byteAddress = new byte[addressLength]; | |
181 buf.get(byteAddress); | |
182 String address = new String(byteAddress, "UTF-8"); | |
235 | 183 int nodeNum = getNodeNum(port, address); |
230 | 184 Long delay = System.currentTimeMillis() - time; |
244 | 185 double halfDelay = (double) delay / 2; |
186 System.out.println("nodeNum" + nodeNum + ", port = " + port + ", address = " + address + ", delay = " + halfDelay); | |
239 | 187 |
188 // checkNodeNum(); | |
189 // readSendData(check); | |
190 | |
223 | 191 } |
192 } else if (b[0] == ClientToServerMessage.SERVER_CHANGE_REQUEST) { | |
193 ClientToServerMessage sc = new ClientToServerMessage() { | |
113
bce2ef0a2e79
use ProtocolContext.sendMessage for upward command
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
112
diff
changeset
|
194 @Override |
bce2ef0a2e79
use ProtocolContext.sendMessage for upward command
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
112
diff
changeset
|
195 public void send(Writer writer) |
bce2ef0a2e79
use ProtocolContext.sendMessage for upward command
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
112
diff
changeset
|
196 throws TransportException { |
bce2ef0a2e79
use ProtocolContext.sendMessage for upward command
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
112
diff
changeset
|
197 writer.write(b,0,c); |
bce2ef0a2e79
use ProtocolContext.sendMessage for upward command
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
112
diff
changeset
|
198 } |
223 | 199 }; |
200 context.sendMessage(sc); | |
230 | 201 } else if (b[0] == ClientToServerMessage.CHECK_DELAY_REPLY) { |
202 ClientToServerMessage checkDelayReply = new ClientToServerMessage() { | |
203 @Override | |
204 public void send(Writer writer) | |
205 throws TransportException { | |
206 writer.write(b,0,c); | |
207 } | |
208 }; | |
209 context.sendMessage(checkDelayReply); | |
223 | 210 } |
211 } catch (Exception e) { | |
212 try { | |
213 writerRunning.set(2); | |
214 os.close(); | |
215 is.close(); | |
216 break; | |
217 } catch (IOException e1) { | |
218 } catch (TransportException e1) { | |
219 e1.printStackTrace(); | |
220 } | |
221 return; | |
222 } | |
223 } | |
224 } | |
107 | 225 |
223 | 226 }; |
227 /** | |
228 * send packets to a client (one thread for each client ) | |
229 */ | |
230 Runnable sender = new Runnable() { | |
231 public void run() { | |
232 writerRunning.set(1); | |
233 try { | |
234 requestThreadNotify(); | |
239 | 235 |
223 | 236 // after this, we discard upward packet. |
239 | 237 new Thread(reader, "upward-packet-processing").start(); |
238 | |
223 | 239 for (;;) { |
240 LinkedList<ByteBuffer> bufs = c.poll(); | |
239 | 241 |
223 | 242 int inputIndex = 0; |
243 ByteBuffer header = bufs.get(inputIndex); | |
244 if (header == null) | |
245 continue; | |
246 writeToClient(os, bufs, inputIndex); | |
247 writerRunning.set(1); // yes my client is awaking. | |
248 } | |
249 } catch (Exception e) { | |
250 try { | |
251 writerRunning.set(2); | |
252 os.close(); | |
253 } catch (IOException e1) { | |
254 System.out.println("root writer close faild :" + e1); | |
255 } | |
256 System.out.println("root writer faild :" + e); | |
257 /* if socket closed cliList.remove(newCli); */ | |
258 } | |
259 } | |
28 | 260 |
223 | 261 public void writeToClient(final Writer os, |
262 LinkedList<ByteBuffer> bufs, int inputIndex) | |
263 throws TransportException { | |
264 while (inputIndex < bufs.size()) { | |
265 ByteBuffer b = bufs.get(inputIndex++); | |
266 os.write(b.array(), b.position(), b.limit()); | |
267 } | |
268 os.flush(); | |
269 bufs = null; | |
270 multicastqueue.heapAvailable(); | |
271 } | |
272 }; | |
273 clients++; | |
274 new Thread(sender, "writer-to-lower-node").start(); | |
28 | 275 |
223 | 276 } |
157
7cea8789387b
thread base command listening loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
153
diff
changeset
|
277 |
223 | 278 |
122
e2416a246c95
noScreenChange flag on command line ( should be on panel also )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
120
diff
changeset
|
279 |
e2416a246c95
noScreenChange flag on command line ( should be on panel also )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
120
diff
changeset
|
280 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
|
281 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
|
282 } |
223 | 283 |
122
e2416a246c95
noScreenChange flag on command line ( should be on panel also )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
120
diff
changeset
|
284 |
e2416a246c95
noScreenChange flag on command line ( should be on panel also )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
120
diff
changeset
|
285 public void setPermitChangeScreen(boolean v) { |
223 | 286 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
|
287 } |
223 | 288 |
289 public void requestThreadNotify() { | |
290 rThread.reStart(); | |
291 } | |
292 | |
293 | |
28 | 294 public void setProtocolContext(Protocol workingProtocol) { |
295 context = workingProtocol; | |
296 } | |
29 | 297 |
134
128cce60c43c
where to connect command
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
298 public Socket accept() throws IOException { |
128cce60c43c
where to connect command
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
299 return servSock.accept(); |
128cce60c43c
where to connect command
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
300 } |
31 | 301 |
118
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
302 public int selectPort(int p) { |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
303 int port = p; |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
304 while (true) { |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
305 try { |
134
128cce60c43c
where to connect command
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
306 servSock = new ServerSocket(port); |
128cce60c43c
where to connect command
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
307 acceptPort = port; |
181 | 308 myAddress = "127.0.0.1"; |
207 | 309 nets.getNetworkInterfaces(); |
118
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
310 break; |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
311 } catch (BindException e) { |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
312 port++; |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
313 continue; |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
314 } catch (IOException e) { |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
315 |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
316 } |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
317 } |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
318 System.out.println("accept port = " + port); |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
319 return port; |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
320 } |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
321 |
33
9d3478d11d3b
Add the processing of client
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents:
32
diff
changeset
|
322 |
9d3478d11d3b
Add the processing of client
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents:
32
diff
changeset
|
323 |
223 | 324 public void writeFramebufferUpdateRequest(int x, int y, int w, int h, |
325 boolean incremental) throws TransportException { | |
326 byte[] b = new byte[10]; | |
327 | |
328 b[0] = (byte) FramebufferUpdateRequest; // 3 is FrameBufferUpdateRequest | |
329 b[1] = (byte) (incremental ? 1 : 0); | |
330 b[2] = (byte) ((x >> 8) & 0xff); | |
331 b[3] = (byte) (x & 0xff); | |
332 b[4] = (byte) ((y >> 8) & 0xff); | |
333 b[5] = (byte) (y & 0xff); | |
334 b[6] = (byte) ((w >> 8) & 0xff); | |
335 b[7] = (byte) (w & 0xff); | |
336 b[8] = (byte) ((h >> 8) & 0xff); | |
337 b[9] = (byte) (h & 0xff); | |
338 } | |
33
9d3478d11d3b
Add the processing of client
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents:
32
diff
changeset
|
339 |
223 | 340 public void setViewer(ViewerInterface v) { |
341 viewer = v; | |
342 } | |
343 | |
344 public ViewerInterface getViewer() { | |
345 return viewer; | |
346 } | |
347 | |
348 | |
349 void sendInitData(OutputStream os) throws IOException { | |
350 os.write(context.getInitData()); | |
351 } | |
352 | |
353 | |
354 public void setTerminationType(boolean setType) { | |
355 normalTermination = setType; | |
356 } | |
357 | |
358 public boolean getTerminationType() { | |
359 return normalTermination; | |
360 } | |
43 | 361 |
206 | 362 |
223 | 363 public void addHostToSelectionPanel(int port, String hostname,String myHostName) { |
364 if (rootSelectionPanel != null) { | |
365 rootSelectionPanel.checkBox(Integer.toString(port) + ":" + hostname + ":" + myHostName); | |
366 rootSelectionPanel.setButton(); | |
367 rootSelectionPanel.visible(); | |
368 } | |
369 } | |
43 | 370 |
223 | 371 public void createRootSelectionPanel(CreateConnectionParam cp) { |
372 rootSelectionPanel = new TreeVncRootSelectionPanel(); | |
373 rootSelectionPanel.setCp(cp); | |
374 } | |
375 | |
134
128cce60c43c
where to connect command
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
376 public void close() { |
223 | 377 // none |
378 } | |
379 | |
380 public int getAcceptPort() { | |
381 return acceptPort; | |
382 } | |
383 | |
384 public boolean getReadyReconnect() { | |
385 return readyReconnect; | |
386 } | |
65 | 387 |
388 | |
223 | 389 public boolean getCuiVersion() { |
390 return cuiVersion; | |
391 } | |
66 | 392 |
223 | 393 public void setCuiVersion(boolean flag) { |
394 cuiVersion = flag; | |
395 } | |
396 | |
397 public void readCheckDelay(Reader reader) throws TransportException { | |
398 | |
399 } | |
134
128cce60c43c
where to connect command
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
133
diff
changeset
|
400 |
223 | 401 public synchronized void vncConnected(boolean ready) { |
402 if (ready && reconnecting) { | |
403 Socket vncSocket = viewer.getVNCSocket(); | |
404 NetworkInterface ni = nets.getInterface(vncSocket); | |
405 if (ni!=null) { | |
406 vncInterface = ni.getName(); | |
407 System.out.println("VNCNetworkInterface :" + vncInterface); | |
408 } | |
409 sendDesktopSizeChange(reconnectingId); | |
410 reconnecting = false; | |
411 if (reconnectingId == 0) { | |
412 viewer.setVisible(false); | |
413 } | |
414 } | |
415 if (reconnectingId!=0) { | |
416 readyReconnect = ready; | |
417 if (ready) { | |
418 notifyAll(); | |
419 } | |
420 } | |
421 } | |
94
75879c316796
synchronized wait for Rfb initialization in change server.
oc
parents:
89
diff
changeset
|
422 |
202 | 423 |
223 | 424 public synchronized void waitForVNCConnection() throws InterruptedException { |
425 if (reconnectingId!=0) { | |
426 while (!readyReconnect) { | |
427 wait(); | |
428 } | |
429 } | |
430 } | |
96 | 431 |
432 | |
223 | 433 public void sendDesktopSizeChange(short id) { |
434 LinkedList<ByteBuffer> desktopSize = new LinkedList<ByteBuffer>(); | |
435 int width = context.getFbWidth(); | |
436 int height = context.getFbHeight(); | |
437 desktopSize.add(new UpdateRectangleMessage(width, height, EncodingType.INIT_DATA, context.getInitData(),id).getMessage()); | |
242 | 438 addSerialNumber(desktopSize); |
223 | 439 multicastqueue.put(desktopSize); |
440 } | |
98 | 441 |
442 | |
223 | 443 public void addSerialNumber(LinkedList<ByteBuffer> bufs) { |
242 | 444 ByteBuffer serialNum = multicastqueue.allocate(4+8); // addSerialNum flag + SerialNum |
243 | 445 if (this.addSerialNum) { |
446 serialNum.putInt(1); | |
447 } else { | |
448 serialNum.putInt(0); | |
449 } | |
223 | 450 serialNum.putLong(counter++); |
451 serialNum.flip(); | |
452 bufs.addFirst(serialNum); | |
453 } | |
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
|
454 |
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
|
455 |
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
|
456 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
|
457 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
|
458 } |
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
|
459 |
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
|
460 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
|
461 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
|
462 context.cleanUpSession(null); |
118
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
463 // cleanup zlib decoder for new VNCServer |
202 | 464 if (isTreeManager()) |
118
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
465 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
|
466 } |
113
bce2ef0a2e79
use ProtocolContext.sendMessage for upward command
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
112
diff
changeset
|
467 |
bce2ef0a2e79
use ProtocolContext.sendMessage for upward command
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
112
diff
changeset
|
468 public String getMyAddress() { |
174 | 469 return myAddress; |
113
bce2ef0a2e79
use ProtocolContext.sendMessage for upward command
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
112
diff
changeset
|
470 } |
118
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
471 |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
472 /** |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
473 * gzip byte arrays |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
474 * |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
475 * @param deflater |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
476 * @param inputs |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
477 * byte data[] |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
478 * @param inputIndex |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
479 * @param outputs |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
480 * byte data[] |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
481 * @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
|
482 * @throws IOException |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
483 */ |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
484 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
|
485 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
|
486 int len = 0; |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
487 ByteBuffer c1 = multicastqueue.allocate(INFLATE_BUFSIZE); |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
488 while (inputIndex < inputs.size()) { |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
489 ByteBuffer b1 = inputs.get(inputIndex++); |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
490 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
|
491 /** |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
492 * 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
|
493 * 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
|
494 * 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
|
495 * 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
|
496 * of bug of Java library. |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
497 */ |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
498 if (inputIndex == inputs.size()) |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
499 deflater.finish(); |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
500 int len1 = 0; |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
501 do { |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
502 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
|
503 c1.remaining()); |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
504 if (len1 > 0) { |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
505 len += len1; |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
506 c1.position(c1.position() + len1); |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
507 if (c1.remaining() == 0) { |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
508 c1.flip(); |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
509 outputs.addLast(c1); |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
510 c1 = multicastqueue.allocate(INFLATE_BUFSIZE); |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
511 } |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
512 } |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
513 } 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
|
514 } |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
515 if (c1.position() != 0) { |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
516 c1.flip(); |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
517 outputs.addLast(c1); |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
518 } |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
519 deflater.reset(); |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
520 return len; |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
521 } |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
522 |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
523 /** |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
524 * gunzip byte arrays |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
525 * |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
526 * @param inflater |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
527 * @param inputs |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
528 * byte data[] |
182 | 529 * @param bytes |
118
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
530 * byte data[] |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
531 * @return number of total bytes |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
532 * @throws IOException |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
533 */ |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
534 public int unzip(Inflater inflater, LinkedList<ByteBuffer> inputs, |
182 | 535 int inputIndex, byte[] bytes, int bufSize) |
223 | 536 throws DataFormatException { |
182 | 537 int position = 0; |
538 int limit = bytes.length; | |
118
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
539 while (inputIndex < inputs.size()) { |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
540 ByteBuffer input = inputs.get(inputIndex++); |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
541 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
|
542 // 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
|
543 // we need this |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
544 // 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
|
545 do { |
182 | 546 int len0 = inflater.inflate(bytes, position, |
547 limit-position); | |
118
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
548 if (len0 > 0) { |
223 | 549 position += len0; |
182 | 550 if (position > limit) { |
223 | 551 throw new DataFormatException(); |
118
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
552 } |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
553 } |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
554 } while (!inflater.needsInput()); |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
555 } |
182 | 556 return position; |
118
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
557 } |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
558 |
135
ada4d850a820
lostParent and notFoundParenet
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
134
diff
changeset
|
559 /** |
ada4d850a820
lostParent and notFoundParenet
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
134
diff
changeset
|
560 * 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
|
561 * 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
|
562 * @param dataLen |
ada4d850a820
lostParent and notFoundParenet
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
134
diff
changeset
|
563 * @param reader |
ada4d850a820
lostParent and notFoundParenet
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
134
diff
changeset
|
564 * @throws TransportException |
232
6ee4cdca104c
send value of port and localhost in checkdelay framebufferupdate, and get this.
oc
parents:
231
diff
changeset
|
565 * @throws UnsupportedEncodingException |
135
ada4d850a820
lostParent and notFoundParenet
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
134
diff
changeset
|
566 */ |
182 | 567 public void readSendData(int dataLen, Reader reader, byte[] bytes) |
232
6ee4cdca104c
send value of port and localhost in checkdelay framebufferupdate, and get this.
oc
parents:
231
diff
changeset
|
568 throws TransportException, UnsupportedEncodingException { |
118
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
569 LinkedList<ByteBuffer> bufs = new LinkedList<ByteBuffer>(); |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
570 ByteBuffer header = multicastqueue.allocate(16); |
242 | 571 ByteBuffer serial = multicastqueue.allocate(4+8); |
202 | 572 if (!isTreeManager()) { |
242 | 573 reader.readBytes(serial.array(),0,4+8); |
574 serial.limit(4+8); | |
182 | 575 } |
185 | 576 reader.mark(dataLen); |
118
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
577 reader.readBytes(header.array(), 0, 16); |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
578 header.limit(16); |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
579 if (header.get(0) == FramebufferUpdate) { |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
580 int encoding = header.getInt(12); |
239 | 581 |
118
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
582 if (encoding == EncodingType.ZRLE.getId() |
229
5eb8aa65f387
fix checkdelay number-of-rectangle, and send checkdelay to lower node.
oc
parents:
227
diff
changeset
|
583 || encoding == EncodingType.ZLIB.getId()) { |
186
f76ee760c2d2
dead lock on command line root
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
185
diff
changeset
|
584 // recompress into ZREE |
f76ee760c2d2
dead lock on command line root
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
185
diff
changeset
|
585 // 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
|
586 ByteBuffer len = multicastqueue.allocate(4); |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
587 reader.readBytes(len.array(), 0, 4); |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
588 len.limit(4); |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
589 ByteBuffer inputData = multicastqueue.allocate(dataLen - 20); |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
590 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
|
591 inputData.limit(dataLen - 20); |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
592 LinkedList<ByteBuffer> inputs = new LinkedList<ByteBuffer>(); |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
593 inputs.add(inputData); |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
594 header.putInt(12, EncodingType.ZRLEE.getId()); // means |
223 | 595 // recompress |
596 // every time | |
118
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
597 // 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
|
598 // protocol, clients have to be modified. |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
599 Deflater nDeflater = deflater; // new Deflater(); |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
600 LinkedList<ByteBuffer> out = new LinkedList<ByteBuffer>(); |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
601 try { |
182 | 602 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
|
603 // dump32(inputs); |
182 | 604 out.add(ByteBuffer.wrap(bytes)); |
118
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
605 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
|
606 ByteBuffer blen = multicastqueue.allocate(4); |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
607 blen.putInt(len2); |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
608 blen.flip(); |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
609 bufs.addFirst(blen); |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
610 bufs.addFirst(header); |
242 | 611 addSerialNumber(bufs); |
118
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
612 multicastqueue.put(bufs); |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
613 } catch (DataFormatException e) { |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
614 throw new TransportException(e); |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
615 } catch (IOException e) { |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
616 throw new TransportException(e); |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
617 } |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
618 return; |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
619 } |
233 | 620 |
186
f76ee760c2d2
dead lock on command line root
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
185
diff
changeset
|
621 // ZRLEE is already compressed |
118
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
622 bufs.add(header); |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
623 if (dataLen > 16) { |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
624 ByteBuffer b = multicastqueue.allocate(dataLen - 16); |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
625 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
|
626 b.limit(dataLen - 16); |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
627 bufs.add(b); |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
628 } |
242 | 629 this.addSerialNumber(bufs); |
118
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
630 multicastqueue.put(bufs); |
233 | 631 |
118
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
632 return; |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
633 } |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
634 // 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
|
635 // decompressing here, |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
636 // 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
|
637 // each client. |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
638 // 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
|
639 // here. |
38e461e9b9c9
remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
113
diff
changeset
|
640 } |
124 | 641 |
223 | 642 public void setId(short id) { |
643 this.id = id; | |
644 } | |
169 | 645 |
223 | 646 public short getId() { |
647 return id; | |
648 } | |
169 | 649 |
174 | 650 public void setMyAddress(String myHostName) { |
651 this.myAddress = myHostName; | |
223 | 652 |
174 | 653 } |
654 | |
655 public void setLeader(boolean leader) { | |
656 this.leader = leader; | |
657 } | |
658 | |
659 public boolean isLeader() { | |
660 return leader; | |
661 } | |
662 | |
203 | 663 public void setTreeManager(String intf, TreeManagement clients) { |
223 | 664 nets.setTreeManager(intf, clients); |
174 | 665 } |
223 | 666 |
203 | 667 public TreeManagement getTreeManager(String intf) { |
231 | 668 TreeManagement tm = nets.getTreeManager(intf); |
669 this.nodeList = tm.getList(); | |
670 return tm; | |
174 | 671 } |
672 | |
673 /** | |
674 * chnageVNCServer is called when host change. | |
675 * | |
676 * @param vncProxyService | |
677 * @param hostName | |
678 * HostAddress | |
679 * @param width | |
680 * FrameWidth | |
681 * @param height | |
682 * FrameHeight | |
683 * @param id | |
684 * @throws InterruptedException | |
685 */ | |
686 public void changeVNCServer(ViewerInterface vncProxyService, String hostName, int width, int height, short id) | |
223 | 687 throws UnknownHostException, IOException, InterruptedException { |
688 // stop reader stop | |
174 | 689 stopReceiverTask(); |
192 | 690 reconnectingId = id; |
223 | 691 vncProxyService.inhelitClients(vncProxyService, hostName); |
187 | 692 // after connecting VNC server, rfb send SEND_INIT_DATA command and wakes me up if necessary |
223 | 693 reconnecting = true; |
694 if (reconnectingId!=0) { | |
695 waitForVNCConnection(); | |
696 } | |
174 | 697 } |
698 | |
699 /** | |
700 * start accepting children | |
701 * run rootFinderListener if necessary | |
702 */ | |
176 | 703 public void createConnectionAndStart(ViewerInterface v) { |
223 | 704 selectPort(ConnectionParams.DEFAULT_VNC_ROOT); |
176 | 705 startTreeVncCommandListener(); |
223 | 706 if(isTreeManager() && firstTime) { |
707 getCast = new TreeRootFinderListener(v); | |
239 | 708 Thread treeRootFindThread = new Thread(getCast, "tree-root-find-listener"); |
709 treeRootFindThread.start(); | |
223 | 710 firstTime = false; |
711 } | |
174 | 712 } |
713 | |
223 | 714 public void startTreeVncCommandListener() { |
176 | 715 acceptThread = new TreeVncCommandChannelListener(this, getAcceptPort()); |
223 | 716 Thread thread = new Thread(acceptThread, "TreeVNC-accept"); |
717 thread.start(); | |
176 | 718 } |
719 | |
174 | 720 public TreeVncCommandChannelListener getAcceptThread() { |
721 return acceptThread; | |
722 } | |
723 | |
176 | 724 public void setConnectionParam(CreateConnectionParam createConnectionParam) { |
725 cp = createConnectionParam; | |
726 } | |
727 | |
728 public CreateConnectionParam getConnectionParam() { | |
729 return cp; | |
730 } | |
731 | |
178
34b7558aeffa
remove TreeTask, StartTreeHandling
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
177
diff
changeset
|
732 public boolean hasViewer() { |
34b7558aeffa
remove TreeTask, StartTreeHandling
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
177
diff
changeset
|
733 return hasViewer; |
34b7558aeffa
remove TreeTask, StartTreeHandling
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
177
diff
changeset
|
734 } |
34b7558aeffa
remove TreeTask, StartTreeHandling
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
177
diff
changeset
|
735 |
34b7558aeffa
remove TreeTask, StartTreeHandling
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
177
diff
changeset
|
736 public void setHasViewer(boolean b) { |
34b7558aeffa
remove TreeTask, StartTreeHandling
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
177
diff
changeset
|
737 hasViewer = b; |
34b7558aeffa
remove TreeTask, StartTreeHandling
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
177
diff
changeset
|
738 } |
34b7558aeffa
remove TreeTask, StartTreeHandling
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
177
diff
changeset
|
739 |
186
f76ee760c2d2
dead lock on command line root
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
185
diff
changeset
|
740 public void setReconnecting(boolean b) { |
f76ee760c2d2
dead lock on command line root
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
185
diff
changeset
|
741 reconnecting = b; |
f76ee760c2d2
dead lock on command line root
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
185
diff
changeset
|
742 } |
f76ee760c2d2
dead lock on command line root
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
185
diff
changeset
|
743 |
223 | 744 public int getReconnectingId() { |
745 return reconnectingId; | |
746 } | |
747 | |
748 public void setShowTree(boolean showTree) { | |
240 | 749 this.showTreeNode = showTree; |
750 } | |
751 | |
752 public void setCheckDelay(boolean checkDelay) { | |
753 this.checkDelay = checkDelay; | |
223 | 754 } |
194 | 755 |
241 | 756 public void setAddSerialNum(boolean addSerialNum) { |
757 this.addSerialNum = addSerialNum; | |
758 } | |
759 | |
235 | 760 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
|
761 int nodeNum = 0; |
235 | 762 |
232
6ee4cdca104c
send value of port and localhost in checkdelay framebufferupdate, and get this.
oc
parents:
231
diff
changeset
|
763 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
|
764 TreeVNCNode tvn = (TreeVNCNode)i.next(); |
235 | 765 if (port == tvn.port && address.equals(tvn.hostname)) { |
766 nodeNum = tvn.treeNum; | |
767 return nodeNum; | |
768 } | |
232
6ee4cdca104c
send value of port and localhost in checkdelay framebufferupdate, and get this.
oc
parents:
231
diff
changeset
|
769 } |
6ee4cdca104c
send value of port and localhost in checkdelay framebufferupdate, and get this.
oc
parents:
231
diff
changeset
|
770 return nodeNum; |
6ee4cdca104c
send value of port and localhost in checkdelay framebufferupdate, and get this.
oc
parents:
231
diff
changeset
|
771 } |
241 | 772 |
240 | 773 } |