annotate src/main/java/jp/ac/u_ryukyu/treevnc/MyRfbProto.java @ 130:1f6bfaa3281b

root selection panel
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Sat, 07 Jun 2014 00:03:13 +0900
parents a6dc674546f2
children 95f53663295c
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;
124
214d4f206431 add TreeVNC command number.
oc
parents: 123
diff changeset
4
118
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
5 import java.io.OutputStream;
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
6 import java.net.BindException;
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
7 import java.net.ServerSocket;
28
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
8 import java.net.Socket;
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
9 import java.nio.ByteBuffer;
109
457f9dfbf7ce minor fix.
oc
parents: 107
diff changeset
10 import java.nio.ByteOrder;
28
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
11 import java.util.LinkedList;
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
12 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
13 import java.util.zip.DataFormatException;
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
14 import java.util.zip.Deflater;
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
15 import java.util.zip.Inflater;
28
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
16
125
32c6563492f3 add vnc protocol command sender.
oc
parents: 124
diff changeset
17 import jp.ac.u_ryukyu.treevnc.client.TreeVncProtocol;
28
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
18 import jp.ac.u_ryukyu.treevnc.server.RequestScreenThread;
94
75879c316796 synchronized wait for Rfb initialization in change server.
oc
parents: 89
diff changeset
19 import jp.ac.u_ryukyu.treevnc.server.VncProxyService;
28
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
20
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
21 import com.glavsoft.exceptions.TransportException;
107
660b296d4f75 send change screen command throw the tree.
oc
parents: 103
diff changeset
22 import com.glavsoft.rfb.client.ClientToServerMessage;
96
76e49dd9c9c5 Client resize without reconnection
oc
parents: 94
diff changeset
23 import com.glavsoft.rfb.encoding.EncodingType;
28
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
24 import com.glavsoft.rfb.protocol.Protocol;
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
25 import com.glavsoft.rfb.protocol.ProtocolContext;
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
26 import com.glavsoft.transport.Reader;
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
27 import com.glavsoft.transport.Writer;
65
ffd7537cebfc cuiversion
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents: 64
diff changeset
28 import com.glavsoft.viewer.ViewerImpl;
28
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
29
124
214d4f206431 add TreeVNC command number.
oc
parents: 123
diff changeset
30
120
c1b14cef2704 MyRfb fix done.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 118
diff changeset
31 public abstract class MyRfbProto {
33
9d3478d11d3b Add the processing of client
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents: 32
diff changeset
32 final static int FramebufferUpdateRequest = 3;
28
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
33 final static int CheckDelay = 11;
103
84f254d8bde4 remove isinstaceof
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 102
diff changeset
34 protected final static int FramebufferUpdate = 0;
28
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
35 private ProtocolContext context;
103
84f254d8bde4 remove isinstaceof
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 102
diff changeset
36 protected final static String versionMsg_3_856 = "RFB 003.856\n";
28
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
37 private int clients;
98
8f4c45c1b396 add serial number to desktop size encoding packet.
oc
parents: 97
diff changeset
38 public MulticastQueue<LinkedList<ByteBuffer>> multicastqueue = new MulticastQueue<LinkedList<ByteBuffer>>();
28
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
39 private RequestScreenThread rThread;
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
40 private boolean proxyFlag = true;
125
32c6563492f3 add vnc protocol command sender.
oc
parents: 124
diff changeset
41 private TreeVncProtocol echo;
45
20326a4b9d88 create new change button for client.
one
parents: 43
diff changeset
42 private String proxyAddr;
118
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
43 public int acceptPort = 0;
94
75879c316796 synchronized wait for Rfb initialization in change server.
oc
parents: 89
diff changeset
44 protected boolean readyReconnect = false;
98
8f4c45c1b396 add serial number to desktop size encoding packet.
oc
parents: 97
diff changeset
45 private boolean cuiVersion;
107
660b296d4f75 send change screen command throw the tree.
oc
parents: 103
diff changeset
46 private long counter = 0; // packet serial number
660b296d4f75 send change screen command throw the tree.
oc
parents: 103
diff changeset
47 private VncProxyService viewer = null;
118
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
48 public ServerSocket servSock;
123
233e94a7b5ed add comment
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 122
diff changeset
49 private boolean permitChangeScreen = true;
118
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
50 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
51
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
52 private Inflater inflater = new Inflater();
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
53 private Deflater deflater = new Deflater();
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
54
107
660b296d4f75 send change screen command throw the tree.
oc
parents: 103
diff changeset
55
33
9d3478d11d3b Add the processing of client
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents: 32
diff changeset
56 public MyRfbProto() {
9d3478d11d3b Add the processing of client
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents: 32
diff changeset
57 rThread = new RequestScreenThread(this);
9d3478d11d3b Add the processing of client
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents: 32
diff changeset
58 }
107
660b296d4f75 send change screen command throw the tree.
oc
parents: 103
diff changeset
59
111
a7988d3c0266 minor fix.
oc
parents: 110
diff changeset
60 public void setVncProxy(VncProxyService viewer) {
107
660b296d4f75 send change screen command throw the tree.
oc
parents: 103
diff changeset
61 this.viewer = viewer;
660b296d4f75 send change screen command throw the tree.
oc
parents: 103
diff changeset
62 }
28
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
63
120
c1b14cef2704 MyRfb fix done.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 118
diff changeset
64 abstract public boolean isRoot() ;
28
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
65
124
214d4f206431 add TreeVNC command number.
oc
parents: 123
diff changeset
66 public boolean initialConnection(final Writer os, final Reader is)
214d4f206431 add TreeVNC command number.
oc
parents: 123
diff changeset
67 throws IOException, TransportException {
214d4f206431 add TreeVNC command number.
oc
parents: 123
diff changeset
68 /**
214d4f206431 add TreeVNC command number.
oc
parents: 123
diff changeset
69 * initial connection of RFB protocol
214d4f206431 add TreeVNC command number.
oc
parents: 123
diff changeset
70 */
214d4f206431 add TreeVNC command number.
oc
parents: 123
diff changeset
71 sendRfbVersion(os);
214d4f206431 add TreeVNC command number.
oc
parents: 123
diff changeset
72 byte[] b;
214d4f206431 add TreeVNC command number.
oc
parents: 123
diff changeset
73 if ((b = readVersionMsg(is, os))!=null) {
214d4f206431 add TreeVNC command number.
oc
parents: 123
diff changeset
74 treeVncCommand(b,is,os);
214d4f206431 add TreeVNC command number.
oc
parents: 123
diff changeset
75 return true;
214d4f206431 add TreeVNC command number.
oc
parents: 123
diff changeset
76 }
214d4f206431 add TreeVNC command number.
oc
parents: 123
diff changeset
77 sendSecurityType(os);
214d4f206431 add TreeVNC command number.
oc
parents: 123
diff changeset
78 readSecType(is);
214d4f206431 add TreeVNC command number.
oc
parents: 123
diff changeset
79 sendSecResult(os);
214d4f206431 add TreeVNC command number.
oc
parents: 123
diff changeset
80 readClientInit(is);
214d4f206431 add TreeVNC command number.
oc
parents: 123
diff changeset
81 sendInitData(os);
214d4f206431 add TreeVNC command number.
oc
parents: 123
diff changeset
82 return false;
214d4f206431 add TreeVNC command number.
oc
parents: 123
diff changeset
83 }
214d4f206431 add TreeVNC command number.
oc
parents: 123
diff changeset
84
130
1f6bfaa3281b root selection panel
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 129
diff changeset
85 /**
1f6bfaa3281b root selection panel
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 129
diff changeset
86 * handle TreeVNC Command
1f6bfaa3281b root selection panel
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 129
diff changeset
87 * @param b 12byte header ( command 4byte, length 4byte, port 4byte, option String )
1f6bfaa3281b root selection panel
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 129
diff changeset
88 * @param is
1f6bfaa3281b root selection panel
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 129
diff changeset
89 * @param os
1f6bfaa3281b root selection panel
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 129
diff changeset
90 */
124
214d4f206431 add TreeVNC command number.
oc
parents: 123
diff changeset
91 private void treeVncCommand(byte[] b, Reader is, Writer os) {
214d4f206431 add TreeVNC command number.
oc
parents: 123
diff changeset
92 ByteBuffer buf = ByteBuffer.wrap(b);
130
1f6bfaa3281b root selection panel
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 129
diff changeset
93 int command = buf.get()&0xff;
1f6bfaa3281b root selection panel
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 129
diff changeset
94 buf.position(buf.position()+3);
1f6bfaa3281b root selection panel
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 129
diff changeset
95 int length = buf.getInt();
1f6bfaa3281b root selection panel
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 129
diff changeset
96 int port = buf.getInt();
1f6bfaa3281b root selection panel
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 129
diff changeset
97 String hostname = null;
1f6bfaa3281b root selection panel
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 129
diff changeset
98 if (length>12) {
1f6bfaa3281b root selection panel
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 129
diff changeset
99 byte namebuf[] = new byte[length-12];
1f6bfaa3281b root selection panel
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 129
diff changeset
100 try {
1f6bfaa3281b root selection panel
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 129
diff changeset
101 is.readBytes(namebuf);
1f6bfaa3281b root selection panel
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 129
diff changeset
102 } catch (TransportException e) {
1f6bfaa3281b root selection panel
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 129
diff changeset
103 return;
1f6bfaa3281b root selection panel
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 129
diff changeset
104 }
1f6bfaa3281b root selection panel
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 129
diff changeset
105 hostname = new String(namebuf);
1f6bfaa3281b root selection panel
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 129
diff changeset
106 }
124
214d4f206431 add TreeVNC command number.
oc
parents: 123
diff changeset
107 switch (command) {
129
a6dc674546f2 change connection param expression timing.
oc
parents: 128
diff changeset
108 case ProtocolContext.FIND_ROOT_REPLY :
130
1f6bfaa3281b root selection panel
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 129
diff changeset
109 handleFindRootReply(port,hostname);
129
a6dc674546f2 change connection param expression timing.
oc
parents: 128
diff changeset
110 break;
124
214d4f206431 add TreeVNC command number.
oc
parents: 123
diff changeset
111 case ProtocolContext.FIND_ROOT :
214d4f206431 add TreeVNC command number.
oc
parents: 123
diff changeset
112 case ProtocolContext.WHERE_TO_CONNECT :
214d4f206431 add TreeVNC command number.
oc
parents: 123
diff changeset
113 case ProtocolContext.LOST_PARENT :
214d4f206431 add TreeVNC command number.
oc
parents: 123
diff changeset
114 System.out.println("get treeVNC command" + command);
214d4f206431 add TreeVNC command number.
oc
parents: 123
diff changeset
115 }
214d4f206431 add TreeVNC command number.
oc
parents: 123
diff changeset
116 }
214d4f206431 add TreeVNC command number.
oc
parents: 123
diff changeset
117
130
1f6bfaa3281b root selection panel
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 129
diff changeset
118 /**
1f6bfaa3281b root selection panel
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 129
diff changeset
119 * Accept FIND_ROOT_REPLY
1f6bfaa3281b root selection panel
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 129
diff changeset
120 * add replying TreeVNC root to RootSelection Panel
1f6bfaa3281b root selection panel
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 129
diff changeset
121 * @param port
1f6bfaa3281b root selection panel
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 129
diff changeset
122 * @param hostname
1f6bfaa3281b root selection panel
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 129
diff changeset
123 */
1f6bfaa3281b root selection panel
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 129
diff changeset
124 private void handleFindRootReply(int port, String hostname) {
129
a6dc674546f2 change connection param expression timing.
oc
parents: 128
diff changeset
125 viewer.addHostToSelectionPanel(port, hostname);
a6dc674546f2 change connection param expression timing.
oc
parents: 128
diff changeset
126 }
a6dc674546f2 change connection param expression timing.
oc
parents: 128
diff changeset
127
130
1f6bfaa3281b root selection panel
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 129
diff changeset
128 /**
1f6bfaa3281b root selection panel
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 129
diff changeset
129 * handle new client accept
1f6bfaa3281b root selection panel
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 129
diff changeset
130 * it also handle TreeVNC Command
1f6bfaa3281b root selection panel
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 129
diff changeset
131 * @param acceptThread
1f6bfaa3281b root selection panel
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 129
diff changeset
132 * @param newCli
1f6bfaa3281b root selection panel
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 129
diff changeset
133 * @param os
1f6bfaa3281b root selection panel
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 129
diff changeset
134 * @param is
1f6bfaa3281b root selection panel
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 129
diff changeset
135 * @throws IOException
1f6bfaa3281b root selection panel
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 129
diff changeset
136 * @throws TransportException
1f6bfaa3281b root selection panel
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 129
diff changeset
137 */
28
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
138 public void newClient(AcceptThread acceptThread, final Socket newCli,
124
214d4f206431 add TreeVNC command number.
oc
parents: 123
diff changeset
139 final Writer os, final Reader is) throws IOException, TransportException {
214d4f206431 add TreeVNC command number.
oc
parents: 123
diff changeset
140
214d4f206431 add TreeVNC command number.
oc
parents: 123
diff changeset
141
130
1f6bfaa3281b root selection panel
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 129
diff changeset
142 if (initialConnection(os, is)) {
1f6bfaa3281b root selection panel
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 129
diff changeset
143 // TreeVNC command is processed
1f6bfaa3281b root selection panel
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 129
diff changeset
144 newCli.close();
1f6bfaa3281b root selection panel
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 129
diff changeset
145 return;
1f6bfaa3281b root selection panel
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 129
diff changeset
146 }
124
214d4f206431 add TreeVNC command number.
oc
parents: 123
diff changeset
147
28
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
148 final int myId = clients;
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
149 final MulticastQueue.Client<LinkedList<ByteBuffer>> c = multicastqueue.newClient();
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
150 final AtomicInteger writerRunning = new AtomicInteger();
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
151 writerRunning.set(1);
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
152 /**
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
153 * Timeout thread. If a client is suspended, it has top of queue
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
154 * indefinitely, which caused memory overflow. After the timeout, we
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
155 * poll the queue and discard it. Start long wait if writer is running.
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
156 */
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
157 final Runnable timer = new Runnable() {
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
158 public void run() {
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
159 int count = 0;
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
160 for (;;) {
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
161 long timeout = 50000 / 8;
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
162 try {
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
163 synchronized (this) {
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
164 int state, flag;
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
165 writerRunning.set(0);
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
166 wait(timeout);
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
167 flag = 0;
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
168 while ((state = writerRunning.get()) == 0) {
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
169 c.poll(); // discard, should be timeout
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
170 count++;
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
171 if (flag == 0) {
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
172 System.out.println("Discarding " + myId
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
173 + " count=" + count);
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
174 flag = 1;
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
175 }
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
176 wait(10); // if this is too short, writer cannot
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
177 // take the poll, if this is too
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
178 // long, memory will overflow...
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
179 }
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
180 if (flag == 1)
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
181 System.out.println("Resuming " + myId
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
182 + " count=" + count);
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
183 if (state != 1) {
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
184 System.out.println("Client died " + myId);
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
185 break;
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
186 }
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
187 }
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
188 } catch (InterruptedException e) {
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
189 }
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
190 }
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
191 }
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
192 };
88
a719aa609e14 add name valuer threads.
oc
parents: 85
diff changeset
193 new Thread(timer, "timer-discard-multicastqueue").start();
28
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
194 /**
107
660b296d4f75 send change screen command throw the tree.
oc
parents: 103
diff changeset
195 * send all incoming from clients to parent.
28
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
196 */
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
197 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
198 public void run() {
28
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
199 for (;;) {
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
200 try {
113
bce2ef0a2e79 use ProtocolContext.sendMessage for upward command
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 112
diff changeset
201 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
202 final int c = is.readByte(b);
28
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
203 if (c <= 0)
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
204 throw new IOException();
107
660b296d4f75 send change screen command throw the tree.
oc
parents: 103
diff changeset
205 if (isRoot()) {
660b296d4f75 send change screen command throw the tree.
oc
parents: 103
diff changeset
206 if (b[0] == ClientToServerMessage.SERVER_CHANGE_REQUEST) {
660b296d4f75 send change screen command throw the tree.
oc
parents: 103
diff changeset
207 if (permitChangeScreen()) {
109
457f9dfbf7ce minor fix.
oc
parents: 107
diff changeset
208 ByteBuffer buf = ByteBuffer.wrap(b);
457f9dfbf7ce minor fix.
oc
parents: 107
diff changeset
209 buf.order(ByteOrder.BIG_ENDIAN);
457f9dfbf7ce minor fix.
oc
parents: 107
diff changeset
210 int length = buf.getInt(4);
107
660b296d4f75 send change screen command throw the tree.
oc
parents: 103
diff changeset
211 if (length == 0)
660b296d4f75 send change screen command throw the tree.
oc
parents: 103
diff changeset
212 continue;
660b296d4f75 send change screen command throw the tree.
oc
parents: 103
diff changeset
213 String newHostName = new String(b, 8, length);
111
a7988d3c0266 minor fix.
oc
parents: 110
diff changeset
214 System.out.println("Root server change request :" + newHostName);
107
660b296d4f75 send change screen command throw the tree.
oc
parents: 103
diff changeset
215 // please remove these numbers.
660b296d4f75 send change screen command throw the tree.
oc
parents: 103
diff changeset
216 if (viewer != null) {
660b296d4f75 send change screen command throw the tree.
oc
parents: 103
diff changeset
217 viewer.changeVNCServer(newHostName, 3200, 1980);
660b296d4f75 send change screen command throw the tree.
oc
parents: 103
diff changeset
218 }
660b296d4f75 send change screen command throw the tree.
oc
parents: 103
diff changeset
219 } else {
660b296d4f75 send change screen command throw the tree.
oc
parents: 103
diff changeset
220 continue;
660b296d4f75 send change screen command throw the tree.
oc
parents: 103
diff changeset
221 }
660b296d4f75 send change screen command throw the tree.
oc
parents: 103
diff changeset
222 }
110
464eb64e3fd6 minor fix.
oc
parents: 109
diff changeset
223 } 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
224 ClientToServerMessage sc = new ClientToServerMessage() {
bce2ef0a2e79 use ProtocolContext.sendMessage for upward command
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 112
diff changeset
225 @Override
bce2ef0a2e79 use ProtocolContext.sendMessage for upward command
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 112
diff changeset
226 public void send(Writer writer)
bce2ef0a2e79 use ProtocolContext.sendMessage for upward command
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 112
diff changeset
227 throws TransportException {
bce2ef0a2e79 use ProtocolContext.sendMessage for upward command
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 112
diff changeset
228 writer.write(b,0,c);
bce2ef0a2e79 use ProtocolContext.sendMessage for upward command
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 112
diff changeset
229 }
bce2ef0a2e79 use ProtocolContext.sendMessage for upward command
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 112
diff changeset
230 };
bce2ef0a2e79 use ProtocolContext.sendMessage for upward command
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 112
diff changeset
231 context.sendMessage(sc);
107
660b296d4f75 send change screen command throw the tree.
oc
parents: 103
diff changeset
232 }
28
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
233 // System.out.println("client read "+c);
89
1503a373ab73 close client correctly in -d mode.
oc
parents: 88
diff changeset
234 } catch (Exception e) {
28
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
235 try {
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
236 writerRunning.set(2);
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
237 os.close();
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
238 is.close();
36
b7d4d0349f99 write part of reconnection and remove warning.
one
parents: 35
diff changeset
239 break;
28
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
240 } catch (IOException e1) {
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
241 } catch (TransportException e1) {
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
242 e1.printStackTrace();
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
243 }
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
244 return;
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
245 }
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
246 }
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
247 }
107
660b296d4f75 send change screen command throw the tree.
oc
parents: 103
diff changeset
248
28
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
249 };
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
250 /**
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
251 * send packets to a client
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
252 */
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
253 Runnable sender = new Runnable() {
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
254 public void run() {
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
255 writerRunning.set(1);
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
256 try {
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
257 requestThreadNotify();
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
258
88
a719aa609e14 add name valuer threads.
oc
parents: 85
diff changeset
259 // after this, we discard upward packet.
a719aa609e14 add name valuer threads.
oc
parents: 85
diff changeset
260 new Thread(reader, "discard-upward-comm").start();
28
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
261 // writeFramebufferUpdateRequest(0,0, framebufferWidth,
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
262 // framebufferHeight, false );
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
263 for (;;) {
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
264 LinkedList<ByteBuffer> bufs = c.poll();
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
265 int inputIndex = 0;
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
266 ByteBuffer header = bufs.get(inputIndex);
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
267 if (header == null)
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
268 continue;
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
269 else if (header.get(0) == CheckDelay) {
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
270 writeToClient(os, bufs, inputIndex);
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
271 continue;
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
272 } else if (header.get(0) == FramebufferUpdate) {
63
84f1c39ba3bf temp commit
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents: 61
diff changeset
273 //System.out.println("client "+ myId);
28
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
274 }
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
275 /*
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
276 * if(i%20==0){ sendDataCheckDelay(); } i++;
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
277 */
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
278 writeToClient(os, bufs, inputIndex);
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
279 writerRunning.set(1); // yes my client is awaking.
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
280 }
89
1503a373ab73 close client correctly in -d mode.
oc
parents: 88
diff changeset
281 } catch (Exception e) {
28
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
282 try {
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
283 writerRunning.set(2);
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
284 os.close();
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
285 } catch (IOException e1) {
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
286 }
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
287 /* if socket closed cliList.remove(newCli); */
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
288 }
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
289 }
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
290
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
291 public void writeToClient(final Writer os,
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
292 LinkedList<ByteBuffer> bufs, int inputIndex)
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
293 throws TransportException {
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
294 while (inputIndex < bufs.size()) {
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
295 ByteBuffer b = bufs.get(inputIndex++);
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
296 os.write(b.array(), b.position(), b.limit());
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
297 }
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
298 os.flush();
74
f1938dd3b518 don't heap space error.
oc
parents: 69
diff changeset
299 bufs = null;
f1938dd3b518 don't heap space error.
oc
parents: 69
diff changeset
300 multicastqueue.heapAvailable();
28
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
301 }
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
302 };
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
303 clients++;
88
a719aa609e14 add name valuer threads.
oc
parents: 85
diff changeset
304 new Thread(sender, "writer-to-lower-node").start();
28
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
305
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
306 }
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
307
122
e2416a246c95 noScreenChange flag on command line ( should be on panel also )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 120
diff changeset
308
e2416a246c95 noScreenChange flag on command line ( should be on panel also )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 120
diff changeset
309 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
310 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
311 }
e2416a246c95 noScreenChange flag on command line ( should be on panel also )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 120
diff changeset
312
e2416a246c95 noScreenChange flag on command line ( should be on panel also )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 120
diff changeset
313
e2416a246c95 noScreenChange flag on command line ( should be on panel also )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 120
diff changeset
314 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
315 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
316 }
e2416a246c95 noScreenChange flag on command line ( should be on panel also )
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 120
diff changeset
317
88
a719aa609e14 add name valuer threads.
oc
parents: 85
diff changeset
318 public void requestThreadNotify() {
28
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
319 rThread.reStart();
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
320 }
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
321
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
322 private void sendRfbVersion(Writer writer) throws IOException, TransportException {
54
0ae87c7e767c bug fix
one
parents: 52
diff changeset
323 writer.write(versionMsg_3_856.getBytes());
28
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
324 }
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
325
124
214d4f206431 add TreeVNC command number.
oc
parents: 123
diff changeset
326 private byte[] readVersionMsg(Reader reader, Writer writer) throws IOException, TransportException {
28
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
327
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
328 byte[] b = new byte[12];
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
329
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
330 reader.readBytes(b);
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
331
128
0cf1541f69bb find root reply is accepted.
oc
parents: 126
diff changeset
332 if ((b[0]&0xff)>=220) return b; // TreeVNC extention command.
28
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
333 if ((b[0] != 'R') || (b[1] != 'F') || (b[2] != 'B') || (b[3] != ' ')
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
334 || (b[4] < '0') || (b[4] > '9') || (b[5] < '0') || (b[5] > '9')
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
335 || (b[6] < '0') || (b[6] > '9') || (b[7] != '.')
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
336 || (b[8] < '0') || (b[8] > '9') || (b[9] < '0') || (b[9] > '9')
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
337 || (b[10] < '0') || (b[10] > '9') || (b[11] != '\n')) {
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
338 throw new IOException("this is not an RFB server");
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
339 }
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
340
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
341 int rfbMajor = (b[4] - '0') * 100 + (b[5] - '0') * 10 + (b[6] - '0');
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
342 int rfbMinor = (b[8] - '0') * 100 + (b[9] - '0') * 10 + (b[10] - '0');
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
343
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
344 if (rfbMajor < 3) {
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
345 throw new IOException(
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
346 "RFB server does not support protocol version 3");
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
347 }
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
348
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
349 if (rfbMinor == 855) {
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
350 sendProxyFlag(writer);
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
351 if (proxyFlag)
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
352 sendPortNumber(writer);
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
353 }
124
214d4f206431 add TreeVNC command number.
oc
parents: 123
diff changeset
354 return null;
28
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
355 }
45
20326a4b9d88 create new change button for client.
one
parents: 43
diff changeset
356
28
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
357
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
358 private void sendProxyFlag(Writer writer) throws TransportException {
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
359 if (proxyFlag)
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
360 writer.writeInt(1);
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
361 else
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
362 writer.writeInt(0);
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
363 }
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
364
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
365 private void sendPortNumber(Writer writer) throws TransportException {
118
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
366 ByteBuffer b = ByteBuffer.allocate(4);
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
367 b.order(ByteOrder.BIG_ENDIAN);
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
368 b.putInt(9999);
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
369 writer.write(b.array());
28
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
370 }
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
371
45
20326a4b9d88 create new change button for client.
one
parents: 43
diff changeset
372
28
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
373 private void readSecType(Reader reader) throws TransportException {
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
374 byte[] b = new byte[1];
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
375 reader.read(b);
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
376 }
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
377
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
378 private void sendSecurityType(Writer os) throws TransportException {
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
379 // number-of-security-types
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
380 os.writeInt(1);
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
381 // security-types
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
382 // 1:None
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
383 os.writeInt(1);
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
384
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
385 /*
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
386 * os.write(4); os.write(30); os.write(31); os.write(32); os.write(35);
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
387 * os.flush();
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
388 */
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
389 }
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
390
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
391 private void sendSecResult(Writer os) throws TransportException {
118
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
392 ByteBuffer b = ByteBuffer.allocate(4);
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
393 b.order(ByteOrder.BIG_ENDIAN);
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
394 b.putInt(0);
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
395 os.write(b.array());
28
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
396 }
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
397
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
398 private void readClientInit(Reader in) throws TransportException {
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
399 byte[] b = new byte[0];
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
400 in.readBytes(b);
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
401 }
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
402
85
432dac0b9dae delete Share Screen pop up in display mode.
sugi
parents: 77
diff changeset
403 byte initData[] = {7, -128, 4, 56, 32, 24, 0, 1, 0, -1, 0, -1, 0, -1, 16, 8, 0, 0, 0, 0, 0, 0, 0, 7, 102, 105, 114, 101, 102, 108, 121};
28
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
404 private void sendInitData(Writer os) throws TransportException {
85
432dac0b9dae delete Share Screen pop up in display mode.
sugi
parents: 77
diff changeset
405 // In case of "-d" we have no context
432dac0b9dae delete Share Screen pop up in display mode.
sugi
parents: 77
diff changeset
406 if (context != null){
432dac0b9dae delete Share Screen pop up in display mode.
sugi
parents: 77
diff changeset
407 os.write(context.getInitData());
432dac0b9dae delete Share Screen pop up in display mode.
sugi
parents: 77
diff changeset
408 } else {
432dac0b9dae delete Share Screen pop up in display mode.
sugi
parents: 77
diff changeset
409 // Send dummy data
432dac0b9dae delete Share Screen pop up in display mode.
sugi
parents: 77
diff changeset
410 os.write(initData);
432dac0b9dae delete Share Screen pop up in display mode.
sugi
parents: 77
diff changeset
411 }
28
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
412 }
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
413
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
414 public void setProtocolContext(Protocol workingProtocol) {
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
415 context = workingProtocol;
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
416 }
29
57eb5575e6c4 MyRfbProto for client and proxy.
one
parents: 28
diff changeset
417
57eb5575e6c4 MyRfbProto for client and proxy.
one
parents: 28
diff changeset
418
31
872d9bcbfe56 Before changing the Viewer.
one
parents: 29
diff changeset
419 public Socket accept() throws IOException {
872d9bcbfe56 Before changing the Viewer.
one
parents: 29
diff changeset
420 return null;
872d9bcbfe56 Before changing the Viewer.
one
parents: 29
diff changeset
421 }
872d9bcbfe56 Before changing the Viewer.
one
parents: 29
diff changeset
422
118
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
423 public void initServSock(int port) throws IOException {
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
424 servSock = new ServerSocket(port);
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
425 acceptPort = port;
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
426 }
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
427
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
428 public int selectPort(int p) {
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
429 int port = p;
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
430 while (true) {
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
431 try {
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
432 initServSock(port);
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
433 break;
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
434 } catch (BindException e) {
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
435 port++;
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
436 continue;
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
437 } catch (IOException e) {
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 }
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
441 System.out.println("accept port = " + port);
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
442 return port;
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
443 }
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
444
33
9d3478d11d3b Add the processing of client
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents: 32
diff changeset
445
9d3478d11d3b Add the processing of client
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents: 32
diff changeset
446
9d3478d11d3b Add the processing of client
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents: 32
diff changeset
447 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
448 boolean incremental) throws TransportException {
9d3478d11d3b Add the processing of client
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents: 32
diff changeset
449 byte[] b = new byte[10];
9d3478d11d3b Add the processing of client
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents: 32
diff changeset
450
9d3478d11d3b Add the processing of client
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents: 32
diff changeset
451 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
452 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
453 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
454 b[3] = (byte) (x & 0xff);
9d3478d11d3b Add the processing of client
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents: 32
diff changeset
455 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
456 b[5] = (byte) (y & 0xff);
9d3478d11d3b Add the processing of client
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents: 32
diff changeset
457 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
458 b[7] = (byte) (w & 0xff);
9d3478d11d3b Add the processing of client
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents: 32
diff changeset
459 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
460 b[9] = (byte) (h & 0xff);
9d3478d11d3b Add the processing of client
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents: 32
diff changeset
461
9d3478d11d3b Add the processing of client
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents: 32
diff changeset
462 // os.write(b);
9d3478d11d3b Add the processing of client
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents: 32
diff changeset
463 }
9d3478d11d3b Add the processing of client
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents: 32
diff changeset
464
9d3478d11d3b Add the processing of client
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents: 32
diff changeset
465 public void notProxy() {
9d3478d11d3b Add the processing of client
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents: 32
diff changeset
466 proxyFlag = false;
9d3478d11d3b Add the processing of client
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents: 32
diff changeset
467 }
35
1b81deb0abb3 write a little part reconnection.
one
parents: 33
diff changeset
468
125
32c6563492f3 add vnc protocol command sender.
oc
parents: 124
diff changeset
469 public void setEcho(TreeVncProtocol _echo) {
35
1b81deb0abb3 write a little part reconnection.
one
parents: 33
diff changeset
470 echo = _echo;
1b81deb0abb3 write a little part reconnection.
one
parents: 33
diff changeset
471 }
1b81deb0abb3 write a little part reconnection.
one
parents: 33
diff changeset
472
65
ffd7537cebfc cuiversion
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents: 64
diff changeset
473 public void setViewer(ViewerImpl v) {
36
b7d4d0349f99 write part of reconnection and remove warning.
one
parents: 35
diff changeset
474 echo.setViewer(v);
b7d4d0349f99 write part of reconnection and remove warning.
one
parents: 35
diff changeset
475 }
b7d4d0349f99 write part of reconnection and remove warning.
one
parents: 35
diff changeset
476
65
ffd7537cebfc cuiversion
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents: 64
diff changeset
477 public ViewerImpl getViewer() {
ffd7537cebfc cuiversion
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents: 64
diff changeset
478 return echo.getViewer();
ffd7537cebfc cuiversion
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents: 64
diff changeset
479 }
ffd7537cebfc cuiversion
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents: 64
diff changeset
480
125
32c6563492f3 add vnc protocol command sender.
oc
parents: 124
diff changeset
481 public TreeVncProtocol getEcho() {
35
1b81deb0abb3 write a little part reconnection.
one
parents: 33
diff changeset
482 return echo;
1b81deb0abb3 write a little part reconnection.
one
parents: 33
diff changeset
483 }
43
6687aa9dd55e add flag for screen change in ReciverTask.java.
one
parents: 38
diff changeset
484
6687aa9dd55e add flag for screen change in ReciverTask.java.
one
parents: 38
diff changeset
485 public void setTerminationType(boolean setType) {
6687aa9dd55e add flag for screen change in ReciverTask.java.
one
parents: 38
diff changeset
486 /*nop*/
6687aa9dd55e add flag for screen change in ReciverTask.java.
one
parents: 38
diff changeset
487 }
6687aa9dd55e add flag for screen change in ReciverTask.java.
one
parents: 38
diff changeset
488
6687aa9dd55e add flag for screen change in ReciverTask.java.
one
parents: 38
diff changeset
489 public boolean getTerminationType() {
6687aa9dd55e add flag for screen change in ReciverTask.java.
one
parents: 38
diff changeset
490 /*nop*/
6687aa9dd55e add flag for screen change in ReciverTask.java.
one
parents: 38
diff changeset
491 return true;
6687aa9dd55e add flag for screen change in ReciverTask.java.
one
parents: 38
diff changeset
492 }
45
20326a4b9d88 create new change button for client.
one
parents: 43
diff changeset
493
20326a4b9d88 create new change button for client.
one
parents: 43
diff changeset
494 public void setProxyAddr(String proxyAddr) {
20326a4b9d88 create new change button for client.
one
parents: 43
diff changeset
495 this.proxyAddr = proxyAddr;
20326a4b9d88 create new change button for client.
one
parents: 43
diff changeset
496 }
52
986f16afb753 update before change host.
one
parents: 45
diff changeset
497
118
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
498 void sendProxyFlag(OutputStream os) throws IOException {
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
499 if (proxyFlag)
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
500 os.write(1);
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
501 else
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
502 os.write(0);
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
503 }
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
504
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
505
52
986f16afb753 update before change host.
one
parents: 45
diff changeset
506
986f16afb753 update before change host.
one
parents: 45
diff changeset
507 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
508 // none
52
986f16afb753 update before change host.
one
parents: 45
diff changeset
509 }
45
20326a4b9d88 create new change button for client.
one
parents: 43
diff changeset
510
60
ac6f9e46566f proxy mode ok.
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents: 59
diff changeset
511 public int getAcceptPort() {
118
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
512 return acceptPort;
60
ac6f9e46566f proxy mode ok.
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents: 59
diff changeset
513 }
ac6f9e46566f proxy mode ok.
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents: 59
diff changeset
514
61
d9cf08c6415c During implementation change screen.
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents: 60
diff changeset
515 public boolean getReadyReconnect() {
d9cf08c6415c During implementation change screen.
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents: 60
diff changeset
516 return readyReconnect;
d9cf08c6415c During implementation change screen.
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents: 60
diff changeset
517 }
65
ffd7537cebfc cuiversion
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents: 64
diff changeset
518
ffd7537cebfc cuiversion
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents: 64
diff changeset
519
ffd7537cebfc cuiversion
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents: 64
diff changeset
520 public boolean getCuiVersion() {
ffd7537cebfc cuiversion
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents: 64
diff changeset
521 return cuiVersion;
61
d9cf08c6415c During implementation change screen.
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents: 60
diff changeset
522 }
65
ffd7537cebfc cuiversion
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents: 64
diff changeset
523
ffd7537cebfc cuiversion
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents: 64
diff changeset
524 public void setCuiVersion(boolean flag) {
ffd7537cebfc cuiversion
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents: 64
diff changeset
525 cuiVersion = flag;
ffd7537cebfc cuiversion
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents: 64
diff changeset
526 }
66
84ad879891e9 dont move
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents: 65
diff changeset
527
84ad879891e9 dont move
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents: 65
diff changeset
528 public void readCheckDelay(Reader reader) throws TransportException {
84ad879891e9 dont move
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents: 65
diff changeset
529
84ad879891e9 dont move
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents: 65
diff changeset
530 }
84ad879891e9 dont move
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents: 65
diff changeset
531
84ad879891e9 dont move
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents: 65
diff changeset
532 public String getProxyAddr() {
84ad879891e9 dont move
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents: 65
diff changeset
533 return proxyAddr;
84ad879891e9 dont move
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents: 65
diff changeset
534 }
65
ffd7537cebfc cuiversion
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents: 64
diff changeset
535
94
75879c316796 synchronized wait for Rfb initialization in change server.
oc
parents: 89
diff changeset
536 public synchronized void setReadyReconnect(boolean ready) {
75879c316796 synchronized wait for Rfb initialization in change server.
oc
parents: 89
diff changeset
537 readyReconnect = ready;
75879c316796 synchronized wait for Rfb initialization in change server.
oc
parents: 89
diff changeset
538 if (ready) {
75879c316796 synchronized wait for Rfb initialization in change server.
oc
parents: 89
diff changeset
539 notifyAll();
75879c316796 synchronized wait for Rfb initialization in change server.
oc
parents: 89
diff changeset
540 }
75879c316796 synchronized wait for Rfb initialization in change server.
oc
parents: 89
diff changeset
541 }
75879c316796 synchronized wait for Rfb initialization in change server.
oc
parents: 89
diff changeset
542
75879c316796 synchronized wait for Rfb initialization in change server.
oc
parents: 89
diff changeset
543 public synchronized void waitForReady(VncProxyService vncProxyService) throws InterruptedException {
75879c316796 synchronized wait for Rfb initialization in change server.
oc
parents: 89
diff changeset
544 while (!readyReconnect) {
75879c316796 synchronized wait for Rfb initialization in change server.
oc
parents: 89
diff changeset
545 wait();
75879c316796 synchronized wait for Rfb initialization in change server.
oc
parents: 89
diff changeset
546 }
75879c316796 synchronized wait for Rfb initialization in change server.
oc
parents: 89
diff changeset
547 }
96
76e49dd9c9c5 Client resize without reconnection
oc
parents: 94
diff changeset
548
76e49dd9c9c5 Client resize without reconnection
oc
parents: 94
diff changeset
549
76e49dd9c9c5 Client resize without reconnection
oc
parents: 94
diff changeset
550 public void sendDesktopSizeChange() {
76e49dd9c9c5 Client resize without reconnection
oc
parents: 94
diff changeset
551 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
552 int width = context.getFbWidth();
44f5cdc63a76 don't create Rfb and VNC proxy on change server on root.
oc
parents: 96
diff changeset
553 int height = context.getFbHeight();
44f5cdc63a76 don't create Rfb and VNC proxy on change server on root.
oc
parents: 96
diff changeset
554 desktopSize.add(new UpdateRectangleMessage(0,0, width, height, EncodingType.DESKTOP_SIZE).getMessage());
99
da5f74092be8 minor fix.
oc
parents: 98
diff changeset
555 addSerialNumber(desktopSize);
96
76e49dd9c9c5 Client resize without reconnection
oc
parents: 94
diff changeset
556 multicastqueue.put(desktopSize);
76e49dd9c9c5 Client resize without reconnection
oc
parents: 94
diff changeset
557 }
98
8f4c45c1b396 add serial number to desktop size encoding packet.
oc
parents: 97
diff changeset
558
8f4c45c1b396 add serial number to desktop size encoding packet.
oc
parents: 97
diff changeset
559
8f4c45c1b396 add serial number to desktop size encoding packet.
oc
parents: 97
diff changeset
560 public void addSerialNumber(LinkedList<ByteBuffer> bufs) {
8f4c45c1b396 add serial number to desktop size encoding packet.
oc
parents: 97
diff changeset
561 ByteBuffer serialNum = multicastqueue.allocate(8);
8f4c45c1b396 add serial number to desktop size encoding packet.
oc
parents: 97
diff changeset
562 serialNum.putLong(counter++);
8f4c45c1b396 add serial number to desktop size encoding packet.
oc
parents: 97
diff changeset
563 serialNum.flip();
8f4c45c1b396 add serial number to desktop size encoding packet.
oc
parents: 97
diff changeset
564 bufs.addFirst(serialNum);
8f4c45c1b396 add serial number to desktop size encoding packet.
oc
parents: 97
diff changeset
565 }
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
566
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
567
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
568 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
569 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
570 }
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
571
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
572 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
573 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
574 context.cleanUpSession(null);
118
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
575 // cleanup zlib decoder for new VNCServer
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
576 if (isRoot())
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
577 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
578 }
113
bce2ef0a2e79 use ProtocolContext.sendMessage for upward command
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 112
diff changeset
579
bce2ef0a2e79 use ProtocolContext.sendMessage for upward command
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 112
diff changeset
580 public String getMyAddress() {
bce2ef0a2e79 use ProtocolContext.sendMessage for upward command
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 112
diff changeset
581 return echo.getMyAddress();
bce2ef0a2e79 use ProtocolContext.sendMessage for upward command
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 112
diff changeset
582 }
118
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
583
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 * gzip byte arrays
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
586 *
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
587 * @param deflater
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
588 * @param inputs
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
589 * byte data[]
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
590 * @param inputIndex
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
591 * @param outputs
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
592 * byte data[]
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
593 * @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
594 * @throws IOException
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
595 */
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
596 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
597 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
598 int len = 0;
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
599 ByteBuffer c1 = multicastqueue.allocate(INFLATE_BUFSIZE);
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
600 while (inputIndex < inputs.size()) {
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
601 ByteBuffer b1 = inputs.get(inputIndex++);
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
602 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
603 /**
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
604 * 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
605 * 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
606 * 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
607 * 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
608 * of bug of Java library.
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
609 */
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
610 if (inputIndex == inputs.size())
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
611 deflater.finish();
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
612 int len1 = 0;
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
613 do {
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
614 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
615 c1.remaining());
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
616 if (len1 > 0) {
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
617 len += len1;
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
618 c1.position(c1.position() + len1);
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
619 if (c1.remaining() == 0) {
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
620 c1.flip();
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
621 outputs.addLast(c1);
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
622 c1 = multicastqueue.allocate(INFLATE_BUFSIZE);
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
623 }
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
624 }
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
625 } 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
626 }
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
627 if (c1.position() != 0) {
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
628 c1.flip();
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
629 outputs.addLast(c1);
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
630 }
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
631 deflater.reset();
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
632 return len;
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
633 }
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
634
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
635 /**
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
636 * gunzip byte arrays
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
637 *
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
638 * @param inflater
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
639 * @param inputs
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
640 * byte data[]
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
641 * @param outputs
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
642 * byte data[]
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
643 * @return number of total bytes
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
644 * @throws IOException
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
645 */
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
646 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
647 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
648 throws DataFormatException {
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
649 int len = 0;
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
650 ByteBuffer buf = multicastqueue.allocate(bufSize);
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
651 while (inputIndex < inputs.size()) {
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
652 ByteBuffer input = inputs.get(inputIndex++);
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
653 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
654 // 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
655 // we need this
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
656 // 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
657 do {
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
658 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
659 buf.remaining());
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
660 if (len0 > 0) {
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
661 buf.position(buf.position() + len0);
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
662 len += len0;
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
663 if (buf.remaining() == 0) {
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
664 buf.flip();
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
665 outputs.addLast(buf);
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
666 buf = multicastqueue.allocate(bufSize);
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
667 }
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
668 }
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
669 } while (!inflater.needsInput());
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
670 }
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
671 if (buf.position() != 0) {
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
672 buf.flip();
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
673 outputs.addLast(buf);
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
674 }
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
675 return len;
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
676 }
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
677
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
678 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
679 throws TransportException {
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
680 LinkedList<ByteBuffer> bufs = new LinkedList<ByteBuffer>();
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
681 ByteBuffer header = multicastqueue.allocate(16);
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
682 ByteBuffer serial = multicastqueue.allocate(8);
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
683 if (!isRoot()) {
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
684 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
685 reader.readBytes(serial.array(),0,8);
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
686 serial.limit(8);
120
c1b14cef2704 MyRfb fix done.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 118
diff changeset
687 }
118
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
688 reader.readBytes(header.array(), 0, 16);
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
689 header.limit(16);
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
690 if (header.get(0) == FramebufferUpdate) {
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
691 int encoding = header.getInt(12);
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
692 if (encoding == EncodingType.ZRLE.getId()
120
c1b14cef2704 MyRfb fix done.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 118
diff changeset
693 || 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
694 ByteBuffer len = multicastqueue.allocate(4);
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
695 reader.readBytes(len.array(), 0, 4);
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
696 len.limit(4);
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
697 ByteBuffer inputData = multicastqueue.allocate(dataLen - 20);
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
698 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
699 inputData.limit(dataLen - 20);
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
700 LinkedList<ByteBuffer> inputs = new LinkedList<ByteBuffer>();
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
701 inputs.add(inputData);
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
702
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
703 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
704 // recompress
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
705 // every time
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
706 // 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
707 // protocol, clients have to be modified.
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
708 Deflater nDeflater = deflater; // new Deflater();
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
709 LinkedList<ByteBuffer> out = new LinkedList<ByteBuffer>();
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
710 try {
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
711 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
712 // dump32(inputs);
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
713 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
714 ByteBuffer blen = multicastqueue.allocate(4);
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
715 blen.putInt(len2);
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
716 blen.flip();
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
717 bufs.addFirst(blen);
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
718 bufs.addFirst(header);
120
c1b14cef2704 MyRfb fix done.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 118
diff changeset
719 this.addSerialNumber(bufs);
118
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
720 multicastqueue.put(bufs);
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
721 if (!isRoot()) reader.reset();
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
722 } catch (DataFormatException e) {
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
723 throw new TransportException(e);
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
724 } catch (IOException e) {
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
725 throw new TransportException(e);
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
726 }
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
727 return;
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
728 }
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
729 bufs.add(header);
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
730 if (dataLen > 16) {
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
731 ByteBuffer b = multicastqueue.allocate(dataLen - 16);
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
732 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
733 b.limit(dataLen - 16);
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
734 bufs.add(b);
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
735 }
120
c1b14cef2704 MyRfb fix done.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 118
diff changeset
736 this.addSerialNumber(bufs);
118
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
737 multicastqueue.put(bufs);
120
c1b14cef2704 MyRfb fix done.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 118
diff changeset
738 if (!isRoot()) reader.reset();
118
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
739 return;
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
740 }
120
c1b14cef2704 MyRfb fix done.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 118
diff changeset
741 if (isRoot()) reader.reset();
118
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
742 // 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
743 // decompressing here,
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
744 // 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
745 // each client.
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
746 // 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
747 // here.
38e461e9b9c9 remove duplicated code in MyRfbProto*
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 113
diff changeset
748 }
124
214d4f206431 add TreeVNC command number.
oc
parents: 123
diff changeset
749
214d4f206431 add TreeVNC command number.
oc
parents: 123
diff changeset
750
28
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
751 }