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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T16:07:28+00:00 2026-06-16T16:07:28+00:00

I am attempting to create an application which has a edit text view and

  • 0

I am attempting to create an application which has a edit text view and a button. This button will send whatever is in the edit text through a TCP connection to the server.

I have accomplished the sending of the edit text, but after I click the button once, the application crashes. How can I put this into a loop so I can send multiple messages? Here is my source

public class MainActivity extends Activity {

    //Handler h;

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        final EditText eText = (EditText) findViewById(R.id.address);
        final TextView tView = (TextView) findViewById(R.id.pagetext);
        final Button button = (Button) findViewById(R.id.ButtonGo);
                button.setOnClickListener(new Button.OnClickListener() {
                    public void onClick(View v) {
                        try {
                            Socket s = new Socket("192.168.0.117", 4447);
                            BufferedReader in = new BufferedReader(new InputStreamReader(s.getInputStream()));
                            final BufferedWriter out = new BufferedWriter(new OutputStreamWriter(s.getOutputStream()));
                            //send output msg
                            String outMsg = ((EditText)findViewById(R.id.address)).getText().toString().trim();
                            out.write(outMsg);
                            out.flush();
                            Log.i("TcpClient", "sent: " + outMsg);
                        } catch (UnknownHostException e) {
                            tView.setText(e.toString());
                            Log.v("Tcp",e.toString());
                        } catch (IOException e) {
                            tView.setText(e.toString());
                            Log.v("Tcp",e.toString());
                        }catch (Exception e) {
                            tView.setText(e.toString());

                        } 
                    }
                }); 
    }
}
  • 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-16T16:07:29+00:00Added an answer on June 16, 2026 at 4:07 pm

    I accomplished this by using two different buttons. A connection button, and a send message button. I think when the server attempted to recreate the socket, the TCP connection broke and the server caught an exception and starting freaking out. Here is the new code.

                bConnect.setOnClickListener(new Button.OnClickListener() {
                    public void onClick(View v) {
                        try {
                            Socket s = new Socket("192.168.0.117", 4447);
                            out = new BufferedWriter(new OutputStreamWriter(s.getOutputStream()));
                            BufferedReader in = new BufferedReader(new InputStreamReader(s.getInputStream()));
                        } catch (UnknownHostException e) {
                            tView.setText(e.toString());
                            Log.v("Tcp",e.toString());
                        } catch (IOException e) {
                            tView.setText(e.toString());
                            Log.v("Tcp",e.toString());
                        }catch (Exception e) {
                            tView.setText(e.toString());
    
                        } 
                    }
                });
    
                bSend.setOnClickListener(new Button.OnClickListener() {
                    public void onClick(View v) {
                        try {
                            String outMsg = ((EditText)findViewById(R.id.address)).getText().toString().trim();
                            out.write(outMsg);
                            out.flush();
                            Log.i("TcpClient", "sent: " + outMsg);  
                        } catch (IOException e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                        }
    
    
                        finally{
    
                        }
                        }
    
    
                    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am attempting to write a VB.net application which will allow users to create
I'm attempting to create an application for SharePoint. I would like this application to
I'm attempting to create a small application in which I can make a poul
I am attempting to create an application which interacts with a database. I program
I am attempting to create a Java source file which will interface with my
I'm attempting to create a Windows application that will allow the controls on earbuds/headphones
I'm attempting to create a contacts application that has two main entities - person
I am attempting to create/deploy an application onto the Redhat OpenShift Express platform, and
I'm attempting to create Data Access Layer for my web application. Currently, all datatables
In a Silverlight 3.0 application I'm attempting to create a rectangle in a canvas

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.