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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T11:05:20+00:00 2026-06-14T11:05:20+00:00

I am having trouble connecting my android emulator to my computer. I can send

  • 0

I am having trouble connecting my android emulator to my computer. I can send information to the android but when sending back it just fails.

Here is what I have so far:

public class sendDataToRegion extends AsyncTask<String,Void,List<String> >{

        final TextView who = (TextView)findViewById(R.id.txtWho);
        final TextView what = (TextView)findViewById(R.id.txtWhat);
        final TextView when = (TextView)findViewById(R.id.txtWhen);
        final TextView where = (TextView)findViewById(R.id.txtWhere);
        final TextView actionTaken = (TextView)findViewById(R.id.txtActionTaken);
        final TextView lengthOfTime = (TextView)findViewById(R.id.txtLengthOfTime);

        public List<String> dataSend2 = new ArrayList<String>();


        @Override
        protected List<String> doInBackground(String... params) {
            try
            {
                System.out.println("Mobile Server Program");

                String whoString = who.getText().toString();
                String whatString = what.getText().toString();
                String whenString = when.getText().toString();
                String whereString = where.getText().toString();
                String actionString = actionTaken.getText().toString();
                String lengthString = lengthOfTime.getText().toString();

                dataSend2.add(whoString);
                dataSend2.add(whatString);
                dataSend2.add(whenString);
                dataSend2.add(whereString);
                dataSend2.add(actionString);
                dataSend2.add(lengthString);


                int port = 4444;

                ServerSocket server = new ServerSocket(port);

                Socket socket=server.accept();

                DataOutputStream network = new DataOutputStream(socket.getOutputStream());


                for(int i = 0; i< dataSend2.size();i++){
                    network.writeUTF(dataSend2.get(i));
                }


            }
            catch (Exception e) {

            Log.e("TCP", "S: Error", e);

            }

            return dataSend2;
        }

        protected void onPostExecute( ) {
            System.out.println("Thread Finished " + dataSend2.size());


        }

    }//End of inner class

And it gets as far as creating the server socket, but nothing after that. Could someone point me in the right direction?

Thanks

UPDATE

here is the client:

try
        {

            String ip = "146.176.230.192";
            System.out.println("IP connected");

            int port = 4444;
            System.out.println("port connected");

            // Connect to the server
            Socket sock = new Socket(ip, port);
            System.out.println("socket created");

            // Create the incoming stream to read messages from
            DataInputStream network = new DataInputStream(sock.getInputStream());

            // Display our address
            System.out.println("Address: " + sock.getInetAddress());
            String line;

            while ((line = network.readUTF()) != null)
            {


                System.out.println(line);
            }



            sock.close();
        }
        catch (IOException ioe)
        {
            System.out.println("Connection failed");


        }
  • 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-14T11:05:21+00:00Added an answer on June 14, 2026 at 11:05 am

    use port 7612 and run this command to forward ports before you run your program:

    adb forward tcp:7612 tcp:7612
    

    Client side: default IP: 127.0.0.1

    Server side: IP address is the wildcard address

    Server side:

        private ServerThread mServer;
        ....
        java.net.ServerSocket s = new java.net.ServerSocket();
    
    // bind, only port used 
    java.net.InetSocketAddressendPoint = new InetSocketAddress(port);
    
    
      if( !s.isBound() ){
        s.bind(7612);
      }
          ....
    

    Client side

     private           Socket mSocket;
     private static final int mConnectTimeout = 2500; // 2.5 seconds
    
     ....
     mSocket = new Socket();
     InetSocketAddress remoteAddr = new InetSocketAddress(127.0.0.1, 7612); 
        mSocket.connect(remoteAddr, mConnectTimeout); 
     ....
    

    ServerThread class

    import java.io.IOException;
    import java.net.ServerSocket;
    import java.net.Socket;
    
    
    
    public class ServerThread implements Runnable{
    public ServerThread(ServerSocket socket, OnConnectItf onConnect) // OnConnectItf is some callback
       {
        mServer   = socket;
        mCallback  = onConnect;
        mCancel    = false;
    }
    
    public void cancel(){
        mCancel = true;
    }
    
    
    public void run() {
        while (true){
            try {
                Socket s = mServer.accept();
                if (mCancel == true) break;
    
                 ....
            }
            catch (IOException e) {
                // optional: implement on error handler
                break;
            }
        }
    
        return;
    }
    
    private ServerSocket mServer;
    private OnConnectItf mCallback;
    private boolean      mCancel;
    

    }

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

Sidebar

Related Questions

I'm having trouble connecting a socket from my android phone to my computer running
I am having a bit of trouble writing an android app that can communicate
I have my Android emulator for the time being connecting to my local computer.
I just downloaded MooTools 1.4. I'm having trouble connecting a button click to the
I am currently having trouble connecting to my webservice on android. I am using
I am having trouble connecting my online application to others across another network. I
I'm using rubber to deploy a rails application and am having trouble connecting to
I'm doing my first C++ - Qt4 application and I'm having some trouble connecting
I'm having a bit of trouble connecting intstruments to my App on a iPod
I'm trying to implement picking using Pyglet's OpenGL wrapper, but I'm having trouble converting

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.