annotate src/main/java/jp/ac/u_ryukyu/treevnc/MyRfbProto.java @ 59:433c79184c05

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