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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T14:59:18+00:00 2026-05-22T14:59:18+00:00

Is it possible to connect two phones using socket programming? I tried following code

  • 0

Is it possible to connect two phones using socket programming?
I tried following code but it didn’t work

 protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    serverStatus = (TextView) findViewById(R.id.server_status);

    SERVERIP = getLocalIpAddress();//Public function to get ip address to it is //working fine 

    Thread fst = new Thread(new ServerThread());
    fst.start();
}

public class ServerThread implements Runnable {

    public void run() {
        try {
            if (SERVERIP != null) {
                handler.post(new Runnable() {
                    public void run() {
                        serverStatus.setText("Listening on IP: " + SERVERIP);
                    }
                });
                serverSocket = new ServerSocket(8087);
                   } else {
                handler.post(new Runnable() {
                    public void run() {
                        serverStatus.setText("Couldn't detect internet connection.");
                    }
                });
            }
        } catch (Exception e) {
            handler.post(new Runnable() {
                public void run() {
                    serverStatus.setText("Error");
                }
            });
            e.printStackTrace();
        }
    }
}
  • 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-22T14:59:19+00:00Added an answer on May 22, 2026 at 2:59 pm

    Yes, it is possible but I think the first thing you should do is read up on Java Socket programming as there are a few problems with your code that make me think you haven’t quite got a grasp of it yet. The main problems are:

    1. Your ServerSocket never accepts a connection and is therefore never actually ‘listening’.
    2. Even if it was listening, if this code is running on both phones they would both only be listening and not actively seeking a connection with each-other.

    You will need to implement a client on one phone and a server on the other like @Deepak has shown.

    Also, you may want to check out AsyncTask in this article for updating views from a non-UI thread (instead of a handler).

    Finally, make sure your app includes the android.permission.INTERNET permission in AndroidManifest.xml.

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

Sidebar

Related Questions

Is it possible to connect two android phones by wi-fi, without using a bluetooth/GSM/CDMA/IR?
Is it possible to connect a socket between two mobile devices (iPhones) over the
Is it possible to manually connect to the database using sqlclient and sqlconnection (ie
All, is there any means by which it is possible to connect to two
Is it possible to connect two iPhones over the web (wide area network) for
I need to connect two android devices using wifi. One device is a server,
I have connected both database, but used two connection string. Is there any possible
Is it possible to connect two (or more) android devices via USB to the
Is that possible to connect mysql database between servers. I mean, lets say i
Is it possible to connect to Sql Server for the purpose of executing simple

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.