Hello everyone,

I've got an application which is making a web request every 10s using
HttpURLConnection.
When the application starts in 3G, it works great. Then I activate
Wifi and after that, all my requests fail during exactly 10 minutes
with the fallowing exception : Socket is not connected.
The behavior is the same if I start in Wifi and then I switch to 3G.

Here's a code sample:

[code]
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        Button button1 = (Button)findViewById(R.id.Button01);
        button1.setOnClickListener(new OnClickListener() {

                        @Override
                        public void onClick(View v) {
                                go=true;

                                Thread t = new Thread(new Runnable() {

                                        @Override
                                        public void run() {

                                                while(go)
                                                {
                                                        try
                                                        {
                                                                
HttpURLConnection connection = (HttpURLConnection) new
URL("http://www.google.com";).openConnection();
                                                                
connection.setConnectTimeout(5000);

                                                                
connection.connect();
                                                                
connection.disconnect();

                                                                
Log.i("DataTransition", "DataTransition Conection OK");
                                                        }
                                                        catch(Exception e)
                                                        {
                                                                
Log.e("DataTransition", "DataTransition Conection failure:
"+e.getMessage());
                                                        }

                                                        try
                                                        {
                                                                
Thread.sleep(6000);
                                                        }
                                                        catch(Exception e)
                                                        {
                                                                //nothing to do 
right now
                                                        }
                                                }
                                        }
                                });
                                t.start();
                        }
                });

        Button button2 = (Button)findViewById(R.id.Button02);
        button2.setOnClickListener(new OnClickListener() {

                        @Override
                        public void onClick(View v) {

                                go=false;
                        }
                });
    }
[/code]

What's the problem here ? Do we need to setup something at socket
level ? a timeout (10 minutes is the default one) ?

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

Reply via email to