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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T08:11:27+00:00 2026-06-10T08:11:27+00:00

This is a bit long so I’ll start with the question: how do I

  • 0

This is a bit long so I’ll start with the question: how do I get the ip to link up sockets (not on a private network) on Android phone?

And how can I check if a port is being blocked by the phones ISP?

A bit more info:

I have a program that show users locations on a map and you can click on them and start a chat. I’ve tested the socket conntion and it was working fine on 2 emulators, but when I tried it on a phone it failed to link up the socket.

Out of time exception on the:

NotificationChat.ChatSocket = new Socket(serverAddr, 5000);

And my best guess is the IP of the server (aka phone 1) is not right, or maybe the port is blocked or in use.

I tried 2 ways to get the phone IP:

public static String getLocalIpAddress() {      
    try {
        Socket socket = new Socket("www.google.com", 80);
        Log.i("iptest", socket.getLocalAddress().toString().substring(1));
        String ip=socket.getLocalAddress().toString().substring(1);
        socket.close();
        return ip;

    } catch (Exception e) {
        Log.i("", e.getMessage());
        return "exception in get ip";
    }

    /*
    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 (SocketException ex) {
        Log.e("b2264", ex.toString());
    }
    return null;  */
}

IP I got was: 10.227.130.191
Which if i remember right is a class A local IP.

The server side:

while(flag==1)
    {   
        if(ss==null)
        {
            try {
                    ss = new ServerSocket(SERVERPORT);

                } catch (IOException e) {
                    e.printStackTrace();
                }                     
        }
            try {
                    Log.d("thread","chatnotifiction befor ss accpect");
                    Socket NotAvilabale=null;
                     NotAvilabale = ss.accept();
                    if(ChatSocket!=null)
                    {
                        Log.d("test55","not avilable");
                        PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(NotAvilabale.getOutputStream())),true);
                        out.println("notav");
                        NotAvilabale.close();
                        continue;
                    }
                    ChatSocket=NotAvilabale;
                    Log.d("thread","chatnotifiction after ss accpect");
                    CharSequence contentText = "someone wants to talk to you";

                    PendingIntent contentIntent = PendingIntent.getActivity(this, 1, notificationIntent, 2);

                    notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);         

                    mNotificationManager.notify(NOTIFI_ID, notification);
            } catch (IOException e) {
                Log.d("chat notifi io exception","chat notifi io exception ");
                    e.printStackTrace();
            }catch (Exception e) {
                Log.d("chat notifi Exception 2","chat notifi Exception 2 ");
                // TODO: handle exception
            }


    }

I do not have much experience with sockets. This is the first time I am using them. I hope one of you has a bit more experience and can help me out.

Thanks in advance (sorry for the crape english).

  • 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-10T08:11:29+00:00Added an answer on June 10, 2026 at 8:11 am

    So while I don’t know much about how the cell infrastructures work, I can only imagine that it is similar to any ISP.

    So imagine you are a large carrier with millions of clients. You can’t give them all each their own reserved public IPs, that would be costly and inefficient. But you do have to give them IPs in order to send data to them. So you basically carve up your network into multiple segments. Each segment has complete network of private ips. Since most connections on phones are not peer to peer it would be safe to assume that all outbound traffic goes through a gateway or a set of gateways until it reaches a public gateway that will relay the message out to which ever public host is beng request. Whatever that gateway’s IP is though, is probably what your server (and any server on the internet) would see as the client ip (which is probably not the same as the reported IP by the client). With all the devices acting this way, it would also be safe to assume that you can’t just make a connection to 10.227.130.191 from a routable IP within the same network unless it has a port open, which in this case would probably mean running your software. I think physical proximity of phones may come into play on some level deciding as to which private segments two different phones get put it. However in most cases, it is not predictable enough to be able to say that Phone A at Lat1,Lng1 IP 10.127.x.x can talk to Phone B at Lat1,Lng1 IP 10.127.x.y simply because they do not have enough information to know if they are on the same physical segment of the network.

    So unless you are on a wifi AP, it would be really really hard to allow a direct connections between the phones simply because the probability of them being on the same routable network would be very low.

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

Sidebar

Related Questions

This question is a bit long, please bear with me. In REST, i think
This question might be a bit long and specific, but I have been attempting
This question is a bit long due the source code, which I tried to
thanks for reading, this is a bit long, but I hope someone can help
(The following question is a bit long so if you're not interested in persistent
This post might be a bit long, but if you think you can help,
Problem This question may seem a bit long, but I try to give as
This is a bit of a long shot as I don't have access to
Please refers to the edit portion for my explanation. This is a bit long
Sorry if this is a bit long winded but I thought better to post

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.