my dog learned polymorphism
The moose likes Java Micro Edition and the fly likes Need help regarding my J2ME client server application Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Mobile » Java Micro Edition
Bookmark "Need help regarding my J2ME client server application" Watch "Need help regarding my J2ME client server application" New topic

Need help regarding my J2ME client server application

Jignesh Gohel
Ranch Hand

Joined: Dec 28, 2004
Posts: 276

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++)

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 ,


The Art Of Life Is To Know When To Be Useless And When To Be Useful - CHUANG TZU
Vijay Dogra

Joined: Sep 16, 2004
Posts: 22
In the following loop
>for(i =0;i<counter;i++)
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
I agree. Here's the link:
subject: Need help regarding my J2ME client server application
It's not a secret anymore!