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