×

Discussion Board

Results 1 to 6 of 6
  1. #1
    Registered User
    Join Date
    Mar 2006
    Posts
    42

    Downlaoding image from a server using socket

    Hello Everybody
    I am trying to make an application (security software)..in this software I want to get image from a remote server..The code which I have written for this application is very simple...using sockets API....
    *********************************************************
    public void run()
    {
    try{
    image_size = 10063; //dummy value in bytes
    byte pBuff[] = new byte[image_size];
    byte temp;
    int i=0;
    while (i<image_size) {
    temp = (byte) is.read(); //"is" is an InputStream Object
    pBuff[i] = temp;
    i++;
    }
    } catch(IOException ioe){

    }
    }
    *********************************************************

    I have checked the above code on JBuilder2005 Simulator...but the problem I am facing that it takes a long to download a file even the file size is only 10kb and I am not checking it in real enviornment...as server is also present on the same computer on which this software is running...and i thinmk that it will be more slow in real enviornment....If anybody have any knowledge about that...that how a WAP browser download an Image...or any best technique to download the image....or the above technique is best.....please help me as I am facing very much difficulties...
    Thanks
    Bye...
    Muhammad Ummar Iqbal Bhutta
    Student (Computer Engineering)
    University of Engineering and Technology Lahore

  2. #2
    Super Contributor
    Join Date
    Mar 2003
    Location
    Israel
    Posts
    2,280

    Re: Downlaoding image from a server using socket

    Try using InputStream.read(byte[] b, int off, int len) to read more than one byte at a time, or maybe even DataInputStream.readFully().

    shmoove

  3. #3
    Registered User
    Join Date
    Mar 2006
    Posts
    42

    Re: Downlaoding image from a server using socket

    Thanks for suggestion I will try it and will let u know..

  4. #4
    Registered User
    Join Date
    Mar 2006
    Posts
    42

    Exclamation Re: Downlaoding image from a server using socket

    Hello At last I have downloaded the Image to my mobile device and have successfully displayed it on the screen of my mobile..but problem is now that..If I want to save that Image to my Mobile What should I do?? I have recieved the bits of Image from a remote server and have stored it in a buffer
    /*****************************************/
    byte pBuff[] = new byte[image_size];
    //where image_size is the size of image

    and then After recieving the image from server I have used

    Image test_image = Image.createImage(pBuff, 0, pBuff.length);

    and after creating the Image I have displayed it on the form using

    this.append(test_image);

    but now problem is that Now i want to save this image on permanant storage of Mobile...I am using Nokis 6680....So please help me as soon as possible...I am looking forward for the help from Nokia Experts...
    Thanks...
    Ummar

  5. #5
    Super Contributor
    Join Date
    Dec 2005
    Location
    Europe/Poland/Warsaw
    Posts
    1,697

    Re: Downlaoding image from a server using socket

    hi Umar,

    your raw bytes need to be saved locally, let say into default system "Photos" (Images) folder,
    see that post by Gopal:
    Balagopal NKnair's Forum Nokia Blog: FileConnection - Introduction to beginners

    hth,
    regards,
    Peter

  6. #6
    Registered User
    Join Date
    Mar 2006
    Posts
    42

    Re: Downlaoding image from a server using socket

    Thanks to all for helping me specially shmoove and peter. But I have another question...the problem is this that in My Project when I download the Image data Bytes 1 by 1 as the previous method. It works well Its code is as follows
    *********************************************************
    public void run()
    {
    try{
    image_size = 10063; //dummy value in bytes
    byte pBuff[] = new byte[image_size];
    byte temp;
    int i=0;
    while (i<image_size) {
    temp = (byte) is.read(); //"is" is an InputStream Object
    pBuff[i] = temp;
    i++;
    }
    } catch(IOException ioe){

    }
    }
    *********************************************************


    but this process so slow even for a 10kb Picture it take a long to download....As shmoove suggested me to change the byte by byte code to a packet of bytes I have tried it...as code given

    /********************************************************/
    byte pBuff[] = new byte[image_size+32]; //adding 32 bytes just for precaution
    byte buffer[] = new byte[32]; //Buffer for reading file

    byte temp2;
    i = 0;
    int count;
    while (i < image_size) {
    count = is.read(buffer);

    for (int j = 0; j < count; j++)
    pBuff[i + j] = buffer[j];

    progress_bar.setValue(i); //setting the progress bar state

    i = i + count;
    }
    intruder_image = Image.createImage(pBuff, 0, pBuff.length);
    /********************************************************/

    The above code really increases the speed...but it is not working properly...as when the Progress Bar reaches to 100% it just stops and don't come out of the loop..and the line

    intruder_image = Image.createImage(pBuff, 0, pBuff.length);

    is not executing....The above code is working 100% right in JBuilder Simulator..but When I run in real enviornment (Nokia 6680) it shows this problem....Please help me.....as I am unable to find any error...or any best suggestion about how to download Image data more fast from Network...I am waiting for a helpful answer....Thanks...
    Muhammad Ummar Iqbal Bhutta
    Student (Computer Engineering)
    University of Engineering and Technology Lahore

Similar Threads

  1. Problem socket server in my nokia phone ....
    By kajinka13 in forum Symbian
    Replies: 0
    Last Post: 2006-01-06, 17:59
  2. problem in persistant socket connection
    By poms4symbian in forum Browsing and Mark-ups
    Replies: 0
    Last Post: 2006-01-03, 13:23
  3. Server socket support (Nokia 6600 in particular)
    By es_nokia in forum Mobile Java Networking & Messaging & Security
    Replies: 4
    Last Post: 2003-12-04, 23:23
  4. Building an XML driven image processing server
    By dugla in forum Mobile Java General
    Replies: 1
    Last Post: 2003-11-13, 10:18
  5. Socket to server web, send a recive data;
    By maxsoftnokia in forum Mobile Java Tools & SDKs
    Replies: 1
    Last Post: 2003-07-16, 16:24

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×