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 9170753
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T16:04:14+00:00 2026-06-17T16:04:14+00:00

i wrote a Server for our global Leadbord which actually works now. I can

  • 0

i wrote a Server for our global Leadbord which actually works now.
I can send data to it if it’s active. But if it’s down my app does not stop. I dont get a solution for it i hope you can help me. Here is the sending:

public void saveToDatabase(LeadboardElement element2) {
    final LeadboardElement element = element2;
    send = false;
    // Need to be a thread! else android blocks it because it could take to
    // long to send!
    this.thread = new Thread() {
        public void run() {
            try {
                Socket soc = new Socket(Config.TCP_SERVERNAME_IP,
                        Config.TCP_PORT);
                DataOutputStream out = new DataOutputStream(
                        soc.getOutputStream());
                DataInputStream in = new DataInputStream(
                        new BufferedInputStream(soc.getInputStream()));

                // to call the save statement!
                out.writeInt(0);
                // give the stuff
                out.writeUTF(element.getName());
                out.writeInt(element.getLevel());
                out.writeInt(element.getKillPoints());

                // close it
                out.close();
                in.close();
                soc.close();
                send = true;
                //join at every error
            } catch (UnknownHostException e) {
                e.printStackTrace();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    };
    // start it
    thread.start();

    // join thread
    if (!send) {
        boolean retry = true;
        while(retry)
        try {
            this.thread.join();
            retry = false;
            Log.w(TAG, "sending to server stopped!");
        } catch (InterruptedException e2) {
            Log.w(TAG, "Thread could not be joined");
        }
    }
}

I noticed that i need to do it in a thread since API 5 so it works like this. It’s called at the end of an Game if the player touches the screen. Everything get stopped and the data is sent to the Server. If hes down it does not work we stuck in the fade to black.
I guess i need something like a timeout. I tried it with a CountDownTimer but this acutally does not solve the problem.

Thanks alot!

  • 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-06-17T16:04:15+00:00Added an answer on June 17, 2026 at 4:04 pm

    Changing the way you initialize the socket, you can set a timeout.

    Socket s1 = new Socket();
    s1.setSoTimeout(200);
    s1.connect(new InetSocketAddress("192.168.1." + i, 1254), 200);
    

    Add a timeout when creating a new Socket

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wrote a perl program which send the updated data from a file to
On our SQL Server (Version 10.0.1600), I have a stored procedure that I wrote.
Through a lot of learning and research, i wrote a server side program. But
I have a server that I can ssh into but that's it. Otherwise it
I wrote a tiny HttpHandler, which works beautifully on my machine. However, once it
I wrote an ASP.Net which acts as our company's hub of reporting services. I
I use Microsoft SQL server to save and retrieve DateTime . But in our
For our webservice, I wrote some logic to prevent multipart/form-data POSTs larger than, say,
In some of our SQL Server Reporting Services reports we wrote for SQL 2005,
I have an HTTP server which is in our internal network and accessible only

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.