ofxOscSender vector


I need to create a vector of ofxOscSender in order to send messages to multiples machines.

This doesn’t even compile and don’t understand whats wrong, and how can i create multiple instances of a ofxOscSender.

any help will be welcome

vector<ofxOscSender> senders;

    void ofApp::setup(){
        ofxOscSender sedner;
        ofxOscSender sedner2;
        ofxOscSender sedner3;
        sedner.setup("", 12344);
        sedner2.setup("", 12344);
        sedner3.setup("", 12344);

Use pointers:


// vector containing pointers
vector<ofxOscSender *> senders;

// pointers to osc senders
ofxOscSender * sender1;
ofxOscSender * sender2;
ofxOscSender * sender3;

in ofApp.cpp:

void ofApp::setup(){
    // construct pointers
    sender1 = new ofxOscSender;
    sender2 = new ofxOscSender;
    sender3 = new ofxOscSender;
    // setup
    sender1->setup("", 12344);
    sender2->setup("", 12344);
    sender3->setup("", 12344);
    // store in vector

You don’t need to put them in a vector though. If you know you are just going to use 3 senders, you can construct objects or pointers to objects of type ofxOscSender and use them directly, differentiating by name. This way you can just use

sender1->sendMessage(ofxOscMessage &message);

with the vector of pointers, you’d use, where ‘i’ is your sender number (less clear):

senders[i]->sendMessage(ofxOscMessage &message);

Thanks Vjacobs !!

I was using a vector because i have a class “player” which contains an ofxOscSender and not all the times i know the amount of players, but can go this way if i don’t get multicast working

As i read later seems like i can use only one sender and broadcast the message to all the clients, but i don’t understand how to use multicast ip address, i have to read more… If im using an ip range ( for my computers which will be their multicast address??

Seems like kyle its using multicast osc in this https://github.com/kylemcdonald/DohaInstallation/tree/master/addons/ofxOsc


broadcast and multicast are 2 different things. Broadcast means sending from one sender to all clients physically attached to the same network using a broadcast address. You can compute this address doing a binary or on subnet mask and ip-address.
Multicast means sending from one sender to a specially reserved multicast address. Clients only receive if they choose to ‘sign in to the group’.

Check this thread for more info about broadcasting using ofxOsc.
Also, the ofxNetwork addon has functions for broadcasting and multicast using UDP.

And did you really try creating three different OSC servers with different addresses and checking if you receive what they send?

Best, V

Thanks for the explain. I will read the links

And did you really try creating three different OSC servers with different addresses and checking if you receive what they send?

I don’t explain me right, sorry. Your code using pointer works, i previously tried using pointers but forget to initialize so it was not working (embarrassed mistake) your code points me in the right direction :slight_smile: right now im using a vector of pointers and it works ok.

I have a main server (osx) and 4 arduinos using arduOsc in this project.

But its just curiosity to see how the broadcast approach will be