×

Discussion Board

Results 1 to 2 of 2
  1. #1
    Regular Contributor
    Join Date
    Jun 2004
    Posts
    60

    Problem with downloading Images using DataInputStream

    I've written a MIDlet that downloads an image to the phone by using an address. It works prefectly on the emulator but on the phone it won't use the DataInputStream. I've checked the phones MIDP and CLDC version and if any optional packages where being used but all is fine. I've tried it on 3 different phones and none work but it works on all emulators. Could it just be the connection? I left the MIDlet running on the phone for at least 10 minutes and nothing happens.

    The phones did subscribe to data service and they did prompt to approve the network connection. I did check the server log file and there is no incoming connection, the log file does get an incoming connection from the emulator. Could it be the connection? I changed the http link in the code so it would download an image from www.o2.co.uk and the phone downloaded the image. Or is there some problem with the server?

    private Image getImage() throws IOException
    {
    ContentConnection connection = (ContentConnection)Connector.open("http://flash.o2.co.uk/personal/homepage/images/k700.jpg");
    DataInputStream iStrm = connection.openDataInputStream();
    ByteArrayOutputStream bStrm = null;
    Image im = null;

    try
    {
    byte imageData[];
    int length = (int) connection.getLength();
    if (length != -1)
    {
    imageData = new byte[length];
    iStrm.readFully(imageData);
    }
    else
    {
    System.out.println("Length unavail");
    bStrm = new ByteArrayOutputStream();
    int ch;
    while ((ch = iStrm.read()) != -1)
    bStrm.write(ch);
    imageData = bStrm.toByteArray();
    bStrm.close();
    }
    im = Image.createImage(imageData, 0, imageData.length);
    }
    finally
    {
    if (iStrm != null)
    iStrm.close();
    if (connection != null)
    connection.close();
    if (bStrm != null)
    bStrm.close();
    }
    return (im == null ? null : im);
    }
    }

    this connects to the site and downloads the image. but if I use my server nothing happens.

  2. #2
    Registered User
    Join Date
    Sep 2003
    Posts
    12
    Thats a weird one. When ever I'm diagnosing connection problems I usually use a packet sniffer like Ethereal

    http://www.ethereal.com

    That way you can see if the HTTP socket is being established.

    If it is the server check the headers you are returning compared to the headers that o2 return when you hit their server

Posting Permissions

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