Created
April 12, 2019 05:42
-
-
Save mangtronix/dfab6fa90f33998b42b0997f812e8823 to your computer and use it in GitHub Desktop.
Example of using OSC multicast with Processing / oscP5
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* oscP5multicast by andreas schlegel | |
* example shows how to send osc via a multicast socket. | |
* what is a multicast? http://en.wikipedia.org/wiki/Multicast | |
* ip multicast ranges and uses: | |
* 224.0.0.0 - 224.0.0.255 Reserved for special Òwell-knownÓ multicast addresses. | |
* 224.0.1.0 - 238.255.255.255 Globally-scoped (Internet-wide) multicast addresses. | |
* 239.0.0.0 - 239.255.255.255 Administratively-scoped (local) multicast addresses. | |
* oscP5 website at http://www.sojamo.de/oscP5 | |
* | |
* updated by mangtronix | |
* - explicitly set IPv4 | |
* - send mouse X and Y | |
*/ | |
import oscP5.*; | |
import netP5.*; | |
OscP5 oscP5; | |
void setup() { | |
size(400,400); | |
frameRate(25); | |
/* create a new instance of oscP5 using a multicast socket. */ | |
System.setProperty("java.net.preferIPv4Stack", "true"); | |
oscP5 = new OscP5(this, "239.0.0.1", 8888, OscP5.UDP | OscP5.MULTICAST); | |
} | |
void draw() { | |
background(0); | |
} | |
void mousePressed() { | |
/* create a new OscMessage with an address pattern, in this case /test. */ | |
OscMessage myOscMessage = new OscMessage("/test"); | |
/* add a value (an integer) to the OscMessage */ | |
myOscMessage.add(100); | |
/* send the OscMessage to the multicast group. | |
* the multicast group netAddress is the default netAddress, therefore | |
* you dont need to specify a NetAddress to send the osc message. | |
*/ | |
oscP5.send(myOscMessage); | |
} | |
/* incoming osc message are forwarded to the oscEvent method. */ | |
void oscEvent(OscMessage theOscMessage) { | |
/* print the address pattern and the typetag of the received OscMessage */ | |
print("### received an osc message."); | |
print(" addrpattern: "+theOscMessage.addrPattern()); | |
println(" typetag: "+theOscMessage.typetag()); | |
theOscMessage.print(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment