开发者

How to use ksoap timeout in android?

开发者 https://www.devze.com 2023-02-19 06:37 出处:网络
I am using ksoap2 to create a user registration application in Android. When I send request to the server and there is no response within 10 seconds I want to prompt the user with a \"Try again\" mes

I am using ksoap2 to create a user registration application in Android.

When I send request to the server and there is no response within 10 seconds I want to prompt the user with a "Try again" message. If the server responds within开发者_Python百科 10 seconds I want the program to proceed without the message.

How can I achieve this? Is there a TimerTask or any method for Timeout in KSoap2?


private String METHOD_NAME;
    private String NAMESPACE;
    private String SOAP_ACTION;
    private String URL;
private int TimeOut=3000;//
    private SoapObject so;
    SoapSerializationEnvelope envelope;
    HttpTransportSE androidHttpTransport;
 try
               {      

                      METHOD_NAME = "myutility";
                      NAMESPACE = "http://";
                      SOAP_ACTION = NAMESPACE + METHOD_NAME;
                      Thread.sleep(2000);  
                      SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
                      envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
                      envelope.setOutputSoapObject(request);

                      URL = "http://www.example.com";
                      androidHttpTransport = new HttpTransportSE(URL,Time_Out);
                      androidHttpTransport.call(SOAP_ACTION,envelope);
                      so = (SoapObject)envelope.bodyIn;
                      String s=so.toString();
                      //Your processing here
               }
               catch(InterruptedException e)
               {
                   //When timeout occurs handles this....

               }
catch( Exception e )
               {}
0

精彩评论

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

关注公众号