2016-04-05 25 views
3

AndroidデバイスはUSB経由でコンピュータに接続しています。 TCPポート転送をadb forward tcp:<port> tcp:<port>で有効にして、ソケットと正常に通信しましたが、私はUDPで同じことをする方法がわかりません。PCとAndroidアプリの間でUSB通信のUDP転送を有効にする方法

EDIT v1の:私はエミュレータ上で自分のアプリケーションを立ち上げ、telnet localhost 5554を入力し、redir add udp:<port>:<port>、それ が働いていた、私はls をしようとすると、それが働いているので、私の関数executeCMDがfunctionnalです。

一部のWebサイトには、このredir add udp:<port>:<port>ようredirを使用するように言ったが、私はそうするとき、私はエラーを取得:

usage: 
    redir --lport=<n> --cport=<n> [options] 
    redir --inetd --cport=<n> 

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

    Version 2.2.1. 

は、それから私は、私は、このメソッドを作成したので、このコマンドは、Androidデバイス上で起動する必要があります考えた:

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)) > 0) output.append(buffer, 0, read); 

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

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

    return output.toString(); 
} 

そして、私はそのように呼ばれる:

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

出力がなく、UDPサーバーは、UDPクライアントと通信できません。

私は少し失われています...私は検索を続けますが、あなたが私を助けることができます。先に行く。

ありがとうございました。だから、最終的には

答えて

0

、私はUDPはUSB通信に転送を有効にする方法を見つけることができませんでしたが、私はかなりうまく機能し、他の代をしましたが、 あなたは見に(コンピュータのpingから電話をテザリングUSBを有効にする必要がありますそれが適切に)有効になっている場合

  1. は、デスクトップ上の電話でTCPサーバとTCPクライアントを作成します。
  2. adb tcp:<port> tcp:<port>をデスクトップに実行すると、localhostの電話とTCPソケットを介して通信できます。
  3. (TCPテザリングネットワーク上の)のIPアドレスを携帯電話のをTCPクライアントに送信させます。
  4. 次に、TCP接続を閉じることができます。通常の状況と同じように、アドレスでソケットとのUDP接続を開始することができます。
関連する問題