简体   繁体   中英

Android, OSC, receiver not receiving messages.

I am working on an app that receive message from other program via OSC. The library I used is the JavaOSC from http://www.illposed.com/software/javaosc.html .

I put the following in the onCreate method (the try{} part):

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. 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. So to send message to the Emulator, you need to find out the ip of that first. Thanks.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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