Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6658229
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T01:52:04+00:00 2026-05-26T01:52:04+00:00

I am experiencing way too many timeouts in the communication between my app and

  • 0

I am experiencing way too many timeouts in the communication between my app and my server..
My problem is that the server doesn’t even get the message. So I guess the problem is somewhere inside my Android code and not the server code.

Here is my code:

HttpParams params = new BasicHttpParams();
    SchemeRegistry registry = new SchemeRegistry();
    registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
    ThreadSafeClientConnManager manager = new ThreadSafeClientConnManager(params, registry);

    //configure timeouts
    HttpConnectionParams.setConnectionTimeout(params, 1000 * 1000);
    HttpConnectionParams.setSoTimeout(params, 1000 * 1000);

    //and finally initialize the http client
    this.mClient = new DefaultHttpClient(manager,params);

    //init the response handler
    this.mResponseHandler = new MyResponseHandler(ctx);




    final HttpPost method = new HttpPost(HttpSender.SERVER_URL);

    List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
    nameValuePairs.add(new BasicNameValuePair("message", s));

    try {
        method.setEntity(new UrlEncodedFormEntity(nameValuePairs));
    } catch (UnsupportedEncodingException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }

    Runnable sender = new Runnable(){
        @Override
        public void run() {
            try {
                mClient.execute(method, mResponseHandler);

            } catch (ClientProtocolException e) {

                Log.v(TAG, "unable to send " + s);
                e.printStackTrace();

            } catch (IOException e) {

                Log.v(TAG, "unable to send " + s);
                e.printStackTrace();

            }
        }
    };

    new Thread(sender).start();

Is there something wrong with my code? By the way it doesn’t always timeout.. just about 2/3 of the time

EDIT : I noticed that when i start the phone it usually works fine (no timeouts) but after
a few messages i start getting the timeouts so maybe i am not closing something correctly
in my code?

EDIT : another thing i have noticed is that if the messages work fine and then i turn my phone (from vertical to horizontal and vice versa)
the problems arise again and right after the orientation change i get:

10-03 11:47:46.920: ERROR/[FT]-Server(3563): NetworkStateReceiver :intent: android.net.conn.CONNECTIVITY_CHANGE

Thanks for your help!
Omri

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T01:52:05+00:00Added an answer on May 26, 2026 at 1:52 am

    well i am not exactly sure what solved it but i think the problem was that i wasn’t closing
    connection and methods anyhow here is my code if any one is interested:

    public class HttpSender {
    
    private ResponseHandler<String> mResponseHandler;
    private String TAG = "HttpSender";
    static final String SERVER_URL = "http://**some ip address**/myServer";
    
    public HttpSender(Context ctx){
        //init the response handler
        this.mResponseHandler = new MyResponseHandler(ctx);
    }
    
    //TODO : see if using postSend is better and dosent cause timeouts?
    public void send(final String s,final Context ctx, final int type){
        Log.v(TAG, "sending message : " + s + "type message of is " + Integer.toString(type));
    
        //for testing
        Toast.makeText(ctx,"sending \n" + s,Toast.LENGTH_LONG).show();
        //done for testing
    
        this.postSend(s, ctx, type);
    
    
    }
    
    
    public void postSend(final String s,final Context ctx,final int type){
        final HttpPost method = new HttpPost(HttpSender.SERVER_URL);
    
        List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
        nameValuePairs.add(new BasicNameValuePair("message", s));
    
        final DefaultHttpClient client = getNewClient(ctx);
    
        try {
            method.setEntity(new UrlEncodedFormEntity(nameValuePairs));
        } catch (UnsupportedEncodingException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }
    
        Runnable sender = new Runnable(){
    
            @Override
            public void run() {
                try {
                    client.execute(method, mResponseHandler, new BasicHttpContext());
                    client.getConnectionManager().shutdown();
    
    
                } catch (ClientProtocolException e) {
                    client.getConnectionManager().shutdown();
                    method.abort(); 
                    e.printStackTrace();
                } catch (IOException e) {
                    client.getConnectionManager().shutdown();
                    method.abort();
    
                    Log.v(TAG, "unable to send " + s);
                        e.printStackTrace();
                    }
                }
            }
        };
        new Thread(sender).start();
    
    }
    
    
    
    private DefaultHttpClient getNewClient(Context ctx) {
    
        HttpParams params = new BasicHttpParams();
        SchemeRegistry registry = new SchemeRegistry();
        registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
        ThreadSafeClientConnManager manager = new ThreadSafeClientConnManager(params, registry);
    
        //and finally initialize the http client
        DefaultHttpClient client = new DefaultHttpClient(manager,params);
    
        return client;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i am currently experiencing a problem were i get *** glibc detected *** ./efit:
The problem I'm experiencing is when I add the message Body part of the
I've been experiencing problems with designing views so that the subviews behave the way
Experiencing jquery in rails through .js.erb templates; but completely puzzled by a simple problem
I am experiencing a problem with some Javascript - please see my site and
I'm currently experiencing some problems with my server. I have a pool which is
We're experiencing a problem where Facebook likes are counted individually for http://urlhere.com and https://urlhere.com
I'm developing an app which uses a custom font but I'm experiencing some unusual
We are currently experiencing an issue that requires the client endpoint configuration file to
I'm experiencing problem with the following code, I created two buttons with onClickListener added.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.