【发布时间】:2017-08-21 23:38:24
【问题描述】:
我正在尝试发送带有与按下按钮相对应的文本的数据包,然后在wireshark上捕获它。我正在使用 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 数据包中都没有看到北、南、东西或中心?
【问题讨论】:
-
你的手机有IP在192.168.1.x子网吗?
-
是的,确实如此。我需要改变什么?
标签: java android udp packet osc