Last week, we had the author of TDD for a Shopping Website LiveProject. Friday at 11am Ranch time, Steven Solomon will be hosting a live TDD session just for us. See for the agenda and registration link
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Need help regarding my J2ME client server application

 
Ranch Hand
Posts: 276
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

I am making one client server application in J2ME.
The client is a midlet from which i want to send all the image files one by one from the phone file system to the server where there is a servlet.

What i am doing is dividing the total file size for one file.

Looping upto that much counter i am opening a inputstream, reading the data into that input stream ,opening an output stream ,writing the read data to that output stream.

This process i am doing upto the no of parts the file gets divided as mentioned above & each time i am reding like this:
t = 0;
byte[] buf = byte[2000];
for(i =0;i<counter;i++)
{
is.read(buf,t,2000);
os.write(buf);
t+=200;
}

where is & os are input stream & output stream.t is the offset for reading.

The problem i am facing is for the first i =1 the bytes gets read & write & servlet is sending the response code 200 .
But as soon as i=2 the program throws exception from reading line & on the server side Socket exception is thrown : Read timed out.

So anybody could help me designing this abt how to achiev this in the easiest way or provide me a sample code for the client side & servlet if anybody has done this.

Regards ,
Jignesh
 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,
In the following loop
>for(i =0;i<counter;i++)
>{
>is.read(buf,t,2000);
for first time its read successfully till 2000 bytes and written to server. However when second time the read API that is being used expects the buffer size to which data is to be copied to be of atleast (t+2000), which is true when i =0 but as soon as i > 0 then buffer size is less than that expected. So its throwing exception (IndexOutOfBoundsException I think so). So instead of using this version of read try using read(buf) instead. Also if you know the size of file that is being read then buffer size can be fixed using byte[] buf = new byte[is.available()]; Hope this helps
Vijay
 
I AM MIGHTY! Especially when I hold this tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic