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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T12:56:57+00:00 2026-06-12T12:56:57+00:00

I have a server program on my PC which is running and waiting for

  • 0

I have a server program on my PC which is running and waiting for the Android client.

I set these in my Android code:

mHost      = "127.168.1.1"; //or getLocalIpAddress()?
mPort      = 5000;
mSocket    = new Socket(mHost, mPort);

And have these permissions in the manifest:

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

When I try to connect to my PC, I get this logcat output:

10-08 19:18:40.970: E/ex closeInputOutput(8735): java.lang.NullPointerException
10-08 19:18:40.970: E/doInBackground Exception(8735):  java.net.ConnectException: failed to connect to /127.168.1.1 (port 5000): connect failed: ECONNREFUSED (Connection refused)

I have a router, how can I connect to my PC to 127.168.1.1:5000?

edit:

public static final 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();
                String ip4 = inetAddress.getHostAddress().toString();
                if (!inetAddress.isLoopbackAddress() && InetAddressUtils.isIPv4Address(ip4)) {
                    Log.d(TAG, "getLocalIpAddress(): " + ip4);
                    return ip4;
                }
            }
        }
    }
    catch (Exception e) {
        Log.e(TAG, "ServerUtils: getLocalIpAddress(): " + e.getMessage());
    }
    return null;
}

this is my new Code, this return 192.168.1.104, wich is not working. with my ipconfig I get 192.168.1.102 (that is the correct.)
So in the last code what is wrong? How can I get the correct local IP?

  • 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-12T12:56:58+00:00Added an answer on June 12, 2026 at 12:56 pm

    It may be different in your LAN, but usually the address 192.168.1.1 is the router address (not the host address).

    Confirm you host address by running the command:

    ipconfig

    at command prompt. The IPv4 address will be the host address and the Gateway address the router address. Be sure to use the correct address on both PC and device.

    Note: You need to post the relevant part of your code, both on PC and device, if you want more precise help.

    –EDITED–

    IP address is like a home address, each device has his own. So when you run ipconfig on the windows machine you get the windows machine ip address. When you call the getLocalIpAddress() on device you get the device IP address.

    If you want to connect from the device to the PC, you need to:

    • Run on the PC a program that listens to the port 5000. If there is no program listening on this port, any attempt to connect to this port will be refused.
    • On device you run a program that connects to 192.168.1.102 (pc IP address) at port 5000
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a server program which should run full time a day. If I
I have a java program which sends a udp packet to a server when
I have created a program which allows me to upload images to my server.
I have a program app1 which launches another application using: app2Server := CreateOleObject('app2.Server'); On
I have a program that downloads PCM data from a Web Server, which it
I have a client/server program in TCP written in C, and I would like
all. I'm having a bit of weird problem with client server program. I have
I have a server program is running on my PC. The server program using
i am developing a client/server program in which i want to invoke a method
I'm trying to implement a client server app which a Server program has a

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.