Mercurial > hg > Members > riono > TreeVNC_ja_comment
comparison src/main/java/jp/ac/u_ryukyu/treevnc/MyRfbProto.java @ 124:214d4f206431
add TreeVNC command number.
author | oc |
---|---|
date | Thu, 05 Jun 2014 17:01:34 +0900 |
parents | 233e94a7b5ed |
children | 32c6563492f3 |
comparison
equal
deleted
inserted
replaced
123:233e94a7b5ed | 124:214d4f206431 |
---|---|
1 package jp.ac.u_ryukyu.treevnc; | 1 package jp.ac.u_ryukyu.treevnc; |
2 | 2 |
3 import java.io.IOException; | 3 import java.io.IOException; |
4 | |
4 import java.io.OutputStream; | 5 import java.io.OutputStream; |
5 import java.net.BindException; | 6 import java.net.BindException; |
6 import java.net.ServerSocket; | 7 import java.net.ServerSocket; |
7 import java.net.Socket; | 8 import java.net.Socket; |
8 import java.nio.ByteBuffer; | 9 import java.nio.ByteBuffer; |
23 import com.glavsoft.rfb.protocol.Protocol; | 24 import com.glavsoft.rfb.protocol.Protocol; |
24 import com.glavsoft.rfb.protocol.ProtocolContext; | 25 import com.glavsoft.rfb.protocol.ProtocolContext; |
25 import com.glavsoft.transport.Reader; | 26 import com.glavsoft.transport.Reader; |
26 import com.glavsoft.transport.Writer; | 27 import com.glavsoft.transport.Writer; |
27 import com.glavsoft.viewer.ViewerImpl; | 28 import com.glavsoft.viewer.ViewerImpl; |
29 | |
28 | 30 |
29 public abstract class MyRfbProto { | 31 public abstract class MyRfbProto { |
30 final static int FramebufferUpdateRequest = 3; | 32 final static int FramebufferUpdateRequest = 3; |
31 final static int CheckDelay = 11; | 33 final static int CheckDelay = 11; |
32 protected final static int FramebufferUpdate = 0; | 34 protected final static int FramebufferUpdate = 0; |
59 this.viewer = viewer; | 61 this.viewer = viewer; |
60 } | 62 } |
61 | 63 |
62 abstract public boolean isRoot() ; | 64 abstract public boolean isRoot() ; |
63 | 65 |
66 public boolean initialConnection(final Writer os, final Reader is) | |
67 throws IOException, TransportException { | |
68 /** | |
69 * initial connection of RFB protocol | |
70 */ | |
71 sendRfbVersion(os); | |
72 byte[] b; | |
73 if ((b = readVersionMsg(is, os))!=null) { | |
74 treeVncCommand(b,is,os); | |
75 return true; | |
76 } | |
77 sendSecurityType(os); | |
78 readSecType(is); | |
79 sendSecResult(os); | |
80 readClientInit(is); | |
81 sendInitData(os); | |
82 return false; | |
83 } | |
84 | |
85 private void treeVncCommand(byte[] b, Reader is, Writer os) { | |
86 ByteBuffer buf = ByteBuffer.wrap(b); | |
87 int command = buf.get(); | |
88 | |
89 switch (command) { | |
90 case ProtocolContext.FIND_ROOT : | |
91 case ProtocolContext.WHERE_TO_CONNECT : | |
92 case ProtocolContext.LOST_PARENT : | |
93 System.out.println("get treeVNC command" + command); | |
94 } | |
95 } | |
96 | |
64 public void newClient(AcceptThread acceptThread, final Socket newCli, | 97 public void newClient(AcceptThread acceptThread, final Socket newCli, |
65 final Writer os, final Reader is) throws IOException { | 98 final Writer os, final Reader is) throws IOException, TransportException { |
66 // createBimgFlag = true; | 99 |
67 // rfb.addSockTmp(newCli); | 100 |
68 // addSock(newCli); | 101 if (initialConnection(os, is)) return; // |
102 | |
69 final int myId = clients; | 103 final int myId = clients; |
70 final MulticastQueue.Client<LinkedList<ByteBuffer>> c = multicastqueue.newClient(); | 104 final MulticastQueue.Client<LinkedList<ByteBuffer>> c = multicastqueue.newClient(); |
71 final AtomicInteger writerRunning = new AtomicInteger(); | 105 final AtomicInteger writerRunning = new AtomicInteger(); |
72 writerRunning.set(1); | 106 writerRunning.set(1); |
73 /** | 107 /** |
175 public void run() { | 209 public void run() { |
176 writerRunning.set(1); | 210 writerRunning.set(1); |
177 try { | 211 try { |
178 requestThreadNotify(); | 212 requestThreadNotify(); |
179 | 213 |
180 /** | 214 |
181 * initial connection of RFB protocol | 215 |
182 */ | 216 |
183 sendRfbVersion(os); | |
184 // readVersionMsg(is); | |
185 readVersionMsg(is, os); | |
186 sendSecurityType(os); | |
187 readSecType(is); | |
188 sendSecResult(os); | |
189 readClientInit(is); | |
190 sendInitData(os); | |
191 // after this, we discard upward packet. | 217 // after this, we discard upward packet. |
192 new Thread(reader, "discard-upward-comm").start(); | 218 new Thread(reader, "discard-upward-comm").start(); |
193 // writeFramebufferUpdateRequest(0,0, framebufferWidth, | 219 // writeFramebufferUpdateRequest(0,0, framebufferWidth, |
194 // framebufferHeight, false ); | 220 // framebufferHeight, false ); |
195 for (;;) { | 221 for (;;) { |
253 | 279 |
254 private void sendRfbVersion(Writer writer) throws IOException, TransportException { | 280 private void sendRfbVersion(Writer writer) throws IOException, TransportException { |
255 writer.write(versionMsg_3_856.getBytes()); | 281 writer.write(versionMsg_3_856.getBytes()); |
256 } | 282 } |
257 | 283 |
258 private int readVersionMsg(Reader reader, Writer writer) throws IOException, TransportException { | 284 private byte[] readVersionMsg(Reader reader, Writer writer) throws IOException, TransportException { |
259 | 285 |
260 byte[] b = new byte[12]; | 286 byte[] b = new byte[12]; |
261 | 287 |
262 reader.readBytes(b); | 288 reader.readBytes(b); |
263 | 289 |
290 if (b[0]>=220) return b; // TreeVNC extention command. | |
264 if ((b[0] != 'R') || (b[1] != 'F') || (b[2] != 'B') || (b[3] != ' ') | 291 if ((b[0] != 'R') || (b[1] != 'F') || (b[2] != 'B') || (b[3] != ' ') |
265 || (b[4] < '0') || (b[4] > '9') || (b[5] < '0') || (b[5] > '9') | 292 || (b[4] < '0') || (b[4] > '9') || (b[5] < '0') || (b[5] > '9') |
266 || (b[6] < '0') || (b[6] > '9') || (b[7] != '.') | 293 || (b[6] < '0') || (b[6] > '9') || (b[7] != '.') |
267 || (b[8] < '0') || (b[8] > '9') || (b[9] < '0') || (b[9] > '9') | 294 || (b[8] < '0') || (b[8] > '9') || (b[9] < '0') || (b[9] > '9') |
268 || (b[10] < '0') || (b[10] > '9') || (b[11] != '\n')) { | 295 || (b[10] < '0') || (b[10] > '9') || (b[11] != '\n')) { |
280 if (rfbMinor == 855) { | 307 if (rfbMinor == 855) { |
281 sendProxyFlag(writer); | 308 sendProxyFlag(writer); |
282 if (proxyFlag) | 309 if (proxyFlag) |
283 sendPortNumber(writer); | 310 sendPortNumber(writer); |
284 } | 311 } |
285 return rfbMinor; | 312 return null; |
286 } | 313 } |
287 | 314 |
288 | 315 |
289 private void sendProxyFlag(Writer writer) throws TransportException { | 316 private void sendProxyFlag(Writer writer) throws TransportException { |
290 if (proxyFlag) | 317 if (proxyFlag) |
675 // but it may generate too many large data. It is better to do it in | 702 // but it may generate too many large data. It is better to do it in |
676 // each client. | 703 // each client. |
677 // But we have do inflation for all input data, so we have to do it | 704 // But we have do inflation for all input data, so we have to do it |
678 // here. | 705 // here. |
679 } | 706 } |
707 | |
708 | |
680 } | 709 } |