×

Discussion Board

Results 1 to 5 of 5
  1. #1
    Registered User
    Join Date
    Oct 2007
    Posts
    25

    How to set Timeout in HttpConnection

    Hi All,
    I am using HttpConnection to post the data to server ,In case the server is not running ,sometimes the application hangs,so i need to set timeout for this problem or anybody have a right solution for this?

    Sasi Kumar

  2. #2
    Super Contributor
    Join Date
    Mar 2008
    Location
    The Capital of INDIA
    Posts
    4,328

    Thumbs up Re: How to set Timeout in HttpConnection

    Hi find the underlined solution for the query ..
    try
    {
    connection = (HttpConnection) Connector.open (urlToCall);
    responseCode = connection.getResponseCode ();
    String responseMessg = connection.getResponseMessage();
    if( responseCode != HttpConnection.HTTP_OK )
    {
    alert = "Some errors were encountered";
    serverState = CONNECTION_ERROR_STATE;
    smsCanvasGPRS.appState = smsCanvasGPRS.CONNECTION_ERR_STATE;
    throw new IOException ("HTTP response code: " + responseCode);
    }
    else if ( responseCode == connection.HTTP_CLIENT_TIMEOUT)
    {
    alert = "Conenction timed out.Please make sure that server is running";
    serverState = CONNECTION_ERROR_STATE;
    smsCanvasGPRS.appState = smsCanvasGPRS.CONNECTION_ERR_STATE;
    }
    catch (IOException ex)
    {
    ex.printStackTrace ();
    System.out.println ("Caught while opening the Connection "+ex.toString () );
    alert= "Error While opening Connection";
    serverState = CONNECTION_ERROR_STATE;
    smsCanvasGPRS.appState = smsCanvasGPRS.CONNECTION_ERR_STATE;
    if(smsCanvasGPRS.isAppRunning = false && smsCanvasGPRS.appThread == null)
    smsCanvasGPRS.startAppThread();

    }
    catch ( Exception e )
    {
    alert = "You did not allow the application to communicate with the server";
    serverState = CONNECTION_ERROR_STATE;
    smsCanvasGPRS.appState = smsCanvasGPRS.CONNECTION_ERR_STATE;
    if(smsCanvasGPRS.isAppRunning = false && smsCanvasGPRS.appThread == null)
    smsCanvasGPRS.startAppThread();
    }



    Hope this may help you..When your server is not running then an IOException is thrown....similarly if you did not allow the application to access th web then SecurityException is thrown. Therefor the relative alert can be drawn on Canvas/Form
    Thanks with Regards,

    R a j - The K e r n e l


    Join Delhi-NCR Nokia Developer's Community,

  3. #3
    Registered User
    Join Date
    Oct 2007
    Posts
    25

    Re: How to set Timeout in HttpConnection

    Hi raj,
    thanks for ur reply,
    In that code which u gave after opening the url in the first line of the code it goes to exception ,if server is not running.

    It takes too much time to open the URL ,but i need time to be minimized or a defined time to open the URL.
    Sasi Kumar T

  4. #4
    Super Contributor
    Join Date
    Apr 2007
    Posts
    2,708

    Re: How to set Timeout in HttpConnection

    I seem to remember the standard j2me timeout is 60 secs, and afaik there is no option to change this...
    I'm not 100% sure though, I'd love to be corrected on this one, cause I never found a way to define the timeout time myself

  5. #5
    Super Contributor
    Join Date
    Mar 2008
    Location
    The Capital of INDIA
    Posts
    4,328

    Thumbs up Re: How to set Timeout in HttpConnection

    Hi,
    As Tiger79 has written in his post that standard time is 60 seconds for the timeout..that's true.
    see that depends upon the requirement ,you can do one thing , just start timer as soon as you request for the connection..and keep on checking this.

    after the desired time set the status of the server what you are looking for..
    hope this concept cab be implemented...and help you..

    thanks
    Last edited by raj_J2ME; 2012-08-13 at 09:11. Reason: spell
    Thanks with Regards,

    R a j - The K e r n e l


    Join Delhi-NCR Nokia Developer's Community,

Similar Threads

  1. Set Exif Gps Info Latitude.
    By shashishaw in forum Symbian
    Replies: 15
    Last Post: 2009-03-24, 16:50
  2. Installation of signed midlet and set permissions automatically
    By ulimativ in forum Mobile Java Networking & Messaging & Security
    Replies: 8
    Last Post: 2008-06-25, 08:28
  3. Set an Id when deploying an application
    By Rodrigo82 in forum Mobile Java Networking & Messaging & Security
    Replies: 2
    Last Post: 2007-02-07, 13:39
  4. How to set socket timeout
    By D|3-H4rD in forum Mobile Java Networking & Messaging & Security
    Replies: 1
    Last Post: 2006-11-30, 00:35
  5. Replies: 0
    Last Post: 2006-10-16, 17:31

Posting Permissions

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