+
+ return chunk;
+ }
+
+ private static byte[] receive_tcpaux( String host, int port, String cid)
+ {
+ Socket jpipsocket;
+ DataOutputStream os;
+ DataInputStream is;
+ byte []auxheader;
+ byte []chunkbody = null;
+ byte []stream = null;
+ int chunkbodylen, streamlen, headlen = 8;
+ ByteArrayOutputStream tmpstream;
+
+ try{
+ jpipsocket = new Socket( host, port);
+ os = new DataOutputStream( jpipsocket.getOutputStream());
+ is = new DataInputStream( jpipsocket.getInputStream());
+ auxheader = new byte[headlen];
+ tmpstream = new ByteArrayOutputStream();
+
+ os.writeBytes( cid + "\r\n");
+
+ do{
+ read_stream( is, auxheader, headlen);
+
+ chunkbodylen = ((auxheader[0]&0xff)<<8 | (auxheader[1]&0xff)) - headlen;
+
+ chunkbody = new byte [ chunkbodylen];
+ read_stream( is, chunkbody, chunkbodylen);
+ tmpstream.write( chunkbody, 0, chunkbodylen);
+
+ os.write( auxheader, 0, headlen);
+ }while( !(chunkbody[chunkbodylen-3]==0x00 && ( chunkbody[chunkbodylen-2]==0x01 || chunkbody[chunkbodylen-2]== 0x02)));
+
+ streamlen = tmpstream.size();
+ stream = tmpstream.toByteArray();
+
+ System.err.println("jpiplen: " + streamlen);
+ System.err.println(" succeeded");
+
+ chunkbody = null;
+ tmpstream = null;
+
+ os.close();
+ is.close();
+
+ jpipsocket.close();