×

Discussion Board

Results 1 to 5 of 5
  1. #1
    Registered User
    Join Date
    Jul 2006
    Posts
    2

    Connection Hangs

    Hi
    I have a problem with closing a connection on an open http request

    the scenario is that I send a http request to a server and leave the connection open waiting for an response(information update).
    If the information has been updated the server sends a response otherwise it will wait for 60 secondes
    and then send the response and we will open a new connection.

    when we for a number of reasons try to close the connection the application hangs until the response comes wich could be 60 seconds.
    This problem seems to concern Nokia phones we don'thave any problems with sonyericsson or samsung or any other brand that we have tested.

    Here is a part of the code that we use .

    //Open Connection
    this.connection = (HttpConnection) Connector.open(getConnectString(),
    getReadMode(), THROW_TIMEOUTS);
    this.connection.setRequestMethod(HttpConnection.POST);
    this.connection.setRequestProperty("Content-Language", "en-US");
    this.connection.setRequestProperty("Connection", "close");
    this.connection.setRequestProperty("Content-Type",
    "application/x-www-form-urlencoded");
    this.os = this.connection.openOutputStream();

    this.os.write(this.xml.getBytes());
    if (this.connection != null) {
    this.is = this.connection.openInputStream();
    }


    //Close Connection
    try{
    if (is != null) {
    is.close();
    }
    if (os != null){
    os.close();
    }
    if (connection != null) {
    connection.close();
    }
    }finally {
    connection = null;
    is = null;
    os = null;
    }

    anybody know how to solve this.

    Regards,
    Magnus

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

    Re: Connection Hangs

    hi Magnus,

    welcome aboard!

    does it mean that canceling connection from outside of thread which own it does nothing? (say by using cancel command added to UI),

    just of topic: why you need to suspend reponse from server for 60 seconds instead simply returning some data which can be proceeded to find if update is succesfull or if there is no new data?

    regards,
    peter

  3. #3
    Registered User
    Join Date
    Jul 2006
    Posts
    2

    Re: Connection Hangs

    Yes, we want to cancel the connection when the user choose a new task.

    The reason whe use the suspended response is that it's crucial for us to get data as soon as it changes and we don't want to generate a lot of unwanted traffic.

    regards Magnus

  4. #4
    Registered User
    Join Date
    Jul 2003
    Posts
    14

    Re: Connection Hangs

    Hi,

    I am afraid you can't stop an established connection. I faced this problem on several phones. And results are variables. Depending on carriers and also phone's VM.
    So when you open a connection, you don't know when it will be closed. The only solution is to stop the application

    Best,

    Mik

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

    Re: Connection Hangs

    Quote Originally Posted by mikbry
    The only solution is to stop the application
    Or to just let it do it's thing and discard the result. If you need a new connection do it in a separate thread. But be careful with that because you don't want too many of those threads hanging...

    shmoove

Similar Threads

  1. Replies: 2
    Last Post: 2006-10-06, 17:24
  2. MMS Interruption during GPRS connection hangs the device?
    By alexhong in forum Mobile Java Networking & Messaging & Security
    Replies: 0
    Last Post: 2004-08-31, 18:47
  3. MMS Interruption during GPRS connection hangs the device?
    By alexhong in forum Mobile Java General
    Replies: 0
    Last Post: 2004-08-31, 18:45
  4. inputstream.read hangs in BT connection
    By kitsch in forum Mobile Java Networking & Messaging & Security
    Replies: 0
    Last Post: 2003-12-23, 15:00
  5. Nokia connection manager hangs
    By puneetjain99 in forum PC Suite API and PC Connectivity SDK
    Replies: 2
    Last Post: 2003-10-17, 06:20

Posting Permissions

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