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