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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T06:30:03+00:00 2026-05-29T06:30:03+00:00

I am to develop an Android application that receives a message from server but

  • 0

I am to develop an Android application that receives a message from server but I can connect to server but can’t receive a message because when I clicked on Button connect blocks. I think it’s because of the cycle but do not know how to resolve this situation in another way and would appreciate your help.

In short I want to know if there’s another way to detect when I receive a message and presents it.

Update: I found the solution like this:

String IP;

String comando;

PrintWriter msgout;

BufferedReader msgin;

Socket socket;

    private ConnectedThread mConnectedThread;



public void connect(){ //Function to Button connect

    IP = edit.getText().toString();

    try {

     InetAddress serverAddr = InetAddress.getByName(IP); //TCPServer.SERVERIP

     Socket socket = new Socket(serverAddr, 4444); //Porta 4444 serverAddr
     PrintWriter out = new PrintWriter( new BufferedWriter( new  OutputStreamWriter(socket.getOutputStream())),true);
     msgout = out;

     BufferedReader in = new BufferedReader(new  InputStreamReader(socket.getInputStream()));
     msgin = in;

 zav.text1.setText("Connectado.");

  //Wait to mensages
  mConnectedThread = new ConnectedThread();
  mConnectedThread.start();

     } catch (Exception e) {
         text1.setText("Erro! Não conectado." + e);
    }
}

public void send(String message){

     try {

         msg.println(message);


     } catch(Exception e) {
         text1.setText("Erro! Comando não enviado." + e);
 } 
}

private class ConnectedThread extends Thread {

    public void run(){

     while(true){

         //Read
     try {

                String str = msgin.readLine();
                 text1.setText(str);

              } catch(Exception e) {

                  text1.setText("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-05-29T06:30:03+00:00Added an answer on May 29, 2026 at 6:30 am

    Have you tried Push Notification? Here is a good place to start http://tokudu.com/2010/how-to-implement-push-notifications-for-android/

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

Sidebar

Related Questions

I want to develop application that sends image/txt or any file from one android
I am trying to develop an android application that will stream the video from
I am trying to develop an Android application that can be used to find
if we develop our Android application with target Android2.1-update1,can we install that application in
I'm trying to develop an android application that uses network connection. The server is
From an application I need to develop, I've received a specific font that has
I want to develop an android application which retrieving data from the Waze Live
I new in the android developing. I want to develop simple application that will
I have to develop an application that gives a popup message at a certain
I want to develop an Android application that visualize Dicom files and present them

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.