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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T06:33:12+00:00 2026-06-11T06:33:12+00:00

I need to send a command from an android phone, via wifi, to a

  • 0

I need to send a command from an android phone, via wifi, to a router, through a wire, to a “cable box” <— just assume cable box for now. When sending the command from my laptop, I get a nice healthy flood of data on my wireshark reading. Also, the cable box responds and does what it is told. However, as soon as I try to put the App on my phone and use it, nothing happens. If I send the command from my phone to my computer I get 2 empty packets sent back and forth between my phone and computer. What am I doing wrong here? I’ve been struggling with this for 3 days now.

import android.util.Log;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.net.SocketAddress;
import java.util.ArrayList;

public class TCPRunnable implements Runnable{
    private final String ip;
    private final int port;
    private final ArrayList<String> commands;

//<editor-fold defaultstate="collapsed" desc="Constructors">
    @Deprecated
    public TCPRunnable(String ip,int port,ArrayList<String> Cmds){
        this.ip=ip;
        this.port=port;
        this.commands = Cmds;
    }
    public TCPRunnable(String ip,int port,String Cmd){
        this.ip=ip;
        this.port=port;
        this.commands = new ArrayList<String>();
        this.commands.add(Cmd);
    }
//</editor-fold>

//<editor-fold defaultstate="collapsed" desc="Static Properties">

//</editor-fold>

//<editor-fold defaultstate="collapsed" desc="Instance Properties">

//</editor-fold>

    public void run() {
        try {
            InetAddress serverAddr = InetAddress.getByName(this.ip);
            SocketAddress socketadd= new InetSocketAddress(serverAddr,port);

            Log.d("TCP","R: Making the socket.");
            Socket socket = new Socket();
                //new Socket();//
            Log.d("TCP","R: Connecting...");
            socket.connect(socketadd, 1500);

        //  PrintWriter out = new PrintWriter (new BufferedWriter( new OutputStreamWriter(socket.getOutputStream())),true);

            InputStream socketReader = socket.getInputStream();
            OutputStream socketWriter = socket.getOutputStream();
             try {
                for (int i = 0; i < commands.size();i++){
                    String Cmd = commands.get(i);
                    Log.d("TCP","R: Sending: '"+Cmd+"'");
                    byte [] iByte;
                    byte[] oByte = new byte[100];//in 32 bit signed integers
                    int CmdLen = 0;
                    CmdLen = commands.get(i).length();
                    oByte[0] = (byte) Integer.parseInt("AF", 16);
                    oByte[1] = (byte) Integer.parseInt("FA", 16);
                    oByte[2] = (byte) Integer.parseInt("F0", 16);
                    oByte[3] = (byte) (255-oByte[2]);
                    oByte[4] = (byte) (Cmd.length() +2);
                    oByte[5] = (byte) (255-oByte[4]);
                    oByte[6] = (byte) Integer.parseInt("07", 16);
                    iByte = Cmd.getBytes();
                    System.arraycopy(iByte, 0, oByte, 7, Cmd.length());
                    oByte[7+CmdLen] = (byte) Integer.parseInt("00",16);
                    oByte[8+CmdLen] = (byte) Integer.parseInt("00",16);

                    Object [] data = new Object [3];
                    data[0]=oByte;
                    data[1]=0;
                    data[2]=(9 + CmdLen);
                    //ping(IP,PORT);
                    //disconnect();
                    //connect();
                    socketWriter.write((byte[])data[0],(Integer)data[1],(Integer)data[2]);
                    socketWriter.flush();
                    Log.d("TCP","R: Sent.");
                    //Thread.sleep(500L);
                }
            }catch (Exception ex){
                Log.e("TCP", "S: Sending failed: "+ex);
            }finally{

                socketWriter.flush();
                socketWriter.close();
                socket.close();
                Log.d("TCP","R: Done.");
             }

        } catch (IOException ex) {
            Log.e("IOEXCEPTION",""+ex);
        }




    }
//<editor-fold defaultstate="collapsed" desc="Static Methods">

//</editor-fold>

//<editor-fold defaultstate="collapsed" desc="Instance Methods">

//</editor-fold>

//<editor-fold defaultstate="collapsed" desc="Accessors">

//</editor-fold>

}

Edit:
I still can’t send data. but at least I know why ‘no data is sent’ now. It was because I was sending data to a laptop and not the machine itself.
Second Edit
where my code comments out //sleep(500L);, It should be uncommented. Otherwise you send data too quickly to receive a response.

  • 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-11T06:33:14+00:00Added an answer on June 11, 2026 at 6:33 am

    Are those two packets like this?

    SYN -->
        <-- SYN ACK
    

    Isn’t there a third ACK going back?

    I see you issue a flush on the stream, but I’m not sure if the OS honors that request. Can you try sending more data, like some kilobytes, and see if anything comes out? A wireshark capture would also be useful.

    Update

    In the pastebin, you try to connect to .32 which is your laptop then. In the successful case, .32 connects to .42. Obviously if port 20036 is not open on your laptop and doesn’t run the service, you can’t connect to it.

    There are some ways to work around this:

    A) If using wireless connection on laptop and phone, you might be able to put the laptop into promiscuous mode to listen to all packages. Google helps here.

    B) You may set up the laptop to redirect the connection to the box, so you can sniff on the laptop. This depends on the laptop OS.

    • For Linux you may use something like redir
    • It seems both Linux and Windows has rinetd

    C) Communicate directly with the box, and root your Android device then install a packet capture software directly on the Android device.

    Update

    rinetd for windows:

    rinetd.conf:

    0.0.0.0 port_to_listen_on_laptop box_ip_address target_box_port
    

    Then:

    rinetd.exe -c rinetd.conf
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to call another app from my app, and send it some command
I need to send command to windows service from a windows form. I have
I need to send some information from the command prompt to a text file
I need to execute and send command to external app from python: .\Ext\PrintfPC /p
I need to send a (probably one) simple one-way command from client processes to
I need to send a command from a computer to another computer (both running
I need to write a program that create pipe send filename from command line
We need send h264 from flash to Wowza and after to vlc by RTSP
I need send certain attributes(say, human readable user name) from server to client after
I need to send an HTML report with images from an application. The report

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.