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