Receiving UDP

I am trying to write apps which communicate to each other via UDP or TCP.

In Qt, for example, you create a QUdpSocket *recv_socket and then bind it and connect it’s readyRead signal to the void readPendingDatagrams(); slot. Then, it responds to UDP messages as they arrive, but doesn’t block.

In Juce, with Midi, you inherit from MidiInputCallback and override handleIncomingMidiMessage. I’d like something similar for UDP messages.

How do I do this in Juce? Or is there a generic C/C++ way of doing it?

You could see if the juce_osc::juce_OSCSender/Receiver class will do what you need it to, with a UDP-based connection … otherwise, it’ll be a matter of finding a cross-platform network library and integrating it into your project …

The support for networking is quite limited in JUCE. There is DatagramSocket but this is only a thin wrapper around the system provided socket. In order to receive something async you would need to read from it manually and find out if any data is available from a background thread.

For C++ the most obvious library to use is ASIO, either through the standalone version or the one included in boost.

Other interesting libraries might be POCO, or have a look at an extensive list on Stack Overflow.