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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T00:05:07+00:00 2026-06-03T00:05:07+00:00

I have server and client code that works perfectly as a Java application. The

  • 0

I have server and client code that works perfectly as a Java application. The server is run on my local machine and listens on port 4444. Any Java application can connect easily, but when I move my code over to Android, I keep getting an IOException no matter what I try. I read that you have to change “localhost” to “10.0.2.2”, but I’m still getting an IOException. I tried my IP address from whatsmyip.org but it still gives me an IOException. Here’s my android code…

package test.myPackage;

import java.io.IOException;
import java.net.Socket;
import java.net.UnknownHostException;

import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;

public class TestProjectActivity extends Activity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        TextView tv = new TextView(this);
        tv.setText("Hello, Android");
        setContentView(tv);

    Socket s = null;
    try {
        s = new Socket("10.0.2.2", 4444);
        tv.setText("socket: CONNECTED!");
    } catch (UnknownHostException e) {
        tv.setText("socket: unknown host");
    } catch (IOException e) {
        tv.setText("socket: IO Exception");
    }
}

}

  • 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-03T00:05:08+00:00Added an answer on June 3, 2026 at 12:05 am

    First make sure your app has internet permission.

    The only time you can use the 10.0.2.2 alias is if your app is running on an emulator and wants to contact something running on the hosting machine. This does not work with actual android devices.

    For an actual android device, you would either have to put the device on the same wifi network as the PC hosting the server, find a way to abuse a tethering solution to get them on the same network over the USB cable, or move your server to a machine externally accessible from the Internet at large in order to be able to reach it from the device’s mobile network connection.

    And EvilDuck definitely has a point about abusing the UI thread.

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

Sidebar

Related Questions

i have a server - client application that runs on java 1.3; i want
i have a java chat server & client, that works fine. I made a
I have a simple server client application. Everything works, but at some stage it
I have a drag and drop code works perfectly on divs that have been
Say I have a simple client/server scenario with one method: // client code $client
I have an ASP.NET MVC server app and client code which uses jquery. I'd
I have a year's experience writing client code but none with server stuff. I
I have come up with the following code to call a webservice using client/server
Hi I have code which sets up a basic client to server scenario and
I have declared an enum in my server code, and would like my client

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.