openframeworks / openFrameworks

openFrameworks is a community-developed cross platform toolkit for creative coding in C++.
http://openframeworks.cc
Other
9.94k stars 2.55k forks source link

ofxNetwork: UDP Errors #5645

Open toliaferrode opened 7 years ago

toliaferrode commented 7 years ago

I'm testing a UDP application between Arm6 (Raspberry Pi/Raspbian) and Android. I'm using oF 0.9.8 on both Android and the Pi. Everything seems to work fine, it connects, it sends and receives data, but on the Arm6 side of things I always get the error: "[error] ofxNetwork: /home/pi/of_v0.9.8_linuxarm6l_release/addons/ofxNetwork/src/ofxUDPManager,cpp: 248 EINVAL: Invalid argument

It seems to happen if I set the program to send packets in the update function. Maybe I'm not supposed to do that? I need to send data that constantly updates and it seems the update function is the only place to do that in.

I also some times get a similar error message to the one aforementioned but it says host not reachable instead and that's rare. Although the network connection is established and is sending/receiving data just fine.

I'm wondering if this is effecting the performance of my application, or cause problems down the road. My project relys on UDP, the Raspberry Pi (or other Arm set top box) and Android/iOS.

bakercp commented 7 years ago

So to clarify, there are no bugs, but you get warnings and errors sometimes? Can you provide some example code to reproduce the errors?

arturoc commented 7 years ago

you might be sending to much data, try sending once every 2 or or more frames until you don't see the error

toliaferrode commented 7 years ago

@bakercp That's correct. I get the invalid argument error all the time. My code is attached. simPrototypeLinux00.tar.gz

@arturoc Ah, I see. Thanks. I'm new to network coding. How would you suggest I limit the sending?

Edit: I think I have a lead on how to do it. Actually, maybe I could use a timer? Thank you both.

bakercp commented 7 years ago

No timer needed. One really easy way would be to just send messages once.

e.g.

    if(network.HasSocket() && !sendMessage.empty()){
        network.Send(sendMessage.c_str(), sendMessage.length());
        sendMessage.clear();
    }

then when your your mousePressed / mouseReleased update the sendMessage with the number, it will no longer be empty and will be sent once on the next update loop.

toliaferrode commented 7 years ago

@bakercp Yes, indeed. Thanks for checking my code. I built this from the UDP sender and receiver example. While that works for this use case, in other cases I need to keep an up to date recording of positional data of of3DPrimitives, and other data. That's why I have it in update().

toliaferrode commented 7 years ago

@bakercp @arturoc Oh, I just thought of something. When I test on desktop and Raspberry Pi I don't get any errors I'm pretty sure.

Edit:

Confirmed! I just ran the application on the Pi and on desktop (which is suddenly very slow for some reason, but it still sends and receives data) and I get no errors on the Pi whatsoever. The Raspberry Pi is the server and my laptop is the client in this testing case.

However, when the client is Android and the server is the Raspberry Pi, I get these errors. Odd, huh? Seems to be something going on on the Android side, maybe? Maybe sending some added stuff that it's not supposed to? I know Android support is experimental.