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

  • Home
  • SEARCH
  • 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 8883089
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T20:43:51+00:00 2026-06-14T20:43:51+00:00

My client sends to the client and reads acknowledged successfully from server just for

  • 0

My client sends to the client and reads acknowledged successfully from server just for the first time . As i hit send button again it Writes to server but fails to read again.

Heres my code:

Note: doit variables indicates that button pressed then it goes back to 0 till the user hit the button again.

 while (connected) {
                try {
                    Log.d("ClientActivity", "C: Sending command.");

                   b.setOnClickListener(new View.OnClickListener() {

                       public void onClick(View v) {
                           // TODO Auto-generated method stub

                         doit=1;
                         Log.e("ErrorButton","NextTime "+doit);
                       }
                   });  
                  if(doit==1)
                  {
                      Log.e("ErrorButton","If");
                  ////
                      out = new PrintWriter( new BufferedWriter( new OutputStreamWriter(socket.getOutputStream())),true); 
                    in = new BufferedReader(new InputStreamReader(socket.getInputStream()));                

                    out.println("Helloo");

                    while ((text = in.readLine()) != null) {
                        finall += text;
                        Log.e("Test","Final: "+finall);
                      if(text=="quit")
                      {
                          socket.close();
                      }
                  Log.e("ClientActivity", "After Read "+doit+" "+finall);
                 // in.close();

                   doit=0;
                   Log.e("ClientActivity", "After If "+doit);
                  } 

                  }     



                } catch (Exception e) {
                    Log.e("ClientActivity", "S: Error", e);
                }

            } 
  • 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-14T20:43:53+00:00Added an answer on June 14, 2026 at 8:43 pm

    Because, I think your Socket is not closed,

    Look at your code line, your if condition is wrong,

    if(text=="quit")
    

    it should be,

    if(text.equals("quit"))
    

    To compare a String always use either .equals() or equlaIgnoreCase() method from Java String Class.

    Also move out the Button’s onClickListener() from the while() loop.

    Every-time its create a New Listener Object for Button for each iteration which cause the problem.

    Write

    b.setOnClickListener(new View.OnClickListener() {
       public void onClick(View v) {
        doit=1;
        Log.e("ErrorButton","NextTime "+doit);
      }
    }); 
    

    in onCreate() of Activity.

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

Sidebar

Related Questions

Under here you find a simple server/client app that sends the integer 5 from
I have a client server situation, where the client sends the data (a movie
somebody know what is encoding type of message that client sends to websocket server?
Here's as far as I understand it: Client & Server make connection Client sends
I have a server, and a client. A client sends a request. The request
Writing a client application that sends images to a server via a webservice. As
I am writing a client for a server that typically sends data as strings
I'm studying Unix sockets programming. I made a time server that sends raw time
I have a simple server that waits for a client to connect, reads the
I have assignment when I need to write simple time server and a client

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.