# Possible timing issues with OSC

**URL:** <https://discourse.processing.org/t/possible-timing-issues-with-osc/46523>\
**Category:** Libraries\
**Created:** [June 10, 2025, 9:47pm UTC](https://discourse.processing.org/t/possible-timing-issues-with-osc/46523 "2025-06-10T21:47:24Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![dom](https://avatars.discourse-cdn.com/v4/letter/d/aeb1de/32.png) [@dom](https://discourse.processing.org/u/dom)\
**Post date:** [June 10, 2025, 9:47pm UTC](https://discourse.processing.org/t/possible-timing-issues-with-osc/46523/1 "2025-06-10T21:47:24Z")

</div>

I am sending OSC messages from Supercollider to Processing. I want to use the OSC messages to populate two arrays storing x and y coordinates for certain shapes. My idea was to send three messages: an index, an x position, and a y position. The index would indicated where to populate the x and y in the array.

My ideas was to use global variables (x,y,index) that the OSC message would change. I can, however, see a flaw with this idea. If two OSC messages are sent at the same time it could cause a conflict. In addition, something feels wrong about my whole approach. I’m not sure if using global variables is the correct approach.

Does anyone have insight or experience into this? Thank you in advance for any help!

---

<div class="post-metadata">

**Author:** ![Max\_Normal](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/max_normal/32/20757_2.png) [@Max\_Normal](https://discourse.processing.org/u/Max_Normal)\
**Post date:** [June 14, 2025, 8:27am UTC](https://discourse.processing.org/t/possible-timing-issues-with-osc/46523/2 "2025-06-14T08:27:39Z")

</div>

I’ll preface this by saying that I know nothing about OSC.

The three messages idea seems bad – is there any guarantee that the messages will arrive in the same order as they were dispatched (does your code handle this possibility?).

Could you pack the index, x and y into a single (32 bit?) integer so as to deal with everything in one message? If the index, x and y ranges can’t be represented as fields that fit into an integer frame then format the message as a BLOB and deliver all of the data in one block.

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [June 14, 2025, 2:41pm UTC](https://discourse.processing.org/t/possible-timing-issues-with-osc/46523/3 "2025-06-14T14:41:36Z")

</div>

Hello @dom,

ChatGPT SuperCollider code I used:

```auto
(
// Setup OSC target and vars
~target = NetAddr("127.0.0.1", 12000); // Your Processing port
~index = 0;
~toggle = 0;

~sendRandomData = {
    var x = rrand(0.0, 1.0);
    var y = rrand(0.0, 1.0);
    ~target.sendMsg("/data", x, y, ~index, ~toggle);
    ("Sent: x=%, y=%, index=%, toggle=% at %").format(x, y, ~index, ~toggle, thisThread.clock.seconds).postln;

    ~index = ~index + 1;
    ~toggle = 1 - ~toggle;
};

// Define a fresh sender task but DO NOT start it yet
~sender = Task({
    loop {
        ~sendRandomData.();
        2.0.wait;
    }
});
)

```

I used the _oscP5broadcastClient_ example to receive the data.

You should be able to receive the data and populate different arrays according to the msg number (toggle in this case).

ChatGPT Processing _oscEvent()_ used with minimal example:

```auto
void oscEvent(OscMessage msg) {
  if (msg.checkAddrPattern("/data")) {
    if (msg.checkTypetag("ffii")) { // expecting 2 floats, 2 ints
      float x = msg.get(0).floatValue();
      float y = msg.get(1).floatValue();
      int index = msg.get(2).intValue();
      int toggle = msg.get(3).intValue();
      println("Received: x=" + x + ", y=" + y + ", index=" + index + ", toggle=" + toggle);
    } else {
      println("Unexpected typetag: " + msg.typetag());
    }
  }
}

```

> [@dom](#):
>
> If two OSC messages are sent at the same time it could cause a conflict.

You can process each one as it is received; I just added the toggle as an example of two different data sets.

I have very little knowledge of either of OSC so this was just a quick exploration.

Cool beans! I may use this in future!

`:)`
