annotate src/main/java/jp/ac/u_ryukyu/treevnc/MyRfbProto.java @ 77:cdf7bbe45885

remove some warnings
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Tue, 29 Apr 2014 18:00:34 +0900
parents f1938dd3b518
children 432dac0b9dae
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
45
20326a4b9d88 create new change button for client.
one
parents: 43
diff changeset
3 import java.io.DataOutputStream;
28
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
4 import java.io.IOException;
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
5 import java.net.Socket;
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
6 import java.nio.ByteBuffer;
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
7 import java.util.LinkedList;
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
8 import java.util.concurrent.atomic.AtomicInteger;
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
9
35
1b81deb0abb3 write a little part reconnection.
one
parents: 33
diff changeset
10 import jp.ac.u_ryukyu.treevnc.client.EchoClient;
28
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
11 import jp.ac.u_ryukyu.treevnc.server.RequestScreenThread;
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
12
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
13 import com.glavsoft.exceptions.TransportException;
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
14 import com.glavsoft.rfb.protocol.Protocol;
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
15 import com.glavsoft.rfb.protocol.ProtocolContext;
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
16 import com.glavsoft.transport.Reader;
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
17 import com.glavsoft.transport.Writer;
65
ffd7537cebfc cuiversion
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents: 64
diff changeset
18 import com.glavsoft.viewer.ViewerImpl;
28
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
19
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
20 public class MyRfbProto {
33
9d3478d11d3b Add the processing of client
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents: 32
diff changeset
21 final static int FramebufferUpdateRequest = 3;
28
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
22 final static int CheckDelay = 11;
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
23 final static int FramebufferUpdate = 0;
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
24 private ProtocolContext context;
54
0ae87c7e767c bug fix
one
parents: 52
diff changeset
25 //final static String versionMsg_3_855 = "RFB 003.855\n";
0ae87c7e767c bug fix
one
parents: 52
diff changeset
26 final static String versionMsg_3_856 = "RFB 003.856\n";
28
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
27 private int clients;
32
758d025ee24b add TextBox.java
one
parents: 31
diff changeset
28 protected MulticastQueue<LinkedList<ByteBuffer>> multicastqueue = new MulticastQueue<LinkedList<ByteBuffer>>();
28
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
29 private RequestScreenThread rThread;
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
30 private boolean proxyFlag = true;
35
1b81deb0abb3 write a little part reconnection.
one
parents: 33
diff changeset
31 private EchoClient echo;
45
20326a4b9d88 create new change button for client.
one
parents: 43
diff changeset
32 private String proxyAddr;
60
ac6f9e46566f proxy mode ok.
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents: 59
diff changeset
33 public int acceptPort;
65
ffd7537cebfc cuiversion
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents: 64
diff changeset
34 protected boolean readyReconnect;
ffd7537cebfc cuiversion
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents: 64
diff changeset
35 private boolean cuiVersion;
33
9d3478d11d3b Add the processing of client
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents: 32
diff changeset
36
9d3478d11d3b Add the processing of client
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents: 32
diff changeset
37 public MyRfbProto() {
9d3478d11d3b Add the processing of client
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents: 32
diff changeset
38 rThread = new RequestScreenThread(this);
9d3478d11d3b Add the processing of client
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents: 32
diff changeset
39 }
28
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
40
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
41
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
42 public void newClient(AcceptThread acceptThread, final Socket newCli,
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
43 final Writer os, final Reader is) throws IOException {
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
44 // createBimgFlag = true;
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
45 // rfb.addSockTmp(newCli);
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
46 // addSock(newCli);
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
47 final int myId = clients;
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
48 final MulticastQueue.Client<LinkedList<ByteBuffer>> c = multicastqueue.newClient();
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
49 final AtomicInteger writerRunning = new AtomicInteger();
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
50 writerRunning.set(1);
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
51 /**
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
52 * Timeout thread. If a client is suspended, it has top of queue
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
53 * indefinitely, which caused memory overflow. After the timeout, we
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
54 * poll the queue and discard it. Start long wait if writer is running.
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
55 */
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
56 final Runnable timer = new Runnable() {
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
57 public void run() {
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
58 int count = 0;
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
59 for (;;) {
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
60 long timeout = 50000 / 8;
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
61 try {
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
62 synchronized (this) {
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
63 int state, flag;
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
64 writerRunning.set(0);
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
65 wait(timeout);
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
66 flag = 0;
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
67 while ((state = writerRunning.get()) == 0) {
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
68 c.poll(); // discard, should be timeout
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
69 count++;
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
70 if (flag == 0) {
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
71 System.out.println("Discarding " + myId
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
72 + " count=" + count);
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
73 flag = 1;
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
74 }
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
75 wait(10); // if this is too short, writer cannot
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
76 // take the poll, if this is too
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
77 // long, memory will overflow...
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
78 }
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
79 if (flag == 1)
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
80 System.out.println("Resuming " + myId
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
81 + " count=" + count);
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
82 if (state != 1) {
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
83 System.out.println("Client died " + myId);
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
84 break;
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
85 }
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
86 }
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
87 } catch (InterruptedException e) {
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
88 }
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
89 }
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
90 }
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
91 };
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
92 new Thread(timer).start();
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
93 /**
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
94 * discard all incoming from clients
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
95 */
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
96 final Runnable reader = new Runnable() {
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
97 public void run() {
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
98 byte b[] = new byte[4096];
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
99 for (;;) {
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
100 try {
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
101 int c = is.readByte(b);
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
102 if (c <= 0)
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
103 throw new IOException();
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
104 // System.out.println("client read "+c);
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
105 } catch (IOException e) {
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
106 try {
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
107 writerRunning.set(2);
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
108 os.close();
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
109 is.close();
36
b7d4d0349f99 write part of reconnection and remove warning.
one
parents: 35
diff changeset
110 break;
28
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
111 } catch (IOException e1) {
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
112 } catch (TransportException e1) {
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
113 e1.printStackTrace();
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
114 }
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
115 return;
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
116 } catch (TransportException e) {
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
117 e.printStackTrace();
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 };
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
122 /**
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
123 * send packets to a client
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
124 */
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
125 Runnable sender = new Runnable() {
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
126 public void run() {
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
127 writerRunning.set(1);
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
128 try {
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
129 requestThreadNotify();
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
130 // rThread.checkDelay();
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
131
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
132 /**
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
133 * initial connection of RFB protocol
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
134 */
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
135 sendRfbVersion(os);
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
136 // readVersionMsg(is);
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
137 readVersionMsg(is, os);
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
138 sendSecurityType(os);
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
139 readSecType(is);
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
140 sendSecResult(os);
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
141 readClientInit(is);
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
142 sendInitData(os);
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
143 new Thread(reader).start(); // discard incoming packet here
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
144 // after.
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
145 // writeFramebufferUpdateRequest(0,0, framebufferWidth,
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
146 // framebufferHeight, false );
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
147 for (;;) {
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
148 LinkedList<ByteBuffer> bufs = c.poll();
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
149 int inputIndex = 0;
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
150 ByteBuffer header = bufs.get(inputIndex);
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
151 if (header == null)
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
152 continue;
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
153 else if (header.get(0) == CheckDelay) {
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
154 writeToClient(os, bufs, inputIndex);
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
155 continue;
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
156 } else if (header.get(0) == FramebufferUpdate) {
63
84f1c39ba3bf temp commit
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents: 61
diff changeset
157 //System.out.println("client "+ myId);
28
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
158 }
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
159 /*
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
160 * if(i%20==0){ sendDataCheckDelay(); } i++;
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
161 */
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
162 writeToClient(os, bufs, inputIndex);
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
163 writerRunning.set(1); // yes my client is awaking.
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
164 }
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
165 } catch (IOException e) {
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
166 try {
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
167 writerRunning.set(2);
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
168 os.close();
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
169 } catch (IOException e1) {
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
170 }
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
171 /* if socket closed cliList.remove(newCli); */
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
172 } catch (TransportException e) {
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
173 e.printStackTrace();
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
174 }
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 public void writeToClient(final Writer os,
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
178 LinkedList<ByteBuffer> bufs, int inputIndex)
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
179 throws TransportException {
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
180 while (inputIndex < bufs.size()) {
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
181 ByteBuffer b = bufs.get(inputIndex++);
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
182 os.write(b.array(), b.position(), b.limit());
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
183 }
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
184 os.flush();
74
f1938dd3b518 don't heap space error.
oc
parents: 69
diff changeset
185 bufs = null;
f1938dd3b518 don't heap space error.
oc
parents: 69
diff changeset
186 multicastqueue.heapAvailable();
28
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
187 }
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
188 };
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
189 clients++;
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
190 new Thread(sender).start();
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
191
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
192 }
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
193
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
194 public synchronized void requestThreadNotify() {
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
195 rThread.reStart();
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
196 }
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
197
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
198 private void sendRfbVersion(Writer writer) throws IOException, TransportException {
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
199 // os.write(versionMsg_3_8.getBytes());
54
0ae87c7e767c bug fix
one
parents: 52
diff changeset
200 writer.write(versionMsg_3_856.getBytes());
28
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
201 }
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
202
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
203 private int readVersionMsg(Reader reader, Writer writer) throws IOException, TransportException {
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
204
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
205 byte[] b = new byte[12];
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
206
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
207 reader.readBytes(b);
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
208
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
209 if ((b[0] != 'R') || (b[1] != 'F') || (b[2] != 'B') || (b[3] != ' ')
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
210 || (b[4] < '0') || (b[4] > '9') || (b[5] < '0') || (b[5] > '9')
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
211 || (b[6] < '0') || (b[6] > '9') || (b[7] != '.')
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
212 || (b[8] < '0') || (b[8] > '9') || (b[9] < '0') || (b[9] > '9')
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
213 || (b[10] < '0') || (b[10] > '9') || (b[11] != '\n')) {
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
214 throw new IOException("this is not an RFB server");
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
215 }
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
216
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
217 int rfbMajor = (b[4] - '0') * 100 + (b[5] - '0') * 10 + (b[6] - '0');
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
218 int rfbMinor = (b[8] - '0') * 100 + (b[9] - '0') * 10 + (b[10] - '0');
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
219
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
220 if (rfbMajor < 3) {
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
221 throw new IOException(
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
222 "RFB server does not support protocol version 3");
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
223 }
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
224
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
225 if (rfbMinor == 855) {
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
226 sendProxyFlag(writer);
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
227 if (proxyFlag)
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
228 sendPortNumber(writer);
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
229 }
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
230 return rfbMinor;
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
231 }
45
20326a4b9d88 create new change button for client.
one
parents: 43
diff changeset
232
20326a4b9d88 create new change button for client.
one
parents: 43
diff changeset
233 public void screenChangeRequest() throws IOException {
64
e73e2c30c9a6 before update for build CUI version.
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents: 63
diff changeset
234 Socket echoSocket = new Socket(proxyAddr, 10002);
45
20326a4b9d88 create new change button for client.
one
parents: 43
diff changeset
235 DataOutputStream os = new DataOutputStream(echoSocket.getOutputStream());
20326a4b9d88 create new change button for client.
one
parents: 43
diff changeset
236 os.writeBytes(echo.getMyAddress()+"\n");
59
433c79184c05 merge version2.7.2
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
237 //os.writeBytes(String.valueOf(echo.client.getFrameWidth())+"\n"); temp comment out for rebuild
433c79184c05 merge version2.7.2
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents: 55
diff changeset
238 //os.writeBytes(String.valueOf(echo.client.getFrameHeight())+"\n"); temp comment out for rebuild
45
20326a4b9d88 create new change button for client.
one
parents: 43
diff changeset
239 os.close();
77
cdf7bbe45885 remove some warnings
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 74
diff changeset
240 echoSocket.close();
45
20326a4b9d88 create new change button for client.
one
parents: 43
diff changeset
241 }
28
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
242
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
243 private void sendProxyFlag(Writer writer) throws TransportException {
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
244 if (proxyFlag)
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
245 writer.writeInt(1);
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
246 else
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
247 writer.writeInt(0);
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
248 }
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
249
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
250 private void sendPortNumber(Writer writer) throws TransportException {
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
251 byte[] b = new byte[4];
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
252 //b = castIntByte(getHost.getPort());
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
253 b = castIntByte(9999);
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
254 writer.write(b);
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
255 }
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
256
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
257 private byte[] castIntByte(int len) {
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
258 byte[] b = new byte[4];
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
259 b[0] = (byte) ((len >>> 24) & 0xFF);
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
260 b[1] = (byte) ((len >>> 16) & 0xFF);
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
261 b[2] = (byte) ((len >>> 8) & 0xFF);
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
262 b[3] = (byte) ((len >>> 0) & 0xFF);
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
263 return b;
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
264 }
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
265
45
20326a4b9d88 create new change button for client.
one
parents: 43
diff changeset
266
28
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
267 private void readSecType(Reader reader) throws TransportException {
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
268 byte[] b = new byte[1];
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
269 reader.read(b);
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
270 }
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
271
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
272 private void sendSecurityType(Writer os) throws TransportException {
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
273 // number-of-security-types
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
274 os.writeInt(1);
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
275 // security-types
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
276 // 1:None
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
277 os.writeInt(1);
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
278
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
279 /*
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
280 * os.write(4); os.write(30); os.write(31); os.write(32); os.write(35);
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
281 * os.flush();
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
282 */
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
283 }
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
284
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
285 private void sendSecResult(Writer os) throws TransportException {
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
286 byte[] b = castIntByte(0);
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
287 os.write(b);
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 private void readClientInit(Reader in) throws TransportException {
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
291 byte[] b = new byte[0];
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
292 in.readBytes(b);
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
293 }
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
294
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
295 private void sendInitData(Writer os) throws TransportException {
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
296 os.write(context.getInitData());
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
297 }
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
298
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
299 public void setProtocolContext(Protocol workingProtocol) {
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
300 context = workingProtocol;
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
301 }
29
57eb5575e6c4 MyRfbProto for client and proxy.
one
parents: 28
diff changeset
302
57eb5575e6c4 MyRfbProto for client and proxy.
one
parents: 28
diff changeset
303
57eb5575e6c4 MyRfbProto for client and proxy.
one
parents: 28
diff changeset
304 public void readSendData(int dataLen, Reader reader) throws TransportException {
57eb5575e6c4 MyRfbProto for client and proxy.
one
parents: 28
diff changeset
305
57eb5575e6c4 MyRfbProto for client and proxy.
one
parents: 28
diff changeset
306 }
31
872d9bcbfe56 Before changing the Viewer.
one
parents: 29
diff changeset
307
872d9bcbfe56 Before changing the Viewer.
one
parents: 29
diff changeset
308 public Socket accept() throws IOException {
872d9bcbfe56 Before changing the Viewer.
one
parents: 29
diff changeset
309 return null;
872d9bcbfe56 Before changing the Viewer.
one
parents: 29
diff changeset
310 }
872d9bcbfe56 Before changing the Viewer.
one
parents: 29
diff changeset
311
38
c2f0b6907448 add doc directory
one
parents: 36
diff changeset
312 public int selectPort(int port) {
c2f0b6907448 add doc directory
one
parents: 36
diff changeset
313 return port;
31
872d9bcbfe56 Before changing the Viewer.
one
parents: 29
diff changeset
314 }
33
9d3478d11d3b Add the processing of client
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents: 32
diff changeset
315
9d3478d11d3b Add the processing of client
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents: 32
diff changeset
316
9d3478d11d3b Add the processing of client
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents: 32
diff changeset
317 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
318 boolean incremental) throws TransportException {
9d3478d11d3b Add the processing of client
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents: 32
diff changeset
319 byte[] b = new byte[10];
9d3478d11d3b Add the processing of client
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents: 32
diff changeset
320
9d3478d11d3b Add the processing of client
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents: 32
diff changeset
321 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
322 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
323 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
324 b[3] = (byte) (x & 0xff);
9d3478d11d3b Add the processing of client
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents: 32
diff changeset
325 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
326 b[5] = (byte) (y & 0xff);
9d3478d11d3b Add the processing of client
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents: 32
diff changeset
327 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
328 b[7] = (byte) (w & 0xff);
9d3478d11d3b Add the processing of client
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents: 32
diff changeset
329 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
330 b[9] = (byte) (h & 0xff);
9d3478d11d3b Add the processing of client
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents: 32
diff changeset
331
9d3478d11d3b Add the processing of client
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents: 32
diff changeset
332 // os.write(b);
9d3478d11d3b Add the processing of client
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents: 32
diff changeset
333 }
9d3478d11d3b Add the processing of client
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents: 32
diff changeset
334
9d3478d11d3b Add the processing of client
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents: 32
diff changeset
335 public void notProxy() {
9d3478d11d3b Add the processing of client
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents: 32
diff changeset
336 proxyFlag = false;
9d3478d11d3b Add the processing of client
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents: 32
diff changeset
337 }
35
1b81deb0abb3 write a little part reconnection.
one
parents: 33
diff changeset
338
1b81deb0abb3 write a little part reconnection.
one
parents: 33
diff changeset
339 public void setEcho(EchoClient _echo) {
1b81deb0abb3 write a little part reconnection.
one
parents: 33
diff changeset
340 echo = _echo;
1b81deb0abb3 write a little part reconnection.
one
parents: 33
diff changeset
341 }
1b81deb0abb3 write a little part reconnection.
one
parents: 33
diff changeset
342
65
ffd7537cebfc cuiversion
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents: 64
diff changeset
343 public void setViewer(ViewerImpl v) {
36
b7d4d0349f99 write part of reconnection and remove warning.
one
parents: 35
diff changeset
344 echo.setViewer(v);
b7d4d0349f99 write part of reconnection and remove warning.
one
parents: 35
diff changeset
345 }
b7d4d0349f99 write part of reconnection and remove warning.
one
parents: 35
diff changeset
346
65
ffd7537cebfc cuiversion
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents: 64
diff changeset
347 public ViewerImpl getViewer() {
ffd7537cebfc cuiversion
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents: 64
diff changeset
348 return echo.getViewer();
ffd7537cebfc cuiversion
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents: 64
diff changeset
349 }
ffd7537cebfc cuiversion
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents: 64
diff changeset
350
35
1b81deb0abb3 write a little part reconnection.
one
parents: 33
diff changeset
351 public EchoClient getEcho() {
1b81deb0abb3 write a little part reconnection.
one
parents: 33
diff changeset
352 return echo;
1b81deb0abb3 write a little part reconnection.
one
parents: 33
diff changeset
353 }
43
6687aa9dd55e add flag for screen change in ReciverTask.java.
one
parents: 38
diff changeset
354
6687aa9dd55e add flag for screen change in ReciverTask.java.
one
parents: 38
diff changeset
355 public void setTerminationType(boolean setType) {
6687aa9dd55e add flag for screen change in ReciverTask.java.
one
parents: 38
diff changeset
356 /*nop*/
6687aa9dd55e add flag for screen change in ReciverTask.java.
one
parents: 38
diff changeset
357 }
6687aa9dd55e add flag for screen change in ReciverTask.java.
one
parents: 38
diff changeset
358
6687aa9dd55e add flag for screen change in ReciverTask.java.
one
parents: 38
diff changeset
359 public boolean getTerminationType() {
6687aa9dd55e add flag for screen change in ReciverTask.java.
one
parents: 38
diff changeset
360 /*nop*/
6687aa9dd55e add flag for screen change in ReciverTask.java.
one
parents: 38
diff changeset
361 return true;
6687aa9dd55e add flag for screen change in ReciverTask.java.
one
parents: 38
diff changeset
362 }
45
20326a4b9d88 create new change button for client.
one
parents: 43
diff changeset
363
20326a4b9d88 create new change button for client.
one
parents: 43
diff changeset
364 public void setProxyAddr(String proxyAddr) {
20326a4b9d88 create new change button for client.
one
parents: 43
diff changeset
365 this.proxyAddr = proxyAddr;
20326a4b9d88 create new change button for client.
one
parents: 43
diff changeset
366 }
52
986f16afb753 update before change host.
one
parents: 45
diff changeset
367
986f16afb753 update before change host.
one
parents: 45
diff changeset
368
986f16afb753 update before change host.
one
parents: 45
diff changeset
369 public void close() {
986f16afb753 update before change host.
one
parents: 45
diff changeset
370 //nothing
986f16afb753 update before change host.
one
parents: 45
diff changeset
371 }
45
20326a4b9d88 create new change button for client.
one
parents: 43
diff changeset
372
60
ac6f9e46566f proxy mode ok.
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents: 59
diff changeset
373 public int getAcceptPort() {
ac6f9e46566f proxy mode ok.
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents: 59
diff changeset
374 return 0;
ac6f9e46566f proxy mode ok.
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents: 59
diff changeset
375 }
ac6f9e46566f proxy mode ok.
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents: 59
diff changeset
376
61
d9cf08c6415c During implementation change screen.
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents: 60
diff changeset
377 public boolean getReadyReconnect() {
d9cf08c6415c During implementation change screen.
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents: 60
diff changeset
378 return readyReconnect;
d9cf08c6415c During implementation change screen.
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents: 60
diff changeset
379 }
d9cf08c6415c During implementation change screen.
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents: 60
diff changeset
380
d9cf08c6415c During implementation change screen.
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents: 60
diff changeset
381 public void setReadyReconnect(boolean ready) {
65
ffd7537cebfc cuiversion
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents: 64
diff changeset
382 }
ffd7537cebfc cuiversion
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents: 64
diff changeset
383
ffd7537cebfc cuiversion
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents: 64
diff changeset
384
ffd7537cebfc cuiversion
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents: 64
diff changeset
385 public boolean getCuiVersion() {
ffd7537cebfc cuiversion
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents: 64
diff changeset
386 return cuiVersion;
61
d9cf08c6415c During implementation change screen.
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents: 60
diff changeset
387 }
65
ffd7537cebfc cuiversion
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents: 64
diff changeset
388
ffd7537cebfc cuiversion
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents: 64
diff changeset
389 public void setCuiVersion(boolean flag) {
ffd7537cebfc cuiversion
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents: 64
diff changeset
390 cuiVersion = flag;
ffd7537cebfc cuiversion
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents: 64
diff changeset
391 }
66
84ad879891e9 dont move
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents: 65
diff changeset
392
84ad879891e9 dont move
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents: 65
diff changeset
393 public void readCheckDelay(Reader reader) throws TransportException {
84ad879891e9 dont move
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents: 65
diff changeset
394
84ad879891e9 dont move
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents: 65
diff changeset
395 }
84ad879891e9 dont move
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents: 65
diff changeset
396
84ad879891e9 dont move
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents: 65
diff changeset
397 public String getProxyAddr() {
84ad879891e9 dont move
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents: 65
diff changeset
398 return proxyAddr;
84ad879891e9 dont move
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents: 65
diff changeset
399 }
65
ffd7537cebfc cuiversion
Taninari YU <you@cr.ie.u-ryukyu.ac.jp>
parents: 64
diff changeset
400
28
18fad65bc447 Create MyRfbProto.java
one
parents:
diff changeset
401 }