×

Discussion Board

Results 1 to 2 of 2

Thread: Http Connection

  1. #1
    Registered User
    Join Date
    Oct 2005
    Posts
    55

    Http Connection

    Hi! Currently I'm developing an application which will deal with the http connection. For the http connection, I will send out my request to download an image. The problem I'm facing right now is when there's no response back for my request, my whole application is hang. I totally unable to exit the application and need to reset the device all the time. Here, I would like to ask whether is there anyone can help me to handle the no response back for the http connection. I'm using the below method for my http connection.

    HttpConnection connection = null;
    connection = (HttpConnection)Connector.open(url,Connector.READ_WRITE);
    DataInputStream iStrm = connection.openDataInputStream();
    ByteArrayOutputStream mSrm = null;
    int length = (int) connection.getLength();
    mData = new byte[length]; mSrm.readFully(mData);

    After opening the connector, I need to close the connector when receiving the response back from my request. If there's no response back, my connector is always open and this cause my application hang.

    Is there way to close the connector if there's no response back from the request made to http connection?

    Please help....


    YHat

  2. #2
    Super Contributor
    Join Date
    Mar 2006
    Posts
    516

    Re: Http Connection

    Hi,

    have a look at this link.

    http://www.corej2me.com/DeveloperRes...ng/index.shtml

    try
    {
    // ContentConnection includes a length method
    byte imageData[];
    int length = (int) connection.getLength();
    if (length != -1)
    {
    imageData = new byte[length];

    // Read the png into an array
    iStrm.readFully(imageData);
    }
    else // Length not available...
    {
    ByteArrayOutputStream bStrm = new ByteArrayOutputStream();

    int ch;
    while ((ch = iStrm.read()) != -1)
    bStrm.write(ch);

    imageData = bStrm.toByteArray();
    bStrm.close();
    }

    // Create the image from the byte array
    im = Image.createImage(imageData, 0, imageData.length);
    }

Similar Threads

  1. Replies: 2
    Last Post: 2006-10-06, 17:24
  2. Another HTTP connection problem
    By issw in forum Mobile Java Networking & Messaging & Security
    Replies: 5
    Last Post: 2006-10-04, 16:36
  3. Close HTTp Connection in N6230i
    By cars2004 in forum Mobile Java General
    Replies: 1
    Last Post: 2005-06-24, 10:46
  4. Close HTTp Connection in N6230i
    By cars2004 in forum Mobile Java Networking & Messaging & Security
    Replies: 0
    Last Post: 2005-06-24, 09:29
  5. HTTP connection on 6310i, 7650, 9210 and in sony-ericsson p800
    By mika1982 in forum Mobile Java Networking & Messaging & Security
    Replies: 1
    Last Post: 2003-07-24, 16:44

Posting Permissions

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