2017-03-28 13 views
0

私は、ボタンプレスに対応するテキストを含むパケットを送信しようとしています。それをwiresharkでキャプチャします。私はOSC/UDPを使用していますが、コードは正しいようですが、私の電話から送信されたパケットは見られません。今のOSC/UDPを使用してネットワークにテキストを送信する

、私だけOSCPortOut使用しています:

OSCPortOut reciever ; 
    OSCListener listener ; 
    OSCPortOut sender ; 
    String sendIPaddr; 
    int sendPort; 

はその後、OnCreateのは、私が指定したIP(私のPC)に接続しています。

protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
    // setContentView(R.layout.playerlogin); 
     setContentView(R.layout.activity_main); 

     Size = (SeekBar)findViewById(R.id.size); 
     Speed =(SeekBar)findViewById(R.id.speed); 
     Agility=(SeekBar)findViewById(R.id.agility); 
     Vision =(SeekBar)findViewById(R.id.vision); 

     text = (TextView) findViewById(R.id.text); 
     Size.setOnSeekBarChangeListener(this); 
     Speed.setOnSeekBarChangeListener(this); 
     Agility.setOnSeekBarChangeListener(this); 
     Vision.setOnSeekBarChangeListener(this); 

     try { 
     InetAddress otherIP = InetAddress.getByName("192.168.1.2"); 

     sender = new OSCPortOut(otherIP,5000); 
    }catch (Exception e){ 
     text.setText("IO Exc: " 
       + e.getClass().getName() + ", " 
       + e.getMessage()); 
    } 
    } 

ラジオボタンをクリックすると、クリックに対応するテキストをネットワークに送信しようとしています。

public void onRadioClick(View v) { 

     n = (RadioButton) findViewById(R.id.north); 
     s = (RadioButton) findViewById(R.id.south); 
     e = (RadioButton) findViewById(R.id.east); 
     w = (RadioButton) findViewById(R.id.west); 
     c = (RadioButton) findViewById(R.id.center); 
     //String direction = text.setText(); 
     // or, you can check each radiobutton and find which one is checked. 
     if (n.isChecked()) { 
      text.setText("North"); 
     } else if (s.isChecked()) { 
      text.setText("South"); 
     } else if (e.isChecked()) { 
      text.setText("East"); 
     } else if (w.isChecked()) { 
      text.setText("West"); 
     } else if (c.isChecked()) { 
      text.setText("Center"); 
     } 
     String direction = String.valueOf(text); 
     try{ 
      sender.send(new OSCMessage(direction)); 
     }catch(Exception E){ 
} 

最初は、ポートにアクセスする際に問題がありましたが、これはマニフェストにアクセス許可を追加することで解決しました。私はキャプチャしているUDPパケットの中で北、南、東西、または中央を見ていないのですか? MainCativityで

+0

は、お使いの携帯電話は、192.168.1.xのサブネット内のIPを持っていますか? –

+0

はい、そうです。私は何を変更する必要がありますか? –

答えて

0

は、この任意のネットワーク通信のために追加する必要があります。

if (android.os.Build.VERSION.SDK_INT > 9) { 
      StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build(); 
      StrictMode.setThreadPolicy(policy); 
     } 
関連する問題