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
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
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,
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
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![]()
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,