annotate src/main/java/jp/ac/u_ryukyu/treevnc/MyRfbProto.java @ 166:26bc52699cf3

send initData to lower node.
author oc
date Thu, 19 Jun 2014 17:19:59 +0900
parents 86289e56263c
children 8ab1f6905db4
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
32
758d025ee24b add TextBox.java
one
parents: 31
diff changeset
1 package jp.ac.u_ryukyu.treevnc;
28
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
2
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
3 import java.io.IOException;
118
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
4 import java.net.BindException;
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
5 import java.net.ServerSocket;
28
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
6 import java.net.Socket;
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
7 import java.nio.ByteBuffer;
109
457f9dfbf7ce minor fix.
oc
parents: 107
diff changeset
8 import java.nio.ByteOrder;
28
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
9 import java.util.LinkedList;
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
10 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
11 import java.util.zip.DataFormatException;
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
12 import java.util.zip.Deflater;
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
13 import java.util.zip.Inflater;
150
925fb2090282 minor fix
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 147
diff changeset
14
125
32c6563492f3 add vnc protocol command sender.
oc
parents: 124
diff changeset
15 import jp.ac.u_ryukyu.treevnc.client.TreeVncProtocol;
28
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
16 import jp.ac.u_ryukyu.treevnc.server.RequestScreenThread;
94
75879c316796 synchronized wait for Rfb initialization in change server.
oc
parents: 89
diff changeset
17 import jp.ac.u_ryukyu.treevnc.server.VncProxyService;
150
925fb2090282 minor fix
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 147
diff changeset
18
28
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
19 import com.glavsoft.exceptions.TransportException;
107
660b296d4f75 send change screen command throw the tree.
oc
parents: 103
diff changeset
20 import com.glavsoft.rfb.client.ClientToServerMessage;
96
76e49dd9c9c5 Client resize without reconnection
oc
parents: 94
diff changeset
21 import com.glavsoft.rfb.encoding.EncodingType;
28
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
22 import com.glavsoft.rfb.protocol.Protocol;
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
23 import com.glavsoft.rfb.protocol.ProtocolContext;
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
24 import com.glavsoft.transport.Reader;
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
25 import com.glavsoft.transport.Writer;
153
e68dfd1972ac fix bad names.
oc
parents: 150
diff changeset
26 import com.glavsoft.viewer.ViewerInterface;
28
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
27
124
214d4f206431 add TreeVNC command number.
oc
parents: 123
diff changeset
28
120
c1b14cef2704 MyRfb fix done.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 118
diff changeset
29 public abstract class MyRfbProto {
33
9d3478d11d3b Add the processing of client
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents: 32
diff changeset
30 final static int FramebufferUpdateRequest = 3;
28
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
31 final static int CheckDelay = 11;
103
84f254d8bde4 remove isinstaceof
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 102
diff changeset
32 protected final static int FramebufferUpdate = 0;
153
e68dfd1972ac fix bad names.
oc
parents: 150
diff changeset
33 protected ProtocolContext context;
e68dfd1972ac fix bad names.
oc
parents: 150
diff changeset
34 private int clients = 0;
98
8f4c45c1b396 add serial number to desktop size encoding packet.
oc
parents: 97
diff changeset
35 public MulticastQueue<LinkedList<ByteBuffer>> multicastqueue = new MulticastQueue<LinkedList<ByteBuffer>>();
28
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
36 private RequestScreenThread rThread;
118
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
37 public int acceptPort = 0;
94
75879c316796 synchronized wait for Rfb initialization in change server.
oc
parents: 89
diff changeset
38 protected boolean readyReconnect = false;
98
8f4c45c1b396 add serial number to desktop size encoding packet.
oc
parents: 97
diff changeset
39 private boolean cuiVersion;
107
660b296d4f75 send change screen command throw the tree.
oc
parents: 103
diff changeset
40 private long counter = 0; // packet serial number
135
ada4d850a820 lostParent and notFoundParenet
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
41 TreeVncProtocol treeProtocol;
118
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
42 public ServerSocket servSock;
123
233e94a7b5ed add comment
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 122
diff changeset
43 private boolean permitChangeScreen = true;
118
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
44 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
45
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
46 private Inflater inflater = new Inflater();
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
47 private Deflater deflater = new Deflater();
157
7cea8789387b thread base command listening loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 153
diff changeset
48 VncProxyService viewer;
118
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
49
107
660b296d4f75 send change screen command throw the tree.
oc
parents: 103
diff changeset
50
33
9d3478d11d3b Add the processing of client
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents: 32
diff changeset
51 public MyRfbProto() {
9d3478d11d3b Add the processing of client
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents: 32
diff changeset
52 rThread = new RequestScreenThread(this);
9d3478d11d3b Add the processing of client
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents: 32
diff changeset
53 }
107
660b296d4f75 send change screen command throw the tree.
oc
parents: 103
diff changeset
54
111
a7988d3c0266 minor fix.
oc
parents: 110
diff changeset
55 public void setVncProxy(VncProxyService viewer) {
135
ada4d850a820 lostParent and notFoundParenet
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
56 this.viewer = viewer;
107
660b296d4f75 send change screen command throw the tree.
oc
parents: 103
diff changeset
57 }
28
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
58
120
c1b14cef2704 MyRfb fix done.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 118
diff changeset
59 abstract public boolean isRoot() ;
28
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
60
164
86289e56263c Send initData in server change
oc
parents: 160
diff changeset
61 public ProtocolContext getContext() {
86289e56263c Send initData in server change
oc
parents: 160
diff changeset
62 return context;
86289e56263c Send initData in server change
oc
parents: 160
diff changeset
63 }
86289e56263c Send initData in server change
oc
parents: 160
diff changeset
64
130
1f6bfaa3281b root selection panel
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 129
diff changeset
65 /**
1f6bfaa3281b root selection panel
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 129
diff changeset
66 * handle new client accept
1f6bfaa3281b root selection panel
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 129
diff changeset
67 * it also handle TreeVNC Command
1f6bfaa3281b root selection panel
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 129
diff changeset
68 * @param acceptThread
1f6bfaa3281b root selection panel
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 129
diff changeset
69 * @param newCli
1f6bfaa3281b root selection panel
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 129
diff changeset
70 * @param os
1f6bfaa3281b root selection panel
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 129
diff changeset
71 * @param is
1f6bfaa3281b root selection panel
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 129
diff changeset
72 * @throws IOException
1f6bfaa3281b root selection panel
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 129
diff changeset
73 * @throws TransportException
1f6bfaa3281b root selection panel
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 129
diff changeset
74 */
157
7cea8789387b thread base command listening loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 153
diff changeset
75 public void newClient(final Socket newCli,final Writer os, final Reader is) {
124
214d4f206431 add TreeVNC command number.
oc
parents: 123
diff changeset
76
28
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
77 final int myId = clients;
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
78 final MulticastQueue.Client<LinkedList<ByteBuffer>> c = multicastqueue.newClient();
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
79 final AtomicInteger writerRunning = new AtomicInteger();
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
80 writerRunning.set(1);
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
81 /**
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
82 * Timeout thread. If a client is suspended, it has top of queue
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
83 * indefinitely, which caused memory overflow. After the timeout, we
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
84 * poll the queue and discard it. Start long wait if writer is running.
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
85 */
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
86 final Runnable timer = new Runnable() {
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
87 public void run() {
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
88 int count = 0;
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
89 for (;;) {
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
90 long timeout = 50000 / 8;
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
91 try {
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
92 synchronized (this) {
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
93 int state, flag;
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
94 writerRunning.set(0);
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
95 wait(timeout);
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
96 flag = 0;
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
97 while ((state = writerRunning.get()) == 0) {
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
98 c.poll(); // discard, should be timeout
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
99 count++;
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
100 if (flag == 0) {
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
101 System.out.println("Discarding " + myId
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
102 + " count=" + count);
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
103 flag = 1;
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
104 }
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
105 wait(10); // if this is too short, writer cannot
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
106 // take the poll, if this is too
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
107 // long, memory will overflow...
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
108 }
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
109 if (flag == 1)
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
110 System.out.println("Resuming " + myId
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
111 + " count=" + count);
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
112 if (state != 1) {
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
113 System.out.println("Client died " + myId);
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
114 break;
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
115 }
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
116 }
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
117 } catch (InterruptedException e) {
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
118 }
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
119 }
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
120 }
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
121 };
88
a719aa609e14 add name valuer threads.
oc
parents: 85
diff changeset
122 new Thread(timer, "timer-discard-multicastqueue").start();
28
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
123 /**
135
ada4d850a820 lostParent and notFoundParenet
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
124 * handle command from lower node
28
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
125 */
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
126 final Runnable reader = new Runnable() {
135
ada4d850a820 lostParent and notFoundParenet
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
127
122
e2416a246c95 noScreenChange flag on command line ( should be on panel also )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 120
diff changeset
128 public void run() {
28
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
129 for (;;) {
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
130 try {
113
bce2ef0a2e79 use ProtocolContext.sendMessage for upward command
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 112
diff changeset
131 final byte b[] = new byte[4096];
bce2ef0a2e79 use ProtocolContext.sendMessage for upward command
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 112
diff changeset
132 final int c = is.readByte(b);
28
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
133 if (c <= 0)
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
134 throw new IOException();
107
660b296d4f75 send change screen command throw the tree.
oc
parents: 103
diff changeset
135 if (isRoot()) {
660b296d4f75 send change screen command throw the tree.
oc
parents: 103
diff changeset
136 if (b[0] == ClientToServerMessage.SERVER_CHANGE_REQUEST) {
660b296d4f75 send change screen command throw the tree.
oc
parents: 103
diff changeset
137 if (permitChangeScreen()) {
109
457f9dfbf7ce minor fix.
oc
parents: 107
diff changeset
138 ByteBuffer buf = ByteBuffer.wrap(b);
457f9dfbf7ce minor fix.
oc
parents: 107
diff changeset
139 buf.order(ByteOrder.BIG_ENDIAN);
457f9dfbf7ce minor fix.
oc
parents: 107
diff changeset
140 int length = buf.getInt(4);
107
660b296d4f75 send change screen command throw the tree.
oc
parents: 103
diff changeset
141 if (length == 0)
660b296d4f75 send change screen command throw the tree.
oc
parents: 103
diff changeset
142 continue;
660b296d4f75 send change screen command throw the tree.
oc
parents: 103
diff changeset
143 String newHostName = new String(b, 8, length);
111
a7988d3c0266 minor fix.
oc
parents: 110
diff changeset
144 System.out.println("Root server change request :" + newHostName);
107
660b296d4f75 send change screen command throw the tree.
oc
parents: 103
diff changeset
145 // please remove these numbers.
660b296d4f75 send change screen command throw the tree.
oc
parents: 103
diff changeset
146 if (viewer != null) {
660b296d4f75 send change screen command throw the tree.
oc
parents: 103
diff changeset
147 viewer.changeVNCServer(newHostName, 3200, 1980);
660b296d4f75 send change screen command throw the tree.
oc
parents: 103
diff changeset
148 }
660b296d4f75 send change screen command throw the tree.
oc
parents: 103
diff changeset
149 } else {
660b296d4f75 send change screen command throw the tree.
oc
parents: 103
diff changeset
150 continue;
660b296d4f75 send change screen command throw the tree.
oc
parents: 103
diff changeset
151 }
660b296d4f75 send change screen command throw the tree.
oc
parents: 103
diff changeset
152 }
110
464eb64e3fd6 minor fix.
oc
parents: 109
diff changeset
153 } else if (b[0] == ClientToServerMessage.SERVER_CHANGE_REQUEST) {
113
bce2ef0a2e79 use ProtocolContext.sendMessage for upward command
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 112
diff changeset
154 ClientToServerMessage sc = new ClientToServerMessage() {
bce2ef0a2e79 use ProtocolContext.sendMessage for upward command
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 112
diff changeset
155 @Override
bce2ef0a2e79 use ProtocolContext.sendMessage for upward command
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 112
diff changeset
156 public void send(Writer writer)
bce2ef0a2e79 use ProtocolContext.sendMessage for upward command
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 112
diff changeset
157 throws TransportException {
bce2ef0a2e79 use ProtocolContext.sendMessage for upward command
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 112
diff changeset
158 writer.write(b,0,c);
bce2ef0a2e79 use ProtocolContext.sendMessage for upward command
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 112
diff changeset
159 }
bce2ef0a2e79 use ProtocolContext.sendMessage for upward command
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 112
diff changeset
160 };
bce2ef0a2e79 use ProtocolContext.sendMessage for upward command
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 112
diff changeset
161 context.sendMessage(sc);
107
660b296d4f75 send change screen command throw the tree.
oc
parents: 103
diff changeset
162 }
28
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
163 // System.out.println("client read "+c);
89
1503a373ab73 close client correctly in -d mode.
oc
parents: 88
diff changeset
164 } catch (Exception e) {
28
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
165 try {
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
166 writerRunning.set(2);
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
167 os.close();
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
168 is.close();
36
b7d4d0349f99 write part of reconnection and remove warning.
one
parents: 35
diff changeset
169 break;
28
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
170 } catch (IOException e1) {
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
171 } catch (TransportException e1) {
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
172 e1.printStackTrace();
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
173 }
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
174 return;
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
175 }
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
176 }
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
177 }
107
660b296d4f75 send change screen command throw the tree.
oc
parents: 103
diff changeset
178
28
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
179 };
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
180 /**
135
ada4d850a820 lostParent and notFoundParenet
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
181 * send packets to a client (one thread for each client )
28
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
182 */
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
183 Runnable sender = new Runnable() {
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
184 public void run() {
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
185 writerRunning.set(1);
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
186 try {
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
187 requestThreadNotify();
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
188
88
a719aa609e14 add name valuer threads.
oc
parents: 85
diff changeset
189 // after this, we discard upward packet.
131
95f53663295c lost host and parent not found
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 130
diff changeset
190 new Thread(reader, "upward-packet-processing").start();
135
ada4d850a820 lostParent and notFoundParenet
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
191
28
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
192 for (;;) {
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
193 LinkedList<ByteBuffer> bufs = c.poll();
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
194 int inputIndex = 0;
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
195 ByteBuffer header = bufs.get(inputIndex);
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
196 if (header == null)
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
197 continue;
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
198 else if (header.get(0) == CheckDelay) {
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
199 writeToClient(os, bufs, inputIndex);
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
200 continue;
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
201 } else if (header.get(0) == FramebufferUpdate) {
63
84f1c39ba3bf temp commit
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents: 61
diff changeset
202 //System.out.println("client "+ myId);
28
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
203 }
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
204 /*
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
205 * if(i%20==0){ sendDataCheckDelay(); } i++;
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
206 */
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
207 writeToClient(os, bufs, inputIndex);
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
208 writerRunning.set(1); // yes my client is awaking.
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
209 }
89
1503a373ab73 close client correctly in -d mode.
oc
parents: 88
diff changeset
210 } catch (Exception e) {
28
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
211 try {
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
212 writerRunning.set(2);
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
213 os.close();
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
214 } catch (IOException e1) {
160
b9052986bbb3 fix command loop.
oc
parents: 157
diff changeset
215 System.out.println("root writer close faild :" + e1);
28
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
216 }
160
b9052986bbb3 fix command loop.
oc
parents: 157
diff changeset
217 System.out.println("root writer faild :" + e);
28
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
218 /* if socket closed cliList.remove(newCli); */
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
219 }
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
220 }
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
221
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
222 public void writeToClient(final Writer os,
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
223 LinkedList<ByteBuffer> bufs, int inputIndex)
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
224 throws TransportException {
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
225 while (inputIndex < bufs.size()) {
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
226 ByteBuffer b = bufs.get(inputIndex++);
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
227 os.write(b.array(), b.position(), b.limit());
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
228 }
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
229 os.flush();
74
f1938dd3b518 don't heap space error.
oc
parents: 69
diff changeset
230 bufs = null;
f1938dd3b518 don't heap space error.
oc
parents: 69
diff changeset
231 multicastqueue.heapAvailable();
28
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
232 }
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
233 };
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
234 clients++;
88
a719aa609e14 add name valuer threads.
oc
parents: 85
diff changeset
235 new Thread(sender, "writer-to-lower-node").start();
28
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
236
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
237 }
157
7cea8789387b thread base command listening loop
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 153
diff changeset
238
28
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
239
122
e2416a246c95 noScreenChange flag on command line ( should be on panel also )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 120
diff changeset
240
e2416a246c95 noScreenChange flag on command line ( should be on panel also )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 120
diff changeset
241 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
242 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
243 }
e2416a246c95 noScreenChange flag on command line ( should be on panel also )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 120
diff changeset
244
e2416a246c95 noScreenChange flag on command line ( should be on panel also )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 120
diff changeset
245
e2416a246c95 noScreenChange flag on command line ( should be on panel also )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 120
diff changeset
246 public void setPermitChangeScreen(boolean v) {
e2416a246c95 noScreenChange flag on command line ( should be on panel also )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 120
diff changeset
247 permitChangeScreen = v;
e2416a246c95 noScreenChange flag on command line ( should be on panel also )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 120
diff changeset
248 }
e2416a246c95 noScreenChange flag on command line ( should be on panel also )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 120
diff changeset
249
88
a719aa609e14 add name valuer threads.
oc
parents: 85
diff changeset
250 public void requestThreadNotify() {
28
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
251 rThread.reStart();
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
252 }
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
253
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
254
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
255 public void setProtocolContext(Protocol workingProtocol) {
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
256 context = workingProtocol;
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
257 }
29
57eb5575e6c4 MyRfbProto for client and proxy.
one
parents: 28
diff changeset
258
134
128cce60c43c where to connect command
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 133
diff changeset
259 public Socket accept() throws IOException {
128cce60c43c where to connect command
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 133
diff changeset
260 return servSock.accept();
128cce60c43c where to connect command
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 133
diff changeset
261 }
31
872d9bcbfe56 Before changing the Viewer.
one
parents: 29
diff changeset
262
118
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
263 public int selectPort(int p) {
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
264 int port = p;
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
265 while (true) {
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
266 try {
134
128cce60c43c where to connect command
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 133
diff changeset
267 servSock = new ServerSocket(port);
128cce60c43c where to connect command
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 133
diff changeset
268 acceptPort = port;
118
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
269 break;
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
270 } catch (BindException e) {
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
271 port++;
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
272 continue;
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
273 } catch (IOException e) {
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
274
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
275 }
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
276 }
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
277 System.out.println("accept port = " + port);
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
278 return port;
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
279 }
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
280
33
9d3478d11d3b Add the processing of client
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents: 32
diff changeset
281
9d3478d11d3b Add the processing of client
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents: 32
diff changeset
282
9d3478d11d3b Add the processing of client
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents: 32
diff changeset
283 public void writeFramebufferUpdateRequest(int x, int y, int w, int h,
9d3478d11d3b Add the processing of client
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents: 32
diff changeset
284 boolean incremental) throws TransportException {
9d3478d11d3b Add the processing of client
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents: 32
diff changeset
285 byte[] b = new byte[10];
9d3478d11d3b Add the processing of client
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents: 32
diff changeset
286
9d3478d11d3b Add the processing of client
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents: 32
diff changeset
287 b[0] = (byte) FramebufferUpdateRequest; // 3 is FrameBufferUpdateRequest
9d3478d11d3b Add the processing of client
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents: 32
diff changeset
288 b[1] = (byte) (incremental ? 1 : 0);
9d3478d11d3b Add the processing of client
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents: 32
diff changeset
289 b[2] = (byte) ((x >> 8) & 0xff);
9d3478d11d3b Add the processing of client
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents: 32
diff changeset
290 b[3] = (byte) (x & 0xff);
9d3478d11d3b Add the processing of client
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents: 32
diff changeset
291 b[4] = (byte) ((y >> 8) & 0xff);
9d3478d11d3b Add the processing of client
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents: 32
diff changeset
292 b[5] = (byte) (y & 0xff);
9d3478d11d3b Add the processing of client
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents: 32
diff changeset
293 b[6] = (byte) ((w >> 8) & 0xff);
9d3478d11d3b Add the processing of client
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents: 32
diff changeset
294 b[7] = (byte) (w & 0xff);
9d3478d11d3b Add the processing of client
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents: 32
diff changeset
295 b[8] = (byte) ((h >> 8) & 0xff);
9d3478d11d3b Add the processing of client
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents: 32
diff changeset
296 b[9] = (byte) (h & 0xff);
9d3478d11d3b Add the processing of client
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents: 32
diff changeset
297
9d3478d11d3b Add the processing of client
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents: 32
diff changeset
298 // os.write(b);
9d3478d11d3b Add the processing of client
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents: 32
diff changeset
299 }
9d3478d11d3b Add the processing of client
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents: 32
diff changeset
300
125
32c6563492f3 add vnc protocol command sender.
oc
parents: 124
diff changeset
301 public void setEcho(TreeVncProtocol _echo) {
133
70cbec526039 connection handling
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 131
diff changeset
302 treeProtocol = _echo;
35
1b81deb0abb3 write a little part reconnection.
one
parents: 33
diff changeset
303 }
1b81deb0abb3 write a little part reconnection.
one
parents: 33
diff changeset
304
153
e68dfd1972ac fix bad names.
oc
parents: 150
diff changeset
305 public void setViewer(ViewerInterface v) {
133
70cbec526039 connection handling
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 131
diff changeset
306 treeProtocol.setViewer(v);
36
b7d4d0349f99 write part of reconnection and remove warning.
one
parents: 35
diff changeset
307 }
b7d4d0349f99 write part of reconnection and remove warning.
one
parents: 35
diff changeset
308
153
e68dfd1972ac fix bad names.
oc
parents: 150
diff changeset
309 public ViewerInterface getViewer() {
133
70cbec526039 connection handling
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 131
diff changeset
310 return treeProtocol.getViewer();
65
ffd7537cebfc cuiversion
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents: 64
diff changeset
311 }
ffd7537cebfc cuiversion
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents: 64
diff changeset
312
125
32c6563492f3 add vnc protocol command sender.
oc
parents: 124
diff changeset
313 public TreeVncProtocol getEcho() {
133
70cbec526039 connection handling
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 131
diff changeset
314 return treeProtocol;
35
1b81deb0abb3 write a little part reconnection.
one
parents: 33
diff changeset
315 }
43
6687aa9dd55e add flag for screen change in ReciverTask.java.
one
parents: 38
diff changeset
316
6687aa9dd55e add flag for screen change in ReciverTask.java.
one
parents: 38
diff changeset
317 public void setTerminationType(boolean setType) {
6687aa9dd55e add flag for screen change in ReciverTask.java.
one
parents: 38
diff changeset
318 /*nop*/
6687aa9dd55e add flag for screen change in ReciverTask.java.
one
parents: 38
diff changeset
319 }
6687aa9dd55e add flag for screen change in ReciverTask.java.
one
parents: 38
diff changeset
320
6687aa9dd55e add flag for screen change in ReciverTask.java.
one
parents: 38
diff changeset
321 public boolean getTerminationType() {
6687aa9dd55e add flag for screen change in ReciverTask.java.
one
parents: 38
diff changeset
322 /*nop*/
6687aa9dd55e add flag for screen change in ReciverTask.java.
one
parents: 38
diff changeset
323 return true;
6687aa9dd55e add flag for screen change in ReciverTask.java.
one
parents: 38
diff changeset
324 }
45
20326a4b9d88 create new change button for client.
one
parents: 43
diff changeset
325
134
128cce60c43c where to connect command
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 133
diff changeset
326 public void close() {
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
327 // none
52
986f16afb753 update before change host.
one
parents: 45
diff changeset
328 }
45
20326a4b9d88 create new change button for client.
one
parents: 43
diff changeset
329
60
ac6f9e46566f proxy mode ok.
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents: 59
diff changeset
330 public int getAcceptPort() {
118
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
331 return acceptPort;
60
ac6f9e46566f proxy mode ok.
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents: 59
diff changeset
332 }
ac6f9e46566f proxy mode ok.
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents: 59
diff changeset
333
61
d9cf08c6415c During implementation change screen.
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents: 60
diff changeset
334 public boolean getReadyReconnect() {
d9cf08c6415c During implementation change screen.
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents: 60
diff changeset
335 return readyReconnect;
d9cf08c6415c During implementation change screen.
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents: 60
diff changeset
336 }
65
ffd7537cebfc cuiversion
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents: 64
diff changeset
337
ffd7537cebfc cuiversion
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents: 64
diff changeset
338
ffd7537cebfc cuiversion
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents: 64
diff changeset
339 public boolean getCuiVersion() {
ffd7537cebfc cuiversion
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents: 64
diff changeset
340 return cuiVersion;
61
d9cf08c6415c During implementation change screen.
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents: 60
diff changeset
341 }
65
ffd7537cebfc cuiversion
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents: 64
diff changeset
342
ffd7537cebfc cuiversion
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents: 64
diff changeset
343 public void setCuiVersion(boolean flag) {
ffd7537cebfc cuiversion
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents: 64
diff changeset
344 cuiVersion = flag;
ffd7537cebfc cuiversion
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents: 64
diff changeset
345 }
66
84ad879891e9 dont move
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents: 65
diff changeset
346
84ad879891e9 dont move
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents: 65
diff changeset
347 public void readCheckDelay(Reader reader) throws TransportException {
84ad879891e9 dont move
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents: 65
diff changeset
348
84ad879891e9 dont move
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents: 65
diff changeset
349 }
134
128cce60c43c where to connect command
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 133
diff changeset
350
94
75879c316796 synchronized wait for Rfb initialization in change server.
oc
parents: 89
diff changeset
351 public synchronized void setReadyReconnect(boolean ready) {
75879c316796 synchronized wait for Rfb initialization in change server.
oc
parents: 89
diff changeset
352 readyReconnect = ready;
75879c316796 synchronized wait for Rfb initialization in change server.
oc
parents: 89
diff changeset
353 if (ready) {
75879c316796 synchronized wait for Rfb initialization in change server.
oc
parents: 89
diff changeset
354 notifyAll();
75879c316796 synchronized wait for Rfb initialization in change server.
oc
parents: 89
diff changeset
355 }
75879c316796 synchronized wait for Rfb initialization in change server.
oc
parents: 89
diff changeset
356 }
75879c316796 synchronized wait for Rfb initialization in change server.
oc
parents: 89
diff changeset
357
75879c316796 synchronized wait for Rfb initialization in change server.
oc
parents: 89
diff changeset
358 public synchronized void waitForReady(VncProxyService vncProxyService) throws InterruptedException {
75879c316796 synchronized wait for Rfb initialization in change server.
oc
parents: 89
diff changeset
359 while (!readyReconnect) {
75879c316796 synchronized wait for Rfb initialization in change server.
oc
parents: 89
diff changeset
360 wait();
75879c316796 synchronized wait for Rfb initialization in change server.
oc
parents: 89
diff changeset
361 }
75879c316796 synchronized wait for Rfb initialization in change server.
oc
parents: 89
diff changeset
362 }
96
76e49dd9c9c5 Client resize without reconnection
oc
parents: 94
diff changeset
363
76e49dd9c9c5 Client resize without reconnection
oc
parents: 94
diff changeset
364
76e49dd9c9c5 Client resize without reconnection
oc
parents: 94
diff changeset
365 public void sendDesktopSizeChange() {
76e49dd9c9c5 Client resize without reconnection
oc
parents: 94
diff changeset
366 LinkedList<ByteBuffer> desktopSize = new LinkedList<ByteBuffer>();
97
44f5cdc63a76 don't create Rfb and VNC proxy on change server on root.
oc
parents: 96
diff changeset
367 int width = context.getFbWidth();
44f5cdc63a76 don't create Rfb and VNC proxy on change server on root.
oc
parents: 96
diff changeset
368 int height = context.getFbHeight();
164
86289e56263c Send initData in server change
oc
parents: 160
diff changeset
369 desktopSize.add(new UpdateRectangleMessage(width, height, EncodingType.INIT_DATA, context.getInitData()).getMessage());
99
da5f74092be8 minor fix.
oc
parents: 98
diff changeset
370 addSerialNumber(desktopSize);
96
76e49dd9c9c5 Client resize without reconnection
oc
parents: 94
diff changeset
371 multicastqueue.put(desktopSize);
76e49dd9c9c5 Client resize without reconnection
oc
parents: 94
diff changeset
372 }
98
8f4c45c1b396 add serial number to desktop size encoding packet.
oc
parents: 97
diff changeset
373
8f4c45c1b396 add serial number to desktop size encoding packet.
oc
parents: 97
diff changeset
374
8f4c45c1b396 add serial number to desktop size encoding packet.
oc
parents: 97
diff changeset
375 public void addSerialNumber(LinkedList<ByteBuffer> bufs) {
8f4c45c1b396 add serial number to desktop size encoding packet.
oc
parents: 97
diff changeset
376 ByteBuffer serialNum = multicastqueue.allocate(8);
8f4c45c1b396 add serial number to desktop size encoding packet.
oc
parents: 97
diff changeset
377 serialNum.putLong(counter++);
8f4c45c1b396 add serial number to desktop size encoding packet.
oc
parents: 97
diff changeset
378 serialNum.flip();
8f4c45c1b396 add serial number to desktop size encoding packet.
oc
parents: 97
diff changeset
379 bufs.addFirst(serialNum);
8f4c45c1b396 add serial number to desktop size encoding packet.
oc
parents: 97
diff changeset
380 }
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
381
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
382
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
383 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
384 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
385 }
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
386
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
387 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
388 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
389 context.cleanUpSession(null);
118
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
390 // cleanup zlib decoder for new VNCServer
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
391 if (isRoot())
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
392 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
393 }
113
bce2ef0a2e79 use ProtocolContext.sendMessage for upward command
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 112
diff changeset
394
bce2ef0a2e79 use ProtocolContext.sendMessage for upward command
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 112
diff changeset
395 public String getMyAddress() {
133
70cbec526039 connection handling
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 131
diff changeset
396 return treeProtocol.getMyAddress();
113
bce2ef0a2e79 use ProtocolContext.sendMessage for upward command
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 112
diff changeset
397 }
118
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
398
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
399 /**
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
400 * gzip byte arrays
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
401 *
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
402 * @param deflater
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
403 * @param inputs
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
404 * byte data[]
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
405 * @param inputIndex
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
406 * @param outputs
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
407 * byte data[]
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
408 * @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
409 * @throws IOException
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
410 */
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
411 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
412 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
413 int len = 0;
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
414 ByteBuffer c1 = multicastqueue.allocate(INFLATE_BUFSIZE);
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
415 while (inputIndex < inputs.size()) {
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
416 ByteBuffer b1 = inputs.get(inputIndex++);
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
417 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
418 /**
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
419 * 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
420 * 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
421 * 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
422 * 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
423 * of bug of Java library.
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
424 */
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
425 if (inputIndex == inputs.size())
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
426 deflater.finish();
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
427 int len1 = 0;
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
428 do {
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
429 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
430 c1.remaining());
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
431 if (len1 > 0) {
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
432 len += len1;
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
433 c1.position(c1.position() + len1);
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
434 if (c1.remaining() == 0) {
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
435 c1.flip();
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
436 outputs.addLast(c1);
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
437 c1 = multicastqueue.allocate(INFLATE_BUFSIZE);
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
438 }
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
439 }
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
440 } 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
441 }
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
442 if (c1.position() != 0) {
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
443 c1.flip();
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
444 outputs.addLast(c1);
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
445 }
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
446 deflater.reset();
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
447 return len;
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
448 }
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
449
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
450 /**
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
451 * gunzip byte arrays
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
452 *
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
453 * @param inflater
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
454 * @param inputs
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
455 * byte data[]
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
456 * @param outputs
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
457 * byte data[]
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
458 * @return number of total bytes
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
459 * @throws IOException
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
460 */
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
461 public int unzip(Inflater inflater, LinkedList<ByteBuffer> inputs,
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
462 int inputIndex, LinkedList<ByteBuffer> outputs, int bufSize)
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
463 throws DataFormatException {
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
464 int len = 0;
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
465 ByteBuffer buf = multicastqueue.allocate(bufSize);
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
466 while (inputIndex < inputs.size()) {
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
467 ByteBuffer input = inputs.get(inputIndex++);
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
468 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
469 // 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
470 // we need this
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
471 // 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
472 do {
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
473 int len0 = inflater.inflate(buf.array(), buf.position(),
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
474 buf.remaining());
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
475 if (len0 > 0) {
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
476 buf.position(buf.position() + len0);
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
477 len += len0;
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
478 if (buf.remaining() == 0) {
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
479 buf.flip();
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
480 outputs.addLast(buf);
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
481 buf = multicastqueue.allocate(bufSize);
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
482 }
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
483 }
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
484 } while (!inflater.needsInput());
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
485 }
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
486 if (buf.position() != 0) {
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
487 buf.flip();
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
488 outputs.addLast(buf);
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
489 }
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
490 return len;
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
491 }
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
492
135
ada4d850a820 lostParent and notFoundParenet
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
493 /**
ada4d850a820 lostParent and notFoundParenet
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
494 * 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
495 * 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
496 * @param dataLen
ada4d850a820 lostParent and notFoundParenet
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
497 * @param reader
ada4d850a820 lostParent and notFoundParenet
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
498 * @throws TransportException
ada4d850a820 lostParent and notFoundParenet
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 134
diff changeset
499 */
118
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
500 public void readSendData(int dataLen, Reader reader)
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
501 throws TransportException {
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
502 LinkedList<ByteBuffer> bufs = new LinkedList<ByteBuffer>();
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
503 ByteBuffer header = multicastqueue.allocate(16);
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
504 ByteBuffer serial = multicastqueue.allocate(8);
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
505 if (!isRoot()) {
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
506 reader.mark(dataLen+8); // +8 is serialnum
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
507 reader.readBytes(serial.array(),0,8);
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
508 serial.limit(8);
120
c1b14cef2704 MyRfb fix done.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 118
diff changeset
509 }
118
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
510 reader.readBytes(header.array(), 0, 16);
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
511 header.limit(16);
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
512 if (header.get(0) == FramebufferUpdate) {
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
513 int encoding = header.getInt(12);
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
514 if (encoding == EncodingType.ZRLE.getId()
120
c1b14cef2704 MyRfb fix done.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 118
diff changeset
515 || encoding == EncodingType.ZLIB.getId()) { // ZRLEE is already compressed
118
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
516 ByteBuffer len = multicastqueue.allocate(4);
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
517 reader.readBytes(len.array(), 0, 4);
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
518 len.limit(4);
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
519 ByteBuffer inputData = multicastqueue.allocate(dataLen - 20);
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
520 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
521 inputData.limit(dataLen - 20);
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
522 LinkedList<ByteBuffer> inputs = new LinkedList<ByteBuffer>();
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
523 inputs.add(inputData);
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 header.putInt(12, EncodingType.ZRLEE.getId()); // means
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
526 // recompress
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
527 // every time
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
528 // 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
529 // protocol, clients have to be modified.
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
530 Deflater nDeflater = deflater; // new Deflater();
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
531 LinkedList<ByteBuffer> out = new LinkedList<ByteBuffer>();
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
532 try {
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
533 unzip(inflater, inputs, 0, out, INFLATE_BUFSIZE);
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
534 // dump32(inputs);
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
535 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
536 ByteBuffer blen = multicastqueue.allocate(4);
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
537 blen.putInt(len2);
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
538 blen.flip();
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
539 bufs.addFirst(blen);
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
540 bufs.addFirst(header);
146
5be1d92e7835 not working yet
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 145
diff changeset
541 addSerialNumber(bufs);
118
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
542 multicastqueue.put(bufs);
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
543 if (!isRoot()) reader.reset();
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
544 } catch (DataFormatException e) {
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
545 throw new TransportException(e);
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
546 } catch (IOException e) {
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
547 throw new TransportException(e);
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
548 }
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
549 return;
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
550 }
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
551 bufs.add(header);
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
552 if (dataLen > 16) {
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
553 ByteBuffer b = multicastqueue.allocate(dataLen - 16);
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
554 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
555 b.limit(dataLen - 16);
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
556 bufs.add(b);
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
557 }
120
c1b14cef2704 MyRfb fix done.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 118
diff changeset
558 this.addSerialNumber(bufs);
118
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
559 multicastqueue.put(bufs);
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
560 return;
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 // 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
563 // decompressing here,
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
564 // 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
565 // each client.
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
566 // 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
567 // here.
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
568 }
124
214d4f206431 add TreeVNC command number.
oc
parents: 123
diff changeset
569
145
649794dfb9d5 add my hostname to handle multiple network
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 144
diff changeset
570 public abstract void addHostToSelectionPanel(int port, String hostname,String myHostName) ;
143
4547543ca73c findRootReply
oc
parents: 138
diff changeset
571
144
1e004d9c599d notify connection panel
oc
parents: 143
diff changeset
572 public void createRootSelectionPanel(CreateConnectionParam createConnectionParam) {
143
4547543ca73c findRootReply
oc
parents: 138
diff changeset
573
4547543ca73c findRootReply
oc
parents: 138
diff changeset
574 }
4547543ca73c findRootReply
oc
parents: 138
diff changeset
575
164
86289e56263c Send initData in server change
oc
parents: 160
diff changeset
576
28
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
577 }