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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T20:29:22+00:00 2026-05-26T20:29:22+00:00

I’m writing a short test app to practice connecting to a server. All the

  • 0

I’m writing a short test app to practice connecting to a server. All the app does is take an IP from an editText box, and then connect to the server. It looks like I can connect to the server because I am able to send data to the server and have the server print it.

I wanted to add some error checking to confirm that I am connected before attempting to send anything to the server. However, the problem is, whenever I use the Socket.isConnected() or isBound() methods my app crashes.

So how do I check if I’m connected if these methods doesn’t seem to work. As I said, I know I’m connected because I can send stuff to the server.

Below is the code, I connect on the press of a button. What I want to do is confirm that I’m connected, and then kick off a thread that will work in the background sending and receiving data from the server. In the section that say’s s.isBound() is where the program crashes. I can even put in s.isConnected() and it will crash also.

Last, what is the difference between isBound, and isConnected?

private OnClickListener connectListener = new OnClickListener() {            
    @Override
    public void onClick(View v) {
        if (!connected) {
            serverIpAddress = serverIp.getText().toString();
            if (!serverIpAddress.equals("")) {
                try{
                    InetAddress serverAddr = InetAddress.getByName(serverIpAddress);
                    Log.d("ClientActivity", "Trying to Connect");
                    s = new Socket(serverAddr, SERVERPORT);
                    Log.d("ClientActivity", "Connected");

                    output = s.getOutputStream();

                    input = s.getInputStream();

                } 
                catch (UnknownHostException e) {
                    e.printStackTrace();
                } 
                catch (IOException e) {
                    e.printStackTrace();
                }

                if(s.isBound()){
                    connected = true;
                    cThread = new Thread(new ClientThread());
                    cThread.setName("Client Connection Thread");
                    cThread.start();
                }

            }
        }
    }
};

This is what the log outputs.

11-13 17:03:56.718: D/ClientActivity(2039): Trying to Connect
11-13 17:03:56.757: W/System.err(2039): java.net.ConnectException: /192.168.16.1:6340 - Connection refused
11-13 17:03:56.757: W/System.err(2039):     at org.apache.harmony.luni.net.PlainSocketImpl.connect(PlainSocketImpl.java:207)
11-13 17:03:56.757: W/System.err(2039):     at org.apache.harmony.luni.net.PlainSocketImpl.connect(PlainSocketImpl.java:183)
11-13 17:03:56.757: W/System.err(2039):     at java.net.Socket.startupSocket(Socket.java:705)
11-13 17:03:56.757: W/System.err(2039):     at java.net.Socket.<init>(Socket.java:263)
11-13 17:03:56.757: W/System.err(2039):     at com.AUIEE.client_test.Client_TestActivity$1.onClick(Client_TestActivity.java:88)
11-13 17:03:56.757: W/System.err(2039):     at android.view.View.performClick(View.java:2485)
11-13 17:03:56.765: W/System.err(2039):     at android.view.View$PerformClick.run(View.java:9089)
11-13 17:03:56.765: W/System.err(2039):     at android.os.Handler.handleCallback(Handler.java:587)
11-13 17:03:56.765: W/System.err(2039):     at android.os.Handler.dispatchMessage(Handler.java:92)
11-13 17:03:56.773: W/System.err(2039):     at android.os.Looper.loop(Looper.java:130)
11-13 17:03:56.773: W/System.err(2039):     at android.app.ActivityThread.main(ActivityThread.java:3859)
11-13 17:03:56.773: W/System.err(2039):     at java.lang.reflect.Method.invokeNative(Native Method)
11-13 17:03:56.773: W/System.err(2039):     at java.lang.reflect.Method.invoke(Method.java:507)
11-13 17:03:56.773: W/System.err(2039):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:840)
11-13 17:03:56.773: W/System.err(2039):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:598)
11-13 17:03:56.773: W/System.err(2039):     at dalvik.system.NativeStart.main(Native Method)
11-13 17:03:56.781: D/AndroidRuntime(2039): Shutting down VM
11-13 17:03:56.781: W/dalvikvm(2039): threadid=1: thread exiting with uncaught exception (group=0x4001e560)
11-13 17:03:56.789: E/AndroidRuntime(2039): FATAL EXCEPTION: main
11-13 17:03:56.789: E/AndroidRuntime(2039): java.lang.NullPointerException
11-13 17:03:56.789: E/AndroidRuntime(2039):     at com.AUIEE.client_test.Client_TestActivity$1.onClick(Client_TestActivity.java:103)
11-13 17:03:56.789: E/AndroidRuntime(2039):     at android.view.View.performClick(View.java:2485)
11-13 17:03:56.789: E/AndroidRuntime(2039):     at android.view.View$PerformClick.run(View.java:9089)
11-13 17:03:56.789: E/AndroidRuntime(2039):     at android.os.Handler.handleCallback(Handler.java:587)
11-13 17:03:56.789: E/AndroidRuntime(2039):     at android.os.Handler.dispatchMessage(Handler.java:92)
11-13 17:03:56.789: E/AndroidRuntime(2039):     at android.os.Looper.loop(Looper.java:130)
11-13 17:03:56.789: E/AndroidRuntime(2039):     at android.app.ActivityThread.main(ActivityThread.java:3859)
11-13 17:03:56.789: E/AndroidRuntime(2039):     at java.lang.reflect.Method.invokeNative(Native Method)
11-13 17:03:56.789: E/AndroidRuntime(2039):     at java.lang.reflect.Method.invoke(Method.java:507)
11-13 17:03:56.789: E/AndroidRuntime(2039):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:840)
11-13 17:03:56.789: E/AndroidRuntime(2039):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:598)
11-13 17:03:56.789: E/AndroidRuntime(2039):     at dalvik.system.NativeStart.main(Native Method)
  • 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-26T20:29:22+00:00Added an answer on May 26, 2026 at 8:29 pm

    Firstly, your

    if(s.isBound()){
        connected = true;
        cThread = new Thread(new ClientThread());
        cThread.setName("Client Connection Thread");
        cThread.start();
    }
    

    block is at a wrong place. If any catch block triggered, then it will execute the above block. But if an exception is raised that means that s will probably be null, so you have a certain NullPointerException. (crash of the application) The appropriate place is inside the try block.

    Secondly, as you can see from the logcat log, the connection that you are trying to establish refuses. Perhaps there is something wrong with the ip/port or a firewall.

    Also logcat informs you that you probably have an uncaught exception.

    1-13 17:03:56.781: W/dalvikvm(2039): threadid=1: thread exiting with uncaught exception (group=0x4001e560)
    

    Fix that problems and if the problem persist come again to discuss it.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a text area in my form which accepts all possible characters from
Does anyone know how can I replace this 2 symbol below from the string
I am writing an app with both english and french support. The app requests
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I am currently running into a problem where an element is coming back from
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out

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.