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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T10:34:13+00:00 2026-05-30T10:34:13+00:00

I have an android application which (over the network) communicates with a desktop server

  • 0

I have an android application which (over the network) communicates with a desktop server application (Both programmed in Java and GUI based). For now to test, i simply have a way to specify the socket on the android phone. However, in the future when i release the application, i want it to be able to attempt connecting to the server by itself.

Some ideas i have had so far is getting the IP address of the phone, and then looping through a class C address space on the same port and seeing if any of those sockets connect. Do you guys have anything else you can suggest?

Also, what is the best way to get the phone’s IP Address in Android? I have a way but it only works on android 2.3 and lower…on ICS it completely flops and gives random gibberish. Here it is:

public String getLocalIpAddress() {
    try {
        for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); en.hasMoreElements();) {
            NetworkInterface intf = en.nextElement();
            for (Enumeration<InetAddress> enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements();) {
                InetAddress inetAddress = enumIpAddr.nextElement();
                if (!inetAddress.isLoopbackAddress()) {
                    return inetAddress.getHostAddress().toString();
                }
            }
        }
    } catch (Exception ex) {
    }
    return null;
}
  • 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-30T10:34:14+00:00Added an answer on May 30, 2026 at 10:34 am

    Looping over C-class network needless overkill. I wouldn’t use it unless as an utter last resort. Your user may have A-class network (10.x.x.x, popular in workplaces), or B-class, because… he likes it so 😉

    The better way would be to utilise broadcast address (or multicast if you prefer, but it’s a bit more work). You may implement simple discovery protocol for your application based on UDP datagrams. In such case your server listens to the broadcast port, e.g UDP 192.168.0.255:6666 (port of your choosing) and responds to any activity by sending the IP:PORT it’s listening to to the requester.

    Phone->Broadcast: "Is there anybody?"
    Server1->Phone  : "I am here. Talk to me at 192.168.0.123:6666"
    Server2->Phone  : "I am here. Talk to me at 192.168.0.124:6666"
    

    Client can then display available servers and ask to which one the user wants to connect, then connect to TCP port provided in the answer (I assume client-server connection is TCP, but it can be anything, the idea is the same).

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

Sidebar

Related Questions

I need to build Android application using Java which is able to send request
i have an android application which has a listview for listing 14 items inside
I have an Android Bluetooth application which manages a couple of remote devices( Capsules
I have an Android application which sends json data to PHP script. The PHP
I have an android application in which if user changes his/her system font through
I have android application in which for a logged facebook user to retrieve in
Hello I have an android application which has a service running. After 20 mins
I have developed a android application which I want to test on multiple devices
I'm writing an Android application which requires the user to login. I have a
I have an Android application that uses speech recognition in an Activity. The GUI

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.