annotate src/main/java/jp/ac/u_ryukyu/treevnc/MyRfbProto.java @ 52:986f16afb753

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