开发者

android - How to set Timeout

开发者 https://www.devze.com 2023-03-21 11:07 出处:网络
In My application i am calling the web service method 开发者_开发百科but it takes more time for the response.

In My application i am calling the web service method 开发者_开发百科but it takes more time for the response.

Because of without time specifying, i got the following Exception. How to handle it. java.net.socketException: connection Reset.

So i want to implement the timeout for that particular web service method. It means suppose web service response not get after the specified time then it will generate timeout exception. how to implement it.

can anybody help me?

thanks


URL URLObj = null;
HttpURLConnection ConnObj = null;
URLObj = new URL("Http://Url.to.the/webservice");
ConnObj = (HttpURLConnection) URLObj .openConnection();
ConnObj .setConnectTimeout(5000); // This will set the desired time out for the connection request
0

精彩评论

暂无评论...
验证码 换一张
取 消