New OSC block on android: Receiver does not get any messages

I am following the SimpleReceiver sample of the new OSC block on Android. The receiver does not receive any messages, nor does it throw any errors.

I have enabled the network access in the AndroidManifest.xml file:

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.CHANGE_WIFI_MULTICAST_STATE" />

Is there anything else I should do?

I am multicasting OSC messages over UDP.

Thanks.

–8

I haven’t used the OSC block on Android, yet (should just work). I know that for multicasting there’s some further socket setup that is needed. See the Broadcast sample. Setting up multicast is similar to setting up broadcast. If possible, can you set up the Sender to just send directly to the ip address of the phone receiver and port? Or see if the phone can send to a desktop?

UDP Broadcast + WiFi has given me some issues in the past. I tend to avoid it if I can.

@ryanbartley: Thanks.

Sending OSC to a specific IP of the android phone works.

I am broadcasting from a desktop application (Isadora), in which instead of a specific IP address, I am setting 255.255.255.255. This works on iOS with no change on the receiving part.

The broadcast sample you are referring to is for sending the OSC messages. This, using Isadora OSC sender just works in all of the cases I tested, except the android receiver. Are you saying to receive broadcast messages on Android, I need to set the sender differently?

Thanks.

–8

In addition to not being able to receive the broadcast messages, androids are NOT able to send the broadcast messages.

Setting the sender:

    mSocket = std::shared_ptr<asio::ip::udp::socket>(new udp::socket( App::get()->io_service(), udp::endpoint( udp::v4(), 10001 ) )) ;
    mSender = std::make_unique<osc::SenderUdp>( mSocket, udp::endpoint( address_v4::broadcast(), destinationPort ) );

Sending the message:

    auto pos =  event.getTouches().front().getPos();
	osc::Message msg( "/start/1" );
	msg.append( pos.x );
	msg.append( pos.y );

	mSender->send( msg );

The error:

E/cinder: |error  | virtual void cinder::osc::SenderBase::handleError(const error_code&, const string&)[930] Socket error: Permission denied, didn't send message [/start/1]

–8

Interesting, I wonder if there’s some more security setup needed by the device. I’ll search around. I haven’t really tested on android before.

I submitted an issue here.

I had a project sending UDP with Asio on Linux a while back and had to run the app as root if I wanted to broadcast. Could be related?

It turns out on android one needs to acquire a special lock in order to receive broadcast messages.

To achieve that, I am overriding CinderNativeActivity.java’s onCreate method.

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        wifi=(WifiManager)getSystemService(Context.WIFI_SERVICE);
        wifiLock = wifi.createMulticastLock("AUGMENTED_THEATRE");
        wifiLock.acquire();
    }

Also to conserve the battery:

    protected void onPause() {
        wifiLock.release();
        super.onPause();
    }

    protected void onResume() {
        wifiLock.acquire();
        super.onResume();
    }

Although the lock is called “MultiCast”, my app now receives the broadcast messages.

It still does not send broadcast messages though.

–8

I was just about to post this crazy old forum post that I found detailing this issue. I’m glad you found it. I haven’t found why there’s a permissions issue on sending broadcast messages.

Thanks, same solution at the end of the thread. And reading about the hardware differences in that context, I have tested Sony, LG, Motorola devices. So far so good.

–8

1 Like