I know this is a somewhat old question, but I had to overcome it recently and did not find a good answer on the Internet. The model used by oscpack seems to be that they drive an infinite Run loop, and you implement everything you want to do inside the class derived from the OscPacketListener. If you do not want to do this, you need to run the Run loop in a separate thread. There seems to be no more internal support for streaming processing in oscpack version 1.1.0. They explain in the CHANGES file for this version that you will need to implement your own streaming solution. The Run procedure in SocketReceiveMultiplexer never returns, so any code after this call is not available. Various Break routines are used to control the execution of a Run loop from another thread. In the example below, I am using C ++ 11 <threads> , but you can use any thread library that you choose to achieve something similar. In my example you need
#include <threads> #include <mutex>
and compile your code using the C ++ 11 compiler. In g ++, you will need the command line argument -std=c++11 .
If you start with an example receiver (parsing one example message) in SVN, you can change main() to be something like
void ListnerThread() { PacketListener listener; UdpListeningReceiveSocket s( IpEndpointName( IpEndpointName::ANY_ADDRESS, PORT ), &listener ); s.Run(); }
Somewhere else in your code make a call like
std::thread lt(ListnerThread);
to start the listener. You will need to create some ways of exchanging information between your main stream and the listener stream. One simple method is to use a global variable surrounded by a mutex (also global). Of course, there are other (better?) Ways, but it is very easy. Declare them globally (following their example) instead of the ProcessMessage function:
std::mutex oscMutex; bool a1; osc::int32 a2; float a3; const char *a4;
Inside ExamplePacketListener , where they set the variables from the args stream and then make a cout call, you do something like
oscMutex.lock(); args >> a1 >> a2 >> a3 >> a4 >> osc::EndMessage; oscMutex.unlock();
Just remember to also lock() and unlock() mutex in the same way, wherever you are in these variables elsewhere in your code.