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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T05:06:59+00:00 2026-05-27T05:06:59+00:00

I am writing an application that communicates using sockets. I have a server running

  • 0

I am writing an application that communicates using sockets. I have a server running on one android emulator on a computer, then i have 2 other clients running on android emulators on 2 other computers. I am trying to get the 2 clients to connect to the server.

This works when i run the server and clients on the same computer, but when i attempt to do this on the same wifi network and on separate computers it gives me the following error. The client and server code is posted below. A lot is stripped out just to show the important stuff. Also, after the server starts i telnet into the server and run these commands redir add tcp:5000:6000 (i have also tried without doing the redir but it still says the same thing). Then i start the clients and get the error. Thanks for the help!

Both the 5000 port and 6000 port are open on my router. And i have windows firewall disabled on the computer hosting the server.

11-27 18:54:02.274: W/ActivityManager(60): Activity idle timeout for HistoryRecord{44cf0a30 school.cpe434.ClassAidClient/school.cpe434.ClassAid.ClassAidClient4Activity}
11-27 18:57:02.424: W/System.err(205): java.net.SocketException: The operation timed out
11-27 18:57:02.454: W/System.err(205):  at org.apache.harmony.luni.platform.OSNetworkSystem.connectSocketImpl(Native Method)
11-27 18:57:02.454: W/System.err(205):  at org.apache.harmony.luni.platform.OSNetworkSystem.connect(OSNetworkSystem.java:114)
11-27 18:57:02.465: W/System.err(205):  at org.apache.harmony.luni.net.PlainSocketImpl.connect(PlainSocketImpl.java:245)
11-27 18:57:02.465: W/System.err(205):  at org.apache.harmony.luni.net.PlainSocketImpl.connect(PlainSocketImpl.java:220)
11-27 18:57:02.465: W/System.err(205):  at java.net.Socket.startupSocket(Socket.java:780)
11-27 18:57:02.465: W/System.err(205):  at java.net.Socket.<init>(Socket.java:314)
11-27 18:57:02.465: W/System.err(205):  at school.cpe434.ClassAid.ClassAidClient4Activity.onCreate(ClassAidClient4Activity.java:102)
11-27 18:57:02.474: W/System.err(205):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
11-27 18:57:02.474: W/System.err(205):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2459)
11-27 18:57:02.474: W/System.err(205):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2512)
11-27 18:57:02.474: W/System.err(205):  at android.app.ActivityThread.access$2200(ActivityThread.java:119)
11-27 18:57:02.474: W/System.err(205):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1863)
11-27 18:57:02.474: W/System.err(205):  at android.os.Handler.dispatchMessage(Handler.java:99)
11-27 18:57:02.474: W/System.err(205):  at android.os.Looper.loop(Looper.java:123)
11-27 18:57:02.486: W/System.err(205):  at android.app.ActivityThread.main(ActivityThread.java:4363)
11-27 18:57:02.486: W/System.err(205):  at java.lang.reflect.Method.invokeNative(Native Method)
11-27 18:57:02.486: W/System.err(205):  at java.lang.reflect.Method.invoke(Method.java:521)
11-27 18:57:02.486: W/System.err(205):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
11-27 18:57:02.486: W/System.err(205):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
11-27 18:57:02.486: W/System.err(205):  at dalvik.system.NativeStart.main(Native Method)

The server code

public class ClassAidServer4Activity extends Activity {

    ServerSocket ss = null;
    String mClientMsg = "";
    String mClientExtraMsg = "";
    Thread myCommsThread = null;
    public static final int SERVERPORT = 6000;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        TextView tv = (TextView) findViewById(R.id.textView1);
        tv.setText("Nothing from client yet");
        this.myCommsThread = new Thread(new CommsThread());
        this.myCommsThread.start();
    }

    class CommsThread implements Runnable {
        public void run() {
            //         Socket s = null;
            try {
                ss = new ServerSocket(SERVERPORT );
            } catch (IOException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            }
            while(true) {
                try {


                    Socket socket = ss.accept();
                    connectedDeviceCount++;

                    Thread lThread = new Thread(new ListeningThread(socket));
                    lThread.start();

                } catch (IOException e) {
                    e.printStackTrace();
                }
            }


        }
    }

    class ListeningThread implements Runnable {

        private Socket s = null;

        public ListeningThread(Socket socket) {
            // TODO Auto-generated constructor stub
            this.s = socket;
        }

        @Override
        public void run() {
            // TODO Auto-generated method stub
            while (!Thread.currentThread().isInterrupted()) {
                Message m = new Message();
                //              m.what = QUESTION_ID;
                try {
                    if (s == null)
                        s = ss.accept();
                    BufferedReader input = new BufferedReader(
                            new InputStreamReader(s.getInputStream()));
                    String st = null;
                    st = input.readLine();
                    String[] temp = parseReadMessage(st);
                    mClientMsg = temp[1];
                    if(temp.length > 2) {
                        mClientExtraMsg = temp[2];
                    }

                    m.what = Integer.parseInt(temp[0]);
                    myUpdateHandler.sendMessage(m);
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }

    }
}

The client code

public class ClassAidClient4Activity extends Activity {

    //telnet localhost 5554
    //redir add tcp:5000:6000
    private Socket socket;
       private String serverIpAddress = "192.168.1.102";
    // if "redir add" is disabled this should be 6000
    private static final int REDIRECTED_SERVERPORT = 5000;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);


        try {
            InetAddress serverAddr = InetAddress.getByName(serverIpAddress);
            socket = new Socket(serverAddr, REDIRECTED_SERVERPORT);
        } catch (UnknownHostException e1) {
            mQuestionAdapter.add("UnknownHostException");
            e1.printStackTrace();
        } catch (IOException e1) {
            mQuestionAdapter.add("IOException");
            e1.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-27T05:06:59+00:00Added an answer on May 27, 2026 at 5:06 am

    I figured it out. I needed to create a proxy. I used this SO post as a reference. And heavily modified this code to work for multiple connections. It is working now. HOORAY!

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

Sidebar

Related Questions

I have an application consisting of two windows, one communicates to the other and
I'm writing a simple application that communicates with an external server. The server currently
I have an application that I was writing that communicates with a third-party application
I am writing an application using Sencha Touch that will require a login to
I'm writing an application for the iPhone that communicates with a SQLite database but
I'm writing an application that communicates with the serial port to control a device.
I am writing an application that communicates with Active Directory and I need to
I have a QT C++ application that runs the Octave program using QProcess. I
I'm writing an application that communicates by sending bytes to the USB port. I'd
I'm writing an application that communicates through the Windows RPC mechanism with a hosted

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.