Re: Problem with large messages over Jxta Socket

Mohamed Abdelaziz <[email protected]> Thu, 25 Aug 2005 14:19:37 -0700
Newsgroups gmane.comp.java.jxta.user,gmane.comp.java.jxta.devel
Message-ID <[email protected]>
By default JxtaSocket sets the buffer size on outgoing to 16K (which 
explains your observation on the initial read()), therefore it would 
take two messages to complete the transfer.  The reason may simply be 
forgetting to flush()  at the end xmision. Otherwise it is likely that 
at the time that ready() was invoked, the remainder of the 20K data 
stream is being received/processed and it would have been accounted for 
in deducing the ready state.

Out of curiosity, any specific reason for the additional BufferedReader?

keep in mind that data is already buffered within the socket/reliability 
layer, and the application buffer would be redundant.


Mohamed


-- 
http://blogs.sun.com/roller/page/hamada
http://weblogs.java.net/blog/hamada

[email protected] wrote:

>Hello Jxta Community --
>
>I have a JxtaSocket based program that has been running without (too
>many) problems for several months. Recently the size of the messages it
>is being asked to process has increased dramatically. 
>
>It appears that the problem is caused by the fact that one call to the
>read method on my BufferedReader doesn't read the entire message.
>
>I have been experimenting with 20,000 byte messages. Sometimes I get the
>whole message when I do the read. Sometimes all I get is about 16,000
>bytes. 
>
>If I make a call to the BufferedReader 'ready' method -- right after I
>do the read - it says there are no more bytes to read. If I go do a
>little processing and check back with 'ready' (in a very short period of
>time) -- it says that there is more data. This is (I believe) the
>remainder of the message.
>
>So - is there some buffered reader processing pattern that I am not
>using? Do I need to increase a buffer some where? I really dont want to
>-- but do I need to sleep a little every time I read and go back and
>check for more data?
>
>Any pointers on where I am going wrong -- most appreciated.
>
>Just for fun -- here is an excerpt from the code.... Any helpful
>comments on the code appreciated, also.
>
>Thanks
>Dan Galewsky
>
>=========================
>        InputStream in = socket.getInputStream();
>        BufferedReader br = new BufferedReader(new
>InputStreamReader(in),40000); //40000 buffer size experiment - no help
>
>        // NOTE !!! This determines how big of a message we can receive
>//(bogus?)
>
>        char[] line = new char[131072]; //128k
>
>        // Read our message from the socket
>
>        int cnt = br.read(line);
>
>        if (br.ready()) 
>        	System.out.println("***** THERE IS MORE ******");
>        else
>        	System.out.println("**No more at the current time");
>                
>        if (cnt <= 0) {
>          logger.info("\n**ServerThread - got a null message - ignoring
>" + cnt);
>
>          br.close();
>          in.close();
>          socket.close();
>          return;
>        }
>
>        // Turn byte array into a string
>
>        inLine = new String(line, 0, cnt);
>
>        // Decode the message and do what it says
>        try {
>        	cp.process(inArray);
>        }catch (Exception e) {
>        // We get this exception if the message is not complete. 
>        // Every time I get this exception -- there are more bytes ready
>to read.
>        	System.out.println("#### Exception end " + br.ready());
>        }
>
>        // Experimental check/read 
>        a
>        System.out.println("reading again");
>        if (br.ready()) {
>        	cnt = br.read(line);
>        	logger.info("**ServerThread -- ** MORE ** read message -- size:
>" + cnt);
>        } else {
>        	System.out.println("Nothing to read...");
>        }
>        
>        in.close();
>        br.close();
>        socket.close();
>  
>

-- 
http://blogs.sun.com/roller/page/hamada
http://weblogs.java.net/blog/hamada