Hi All,

I need to send asynchronous calls to the server. During network
connection this works fine. How ever if i disable my LAN from Network
connections android will through a socket exception after the
specified timeout for that particular call. Now the issue that i face
is the time out happens in a synchronous manner. Though both the calls
has been started in a thread the timeout is not happening at the same
time. If i keep the timeout as 20sec i am getting a socket exception
for the first call after 20 sec and after the next 20 sec i get the
timeout for the next call. Why is this happening..? I am not opening
two connections asynchronously in this case. I am attaching a sample
code that can replicate the above scenario

package and.httptest;

import java.net.HttpURLConnection;
import java.net.URL;

import android.app.Activity;
import android.os.Bundle;

public class htptest extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        Thread th=new Thread(httpconn2);
              th.start();
              Thread th2=new Thread(httpconn1);
              th2.start();
    }

    static Runnable httpconn1=new Runnable() {

        @Override
        public void run() {
                // TODO Auto-generated method stub
            try{
              HttpURLConnection httpCon=null;
              URL url_ContentList = new URL("http://www.google.com";);
              httpCon=(HttpURLConnection)url_ContentList.openConnection
();

              System.out.println("Before connecting to
server !!!!!!!!!!!!!!!!! ");

              httpCon.setRequestMethod("GET");
              httpCon.setConnectTimeout(20000);
              httpCon.setReadTimeout(10000 /* milliseconds */);
              System.out.println("time out is"+httpCon. getConnectTimeout
());
              httpCon.connect();

              System.out.println("Response code is
resp1"+httpCon.getResponseCode());
            }
            catch(Exception e)
            {System.out.println("exp is"+e);}
        }
    };

    static Runnable httpconn2=new Runnable() {

        @Override
        public void run() {
                // TODO Auto-generated method stub
            try{
              HttpURLConnection httpCon=null;
              URL url_ContentList = new URL("http://www.bing.com";);
              httpCon=(HttpURLConnection)url_ContentList.openConnection
();

              System.out.println("Before connecting to
server !!!!!!!!!!!!!!!!! ");

              httpCon.setRequestMethod("GET");
              httpCon.setConnectTimeout(20000);
              httpCon.setReadTimeout(10000 /* milliseconds */);
              System.out.println("time out is"+httpCon. getConnectTimeout
());
              httpCon.connect();

              System.out.println("Response code is
resp2"+httpCon.getResponseCode());
            }
            catch(Exception e)
            {System.out.println("exp is"+e);}
        }
    };
}


Please correct me if i am wrong



-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to