简体   繁体   English

Android,OSC,接收器未收到消息。

[英]Android, OSC, receiver not receiving messages.

I am working on an app that receive message from other program via OSC.我正在开发一个通过 OSC 从其他程序接收消息的应用程序。 The library I used is the JavaOSC from http://www.illposed.com/software/javaosc.html .我使用的库是来自http://www.illposed.com/software/javaosc.html的 JavaOSC。

I put the following in the onCreate method (the try{} part):我将以下内容放入 onCreate 方法(try{} 部分):

import com.illposed.osc.OSCListener;
import com.illposed.osc.OSCMessage;
import com.illposed.osc.OSCPort;
import com.illposed.osc.OSCPortIn;

public class MainActivity extends AppCompatActivity{
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        try {
            OSCPortIn receiver = new OSCPortIn(5679);
            OSCListener listener = new OSCListener() {
                public void acceptMessage(Date time, OSCMessage message) {
                    System.out.println("Message received!");
                }
            };
            receiver.addListener("/fromPython", listener);
            receiver.startListening();
        } catch (SocketException e) {
            Log.d("OSCSendInitalisation", "Socket exception error!");
        }
    }    
}

In my python code, I send out a message with the address of /fromPython to the right port, which I tested with other programs (eg Max, Pd) and confirm message can be received.在我的python代码中,我向正确的端口发送了一条地址为/fromPython的消息,我用其他程序(例如Max、Pd)测试了该消息并确认可以接收消息。 However, I could not receive any message here.但是,我在这里收不到任何消息。 Please help.请帮忙。

Actually, there is nothing wrong with the code.实际上,代码没有任何问题。 It is that the Android Emulator has a different IP address than the computer.原因是 Android Emulator 的 IP 地址与计算机的 IP 地址不同。 So to send message to the Emulator, you need to find out the ip of that first.因此,要将消息发送到模拟器,您需要先找出它的 ip。 Thanks.谢谢。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM