Mercurial > hg > Applications > TightVNC_orginal
annotate src/main/java/jp/ac/u_ryukyu/treevnc/server/MyRfbProtoProxy.java @ 34:f70008073a03
add TreeViewer.java
author | one |
---|---|
date | Tue, 04 Sep 2012 19:02:04 +0900 |
parents | 9d3478d11d3b |
children | 1b81deb0abb3 |
rev | line source |
---|---|
12 | 1 package jp.ac.u_ryukyu.treevnc.server; |
11 | 2 |
34 | 3 //import static org.junit.Assert.*; |
4 //import org.junit.Test; | |
11 | 5 |
6 import java.io.IOException; | |
7 import java.net.BindException; | |
8 import java.net.ServerSocket; | |
9 import java.net.Socket; | |
10 import java.nio.ByteBuffer; | |
11 import java.util.Iterator; | |
12 import java.util.LinkedList; | |
15 | 13 import com.glavsoft.exceptions.TransportException; |
14 import com.glavsoft.rfb.encoding.EncodingType; | |
15 import com.glavsoft.transport.Reader; | |
16 | 16 import com.glavsoft.transport.Writer; |
11 | 17 import java.util.concurrent.ExecutorService; |
18 import java.util.zip.DataFormatException; | |
19 import java.util.zip.Deflater; | |
20 import java.util.zip.Inflater; | |
21 | |
32 | 22 import jp.ac.u_ryukyu.treevnc.MyRfbProto; |
12 | 23 |
28 | 24 public class MyRfbProtoProxy extends MyRfbProto { |
11 | 25 final static String versionMsg_3_855 = "RFB 003.855\n"; |
26 /** | |
27 * CheckMillis is one of new msgType for RFB 3.855. | |
28 */ | |
29 final static byte SpeedCheckMillis = 4; | |
15 | 30 final static int FramebufferUpdate = 0; |
31 final static int CheckDelay = 11; | |
16 | 32 final static int FramebufferUpdateRequest = 3; |
11 | 33 |
34 // Secyrity type of OS X | |
35 final static int SecTypeReqAccess = 32; | |
36 | |
37 // Supported authentication types | |
38 final static int AuthAccess = 32; | |
39 | |
40 private static final int INFLATE_BUFSIZE = 1024 * 100; | |
41 boolean printStatusFlag = false; | |
42 long startCheckTime; | |
19 | 43 |
11 | 44 |
45 private ServerSocket servSock; | |
46 protected int acceptPort; | |
47 // private byte initData[]; | |
48 private LinkedList<Socket> cliListTmp; | |
49 private LinkedList<Socket> cliList; | |
50 boolean createBimgFlag; | |
51 boolean proxyFlag = true; | |
52 ExecutorService executor; | |
53 | |
54 byte[] pngBytes; | |
55 | |
56 // private MulticastQueue<LinkedList<ByteBuffer>> multicastqueue = new | |
57 // MostRecentMultiCast<LinkedList<ByteBuffer>>(10); | |
32 | 58 // private MulticastQueue<LinkedList<ByteBuffer>> multicastqueue = new MulticastQueue<LinkedList<ByteBuffer>>(); |
11 | 59 private Inflater inflater = new Inflater(); |
60 private Deflater deflater = new Deflater(); | |
61 // private Thread requestThread; | |
62 private RequestScreenThread rThread; | |
63 private Thread requestThread; | |
64 | |
15 | 65 public MyRfbProtoProxy() { |
16 | 66 rThread = new RequestScreenThread(this); |
67 requestThread = new Thread(rThread); | |
11 | 68 } |
69 | |
19 | 70 public void setStream(Writer _writer) { |
23 | 71 // os = _writer; |
15 | 72 } |
11 | 73 |
74 void initServSock(int port) throws IOException { | |
75 servSock = new ServerSocket(port); | |
76 acceptPort = port; | |
77 } | |
78 | |
79 /* | |
80 * default port number is 5999. | |
81 */ | |
82 public void selectPort(int p) { | |
83 if (servSock != null) | |
84 return; | |
85 int port = p; | |
86 while (true) { | |
87 try { | |
88 initServSock(port); | |
89 break; | |
90 } catch (BindException e) { | |
91 port++; | |
92 continue; | |
93 } catch (IOException e) { | |
94 | |
95 } | |
96 } | |
97 System.out.println("accept port = " + port); | |
98 } | |
99 | |
100 int getAcceptPort() { | |
101 return acceptPort; | |
102 } | |
103 | |
104 void setSoTimeout(int num) throws IOException { | |
105 servSock.setSoTimeout(num); | |
106 } | |
107 | |
108 public Socket accept() throws IOException { | |
109 return servSock.accept(); | |
110 } | |
111 | |
112 void addSock(Socket sock) { | |
113 cliList.add(sock); | |
114 } | |
115 | |
116 void addSockTmp(Socket sock) { | |
117 System.out.println("connected " + sock.getInetAddress()); | |
118 cliListTmp.add(sock); | |
119 } | |
120 | |
121 synchronized void changeStatusFlag() { | |
122 printStatusFlag = true; | |
123 } | |
124 | |
125 void printMills() { | |
126 if (printStatusFlag) { | |
127 | |
128 changeStatusFlag(); | |
129 } else { | |
130 changeStatusFlag(); | |
131 } | |
132 } | |
133 | |
134 void requestThreadStart() { | |
135 requestThread.start(); | |
136 } | |
137 | |
138 public synchronized void requestThreadNotify() { | |
139 rThread.reStart(); | |
140 } | |
141 | |
142 /** | |
143 * gzip byte arrays | |
144 * | |
145 * @param deflater | |
146 * @param inputs | |
147 * byte data[] | |
148 * @param inputIndex | |
149 * @param outputs | |
150 * byte data[] | |
151 * @return byte length in last byte array | |
152 * @throws IOException | |
153 */ | |
154 public int zip(Deflater deflater, LinkedList<ByteBuffer> inputs, | |
155 int inputIndex, LinkedList<ByteBuffer> outputs) throws IOException { | |
156 int len = 0; | |
157 ByteBuffer c1 = ByteBuffer.allocate(INFLATE_BUFSIZE); | |
158 while (inputIndex < inputs.size()) { | |
159 ByteBuffer b1 = inputs.get(inputIndex++); | |
160 deflater.setInput(b1.array(), b1.position(), b1.remaining()); | |
161 /** | |
162 * If we finish() stream and reset() it, Deflater start new gzip | |
163 * stream, this makes continuous zlib reader unhappy. if we remove | |
164 * finish(), Deflater.deflate() never flushes its output. The | |
165 * original zlib deflate has flush flag. I'm pretty sure this a kind | |
166 * of bug of Java library. | |
167 */ | |
168 if (inputIndex == inputs.size()) | |
169 deflater.finish(); | |
170 int len1 = 0; | |
171 do { | |
172 len1 = deflater.deflate(c1.array(), c1.position(), | |
173 c1.remaining()); | |
174 if (len1 > 0) { | |
175 len += len1; | |
176 c1.position(c1.position() + len1); | |
177 if (c1.remaining() == 0) { | |
178 c1.flip(); | |
179 outputs.addLast(c1); | |
180 c1 = ByteBuffer.allocate(INFLATE_BUFSIZE); | |
181 } | |
182 } | |
183 } while (len1 > 0 || !deflater.needsInput()); // &&!deflater.finished()); | |
184 } | |
185 if (c1.position() != 0) { | |
186 c1.flip(); | |
187 outputs.addLast(c1); | |
188 } | |
189 deflater.reset(); | |
190 return len; | |
191 } | |
192 | |
193 /** | |
194 * gunzip byte arrays | |
195 * | |
196 * @param inflater | |
197 * @param inputs | |
198 * byte data[] | |
199 * @param outputs | |
200 * byte data[] | |
201 * @return number of total bytes | |
202 * @throws IOException | |
203 */ | |
204 public int unzip(Inflater inflater, LinkedList<ByteBuffer> inputs, | |
205 int inputIndex, LinkedList<ByteBuffer> outputs, int bufSize) | |
206 throws DataFormatException { | |
207 int len = 0; | |
208 ByteBuffer buf = ByteBuffer.allocate(bufSize); | |
209 while (inputIndex < inputs.size()) { | |
210 ByteBuffer input = inputs.get(inputIndex++); | |
211 inflater.setInput(input.array(), input.position(), input.limit()); | |
212 // if (inputIndex==inputs.size()) if inflater/deflater has symmetry, | |
213 // we need this | |
214 // inflater.end(); but this won't work | |
215 do { | |
216 int len0 = inflater.inflate(buf.array(), buf.position(), | |
217 buf.remaining()); | |
218 if (len0 > 0) { | |
219 buf.position(buf.position() + len0); | |
220 len += len0; | |
221 if (buf.remaining() == 0) { | |
222 buf.flip(); | |
223 outputs.addLast(buf); | |
224 buf = ByteBuffer.allocate(bufSize); | |
225 } | |
226 } | |
227 } while (!inflater.needsInput()); | |
228 } | |
229 if (buf.position() != 0) { | |
230 buf.flip(); | |
231 outputs.addLast(buf); | |
232 } | |
233 return len; | |
234 } | |
235 | |
236 float maxMag = 1; | |
237 | |
238 /** | |
239 * send data to clients | |
240 * | |
241 * @param dataLen | |
19 | 242 * @param is |
11 | 243 * @throws IOException |
244 * @throws DataFormatException | |
245 * | |
246 * Zlibed packet is compressed in context dependent way, that | |
247 * is, it have to send from the beginning. But this is | |
248 * impossible. So we have to compress it again for each clients. | |
249 * Separate deflater for each clients is necessary. | |
250 * | |
251 * Java's deflater does not support flush. This means to get the | |
252 * result, we have to finish the compression. Reseting start new | |
253 * compression, but it is not accepted well in zlib continuous | |
254 * reading. So we need new Encoding ZRLEE which reset decoder | |
255 * for each packet. ZRLEE can be invisible from user, but it | |
256 * have to be implemented in the clients. ZRLEE compression is | |
257 * not context dependent, so no recompression is necessary. | |
16 | 258 * @throws TransportException |
11 | 259 */ |
260 | |
26
73b13bc335c2
add ZRLEESender.java, NullRenderer.java and NullRepaintController.java
one
parents:
23
diff
changeset
|
261 public void readSendData(int dataLen, Reader is) throws TransportException { |
11 | 262 LinkedList<ByteBuffer> bufs = new LinkedList<ByteBuffer>(); |
263 ByteBuffer header = ByteBuffer.allocate(16); | |
17 | 264 is.readBytes(header.array(), 0, 16); |
11 | 265 header.limit(16); |
16 | 266 if (header.get(0) == FramebufferUpdate) { |
11 | 267 int encoding = header.getInt(12); |
15 | 268 if (encoding == EncodingType.ZRLE.getId() |
16 | 269 || encoding == EncodingType.ZLIB.getId()) { // ZRLEE is |
270 // already | |
271 // recompressed | |
11 | 272 ByteBuffer len = ByteBuffer.allocate(4); |
17 | 273 is.readBytes(len.array(), 0, 4); |
11 | 274 len.limit(4); |
275 ByteBuffer inputData = ByteBuffer.allocate(dataLen - 20); | |
276 | |
17 | 277 is.readBytes(inputData.array(), 0, inputData.capacity()); |
16 | 278 // System.out.println(dataLen); |
11 | 279 inputData.limit(dataLen - 20); |
280 | |
281 LinkedList<ByteBuffer> inputs = new LinkedList<ByteBuffer>(); | |
282 inputs.add(inputData); | |
283 | |
16 | 284 header.putInt(12, EncodingType.ZRLEE.getId()); // means |
285 // recompress | |
286 // every time | |
11 | 287 // using new Deflecter every time is incompatible with the |
288 // protocol, clients have to be modified. | |
289 Deflater nDeflater = deflater; // new Deflater(); | |
290 LinkedList<ByteBuffer> out = new LinkedList<ByteBuffer>(); | |
19 | 291 int len2 = 0; |
292 try { | |
293 unzip(inflater, inputs, 0, out, INFLATE_BUFSIZE); | |
294 len2 = zip(nDeflater, out, 0, bufs); | |
295 } catch (DataFormatException e) { | |
26
73b13bc335c2
add ZRLEESender.java, NullRenderer.java and NullRepaintController.java
one
parents:
23
diff
changeset
|
296 throw new TransportException(e); |
19 | 297 } catch (IOException e) { |
26
73b13bc335c2
add ZRLEESender.java, NullRenderer.java and NullRepaintController.java
one
parents:
23
diff
changeset
|
298 throw new TransportException(e); |
19 | 299 } |
300 | |
11 | 301 ByteBuffer blen = ByteBuffer.allocate(4); |
302 blen.putInt(len2); | |
303 blen.flip(); | |
304 bufs.addFirst(blen); | |
305 | |
306 bufs.addFirst(header); | |
16 | 307 // if(dataLen<=64000) |
308 multicastqueue.put(bufs); | |
11 | 309 // is.reset(); |
310 | |
311 /* | |
312 * System.out.println("ZRLE = "+dataLen); | |
313 * System.out.println("ZRLEE = "+(len2+20)); float mag = | |
314 * (float)dataLen / (float)(len2 + 20); | |
315 * System.out.println("ZRLE / ZRLEE = "+ mag); if(mag > maxMag) | |
316 * maxMag = mag; System.out.println("maxMag = "+maxMag); | |
317 */ | |
318 return; | |
319 } | |
320 bufs.add(header); | |
321 if (dataLen > 16) { | |
322 ByteBuffer b = ByteBuffer.allocate(dataLen - 16); | |
17 | 323 is.readBytes(b.array(), 0, dataLen - 16); |
11 | 324 b.limit(dataLen - 16); |
325 bufs.add(b); | |
326 } | |
327 multicastqueue.put(bufs); | |
328 // is.reset(); | |
329 return; | |
330 } | |
17 | 331 is.reset(); |
11 | 332 |
333 // It may be compressed. We can inflate here to avoid repeating clients | |
334 // decompressing here, | |
335 // but it may generate too many large data. It is better to do it in | |
336 // each client. | |
337 // But we have do inflation for all input data, so we have to do it | |
338 // here. | |
339 } | |
340 | |
341 public void dump32(LinkedList<ByteBuffer> bufs) { | |
342 int len = 0; | |
343 for (ByteBuffer b : bufs) | |
344 len += b.remaining(); | |
345 ByteBuffer top = bufs.getFirst(); | |
346 ByteBuffer end = bufs.getLast(); | |
347 System.err.println("length: " + len); | |
348 System.err.print("head 0: "); | |
349 for (int i = 0; i < 16 && i < top.remaining(); i++) { | |
350 System.err.print(" " + top.get(i)); | |
351 } | |
352 System.err.print("tail 0: "); | |
353 for (int i = 0; i < 16 && i < end.remaining(); i++) { | |
354 System.err.print(" " + end.get(i)); | |
355 } | |
356 System.err.println(); | |
357 } | |
358 | |
34 | 359 /* |
11 | 360 @Test |
361 public void test1() { | |
362 try { | |
363 LinkedList<ByteBuffer> in = new LinkedList<ByteBuffer>(); | |
364 LinkedList<ByteBuffer> out = new LinkedList<ByteBuffer>(); | |
365 LinkedList<ByteBuffer> out2 = new LinkedList<ByteBuffer>(); | |
366 // if (false) { | |
367 // for(int i=0;i<10;i++) { | |
368 // in.add(ByteBuffer.wrap("test1".getBytes())); | |
369 // in.add(ByteBuffer.wrap("test2".getBytes())); | |
370 // in.add(ByteBuffer.wrap("test3".getBytes())); | |
371 // in.add(ByteBuffer.wrap("test44".getBytes())); | |
372 // } | |
373 // } else | |
374 { | |
375 String t = ""; | |
376 for (int i = 0; i < 10; i++) { | |
377 t += "test1"; | |
378 t += "test2"; | |
379 t += "test3"; | |
380 t += "test44"; | |
381 } | |
382 in.add(ByteBuffer.wrap(t.getBytes())); | |
383 } | |
384 | |
385 LinkedList<ByteBuffer> in1 = clone(in); | |
386 | |
387 Deflater deflater = new Deflater(); | |
388 zip(deflater, in, 0, out); | |
389 // LinkedList<ByteBuffer> out3 = clone(out); zipped result is depend | |
390 // on deflator's state | |
391 unzip(inflater, out, 0, out2, INFLATE_BUFSIZE); | |
392 // inflater.reset(); | |
393 equalByteBuffers(in1, out2); | |
394 LinkedList<ByteBuffer> out4 = new LinkedList<ByteBuffer>(); | |
395 deflater = new Deflater(); | |
396 zip(deflater, out2, 0, out4); | |
397 LinkedList<ByteBuffer> out5 = new LinkedList<ByteBuffer>(); | |
398 unzip(inflater, out4, 0, out5, INFLATE_BUFSIZE); | |
399 int len = equalByteBuffers(in1, out5); | |
400 | |
401 System.out.println("Test Ok. " + len); | |
402 } catch (Exception e) { | |
403 assertEquals(0, 1); | |
404 } | |
405 } | |
34 | 406 */ |
407 | |
11 | 408 private LinkedList<ByteBuffer> clone(LinkedList<ByteBuffer> in) { |
409 LinkedList<ByteBuffer> copy = new LinkedList<ByteBuffer>(); | |
410 for (ByteBuffer b : in) { | |
411 ByteBuffer c = b.duplicate(); | |
412 copy.add(c); | |
413 } | |
414 return copy; | |
415 } | |
34 | 416 |
417 /* | |
11 | 418 public int equalByteBuffers(LinkedList<ByteBuffer> in, |
419 LinkedList<ByteBuffer> out2) { | |
420 int len = 0; | |
421 Iterable<Byte> i = byteBufferIterator(in); | |
422 Iterator<Byte> o = byteBufferIterator(out2).iterator(); | |
423 | |
424 for (int b : i) { | |
425 len++; | |
426 if (o.hasNext()) { | |
427 int c = o.next(); | |
428 assertEquals(b, c); | |
429 } else | |
430 assertEquals(0, 1); | |
431 } | |
432 if (o.hasNext()) | |
433 assertEquals(0, 1); | |
434 // System.out.println(); | |
435 return len; | |
436 } | |
34 | 437 */ |
11 | 438 |
439 private Iterable<Byte> byteBufferIterator(final LinkedList<ByteBuffer> in) { | |
440 return new Iterable<Byte>() { | |
441 public Iterator<Byte> iterator() { | |
442 return new Iterator<Byte>() { | |
443 int bytes = 0; | |
444 int buffers = 0; | |
445 | |
446 public boolean hasNext() { | |
447 for (;;) { | |
448 if (buffers >= in.size()) | |
449 return false; | |
450 ByteBuffer b = in.get(buffers); | |
451 if (!(bytes < b.remaining())) { | |
452 buffers++; | |
453 bytes = 0; | |
454 } else | |
455 return true; | |
456 } | |
457 } | |
458 | |
459 public Byte next() { | |
460 ByteBuffer bf = in.get(buffers); | |
461 byte b = bf.get(bytes++); | |
462 if (bf.remaining() <= bytes) { | |
463 buffers++; | |
464 bytes = 0; | |
465 } | |
466 // System.out.print(b); | |
467 return b; | |
468 } | |
469 | |
470 public void remove() { | |
471 } | |
472 }; | |
473 } | |
474 }; | |
475 } | |
16 | 476 |
17 | 477 void sendRfbVersion(Writer writer) throws IOException, TransportException { |
15 | 478 // os.write(versionMsg_3_8.getBytes()); |
17 | 479 writer.write(versionMsg_3_855.getBytes()); |
15 | 480 } |
16 | 481 |
17 | 482 int readVersionMsg(Reader reader, Writer writer) throws IOException, TransportException { |
11 | 483 |
15 | 484 byte[] b = new byte[12]; |
485 | |
17 | 486 reader.readBytes(b); |
15 | 487 |
488 if ((b[0] != 'R') || (b[1] != 'F') || (b[2] != 'B') || (b[3] != ' ') | |
489 || (b[4] < '0') || (b[4] > '9') || (b[5] < '0') || (b[5] > '9') | |
490 || (b[6] < '0') || (b[6] > '9') || (b[7] != '.') | |
491 || (b[8] < '0') || (b[8] > '9') || (b[9] < '0') || (b[9] > '9') | |
492 || (b[10] < '0') || (b[10] > '9') || (b[11] != '\n')) { | |
493 throw new IOException("this is not an RFB server"); | |
494 } | |
495 | |
496 int rfbMajor = (b[4] - '0') * 100 + (b[5] - '0') * 10 + (b[6] - '0'); | |
497 int rfbMinor = (b[8] - '0') * 100 + (b[9] - '0') * 10 + (b[10] - '0'); | |
498 | |
499 if (rfbMajor < 3) { | |
500 throw new IOException( | |
501 "RFB server does not support protocol version 3"); | |
502 } | |
503 | |
504 if (rfbMinor == 855) { | |
17 | 505 sendProxyFlag(writer); |
15 | 506 if (proxyFlag) |
17 | 507 sendPortNumber(writer); |
15 | 508 } |
509 return rfbMinor; | |
510 } | |
16 | 511 |
17 | 512 void sendProxyFlag(Writer writer) throws TransportException { |
15 | 513 if (proxyFlag) |
17 | 514 writer.writeInt(1); |
15 | 515 else |
17 | 516 writer.writeInt(0); |
15 | 517 } |
16 | 518 |
17 | 519 void sendPortNumber(Writer writer) throws TransportException { |
15 | 520 byte[] b = new byte[4]; |
17 | 521 //b = castIntByte(getHost.getPort()); |
522 b = castIntByte(9999); | |
523 writer.write(b); | |
15 | 524 } |
525 | |
17 | 526 void sendSecurityType(Writer os) throws TransportException { |
15 | 527 // number-of-security-types |
17 | 528 os.writeInt(1); |
15 | 529 // security-types |
530 // 1:None | |
17 | 531 os.writeInt(1); |
15 | 532 |
533 /* | |
534 * os.write(4); os.write(30); os.write(31); os.write(32); os.write(35); | |
535 * os.flush(); | |
536 */ | |
537 } | |
538 | |
17 | 539 void readSecType(Reader reader) throws TransportException { |
15 | 540 byte[] b = new byte[1]; |
17 | 541 reader.read(b); |
15 | 542 } |
543 | |
17 | 544 void readSecType(Reader is, Writer os) throws TransportException { |
15 | 545 byte[] b = new byte[1]; |
17 | 546 is.readBytes(b); |
15 | 547 |
548 int count = 260; | |
549 int[] data = { 0, 2, 0, -128, -1, -1, -1, -1, -1, -1, -1, -1, -55, 15, | |
550 -38, -94, 33, 104, -62, 52, -60, -58, 98, -117, -128, -36, 28, | |
551 -47, 41, 2, 78, 8, -118, 103, -52, 116, 2, 11, -66, -90, 59, | |
552 19, -101, 34, 81, 74, 8, 121, -114, 52, 4, -35, -17, -107, 25, | |
553 -77, -51, 58, 67, 27, 48, 43, 10, 109, -14, 95, 20, 55, 79, | |
554 -31, 53, 109, 109, 81, -62, 69, -28, -123, -75, 118, 98, 94, | |
555 126, -58, -12, 76, 66, -23, -90, 55, -19, 107, 11, -1, 92, -74, | |
556 -12, 6, -73, -19, -18, 56, 107, -5, 90, -119, -97, -91, -82, | |
557 -97, 36, 17, 124, 75, 31, -26, 73, 40, 102, 81, -20, -26, 83, | |
558 -127, -1, -1, -1, -1, -1, -1, -1, -1, -111, 73, -29, 30, 57, | |
559 -67, -75, -77, -49, -50, -99, -76, -80, -80, 14, 65, 57, -105, | |
560 -103, -54, -102, 3, 39, -44, 39, 35, 118, -84, -64, 37, -117, | |
561 -21, 89, -31, -68, 70, 5, 122, -92, -119, 9, 121, 63, -112, | |
562 -60, 122, -46, -69, -36, 92, -103, -92, 74, 92, -73, 87, 120, | |
563 -8, 116, -47, 111, 20, -41, 110, 122, -3, -94, 14, 42, -51, | |
564 -59, 48, -54, -125, 117, 60, 77, -52, -31, 98, 32, -2, -102, | |
565 -15, -29, 58, -14, -106, -116, -32, -86, 50, -32, -16, -3, | |
566 -123, 87, 88, -118, 10, 120, -107, -37, 125, -110, 59, 87, 93, | |
567 -24, 124, -99, 18, 78, -13, -49, -34, -24, -27, 1, 114, -67, | |
568 -98, -56, -3, 85, -67, -126, 77 }; | |
569 for (int i = 0; i < count; i++) { | |
570 os.write((byte) data[i]); | |
571 os.flush(); | |
572 } | |
573 | |
574 byte[] c = new byte[256]; | |
17 | 575 is.readBytes(c); |
15 | 576 |
577 System.out.println(new String(c)); | |
578 | |
579 } | |
580 | |
17 | 581 void sendSecResult(Writer os) throws TransportException { |
15 | 582 byte[] b = castIntByte(0); |
583 os.write(b); | |
584 } | |
16 | 585 |
15 | 586 byte[] castIntByte(int len) { |
587 byte[] b = new byte[4]; | |
588 b[0] = (byte) ((len >>> 24) & 0xFF); | |
589 b[1] = (byte) ((len >>> 16) & 0xFF); | |
590 b[2] = (byte) ((len >>> 8) & 0xFF); | |
591 b[3] = (byte) ((len >>> 0) & 0xFF); | |
592 return b; | |
593 } | |
594 | |
17 | 595 void readClientInit(Reader in) throws TransportException { |
15 | 596 byte[] b = new byte[0]; |
17 | 597 in.readBytes(b); |
15 | 598 } |
18 | 599 |
11 | 600 } |