How can I activate UDP forwarding for USB communication between a PC and an Android app I have an real Android device connected to a computer via USB. I managed to activate TCP port forwarding with adb forward tcp:&lt;port&gt; tcp:&lt;port&gt; and successfully communicate with sockets but I don't know how to do the same for UDP.


  EDIT : I launched my application on the emulator and typed telnet localhost 5554 and redir add udp:&lt;port&gt;:&lt;port&gt; and it
  worked, my function executeCMD is functionnal because when I try ls
  it's working.


Some websites said to use redir like this redir add udp:&lt;port&gt;:&lt;port&gt; but when I do so I obtain an error :

usage:
    redir --lport=&lt;n&gt; --cport=&lt;n&gt; [options]
    redir --inetd --cport=&lt;n&gt;

    Options are:-
        --lport=&lt;n&gt;     port to listen on
        --laddr=IP      address of interface to listen on
        --cport=&lt;n&gt;     port to connect to
        --caddr=&lt;host&gt;      remote host to connect to
        --inetd     run from inetd
        --debug     output debugging info
        --timeout=&lt;n&gt;   set timeout to n seconds
        --syslog    log messages to syslog
        --name=&lt;str&gt;    tag syslog messages with 'str'
        --connect=&lt;str&gt; CONNECT string passed to proxy server
        --bind_addr=IP  bind() outgoing IP to given addr
        --ftp=&lt;type&gt;        redirect ftp connections
            where type is either port, pasv, both
        --transproxy    run in linux's transparent proxy mode
        --bufsize=&lt;octets&gt;  size of the buffer
        --max_bandwidth=&lt;bit-per-sec&gt;   limit the bandwidth
        --random_wait=&lt;millisec&gt;    wait before each packet
        --wait_in_out=&lt;flag&gt;    1 wait for in, 2 out, 3 in&amp;out

    Version 2.2.1.


Then I thought this command should be launch on the Android device so I created this method :

 public String executeCMD(String cmd){
    StringBuffer output = new StringBuffer();
    try{
        Process process = Runtime.getRuntime().exec(cmd);
        BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
        int read;
        char[] buffer = new char[4096];
        while ((read = reader.read(buffer)) &gt; 0) output.append(buffer, 0, read);

        reader.close();
        process.waitFor();

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

    return output.toString();
}


And when I called it like that :

executeCMD("redir add udp:" + UDP_PORT + ":" + UDP_PORT)


I get no output and the UDP server on the Android app can't communicate with the UDP client.

So I'm a bit lost... I'll continue searching but If you can help me; go ahead.

Thanks.
So finally, I did not find out how to enable UDP forwarding for USB communication but I did somethings else that works pretty well, but you have to enable USB tethering (from the computer ping the phone to see if it's properly enabled):


Create a TCP server on the phone and a TCP client on the desktop.
Execute adb tcp:port tcp:port on the desktop so it can communicate with the phone on localhost via TCP sockets.
Make the TCP server send the IP address (on the USB tethering network) of your phone to the TCP client.
Then you can close the TCP connection and with the address you can initiate an UDP connection with socket as you would in a normal situation.