summaryrefslogtreecommitdiffstats
path: root/libraries/oscP5/examples/oscP5broadcaster
diff options
context:
space:
mode:
authorDavid Runge <dave@sleepmap.de>2015-12-31 03:34:08 +0100
committerDavid Runge <dave@sleepmap.de>2015-12-31 03:34:08 +0100
commit589e6c881bd2cf11e8615e9c1bf8cb4012293bad (patch)
tree407d617ed861a61d64e64f7d581052f90b10e981 /libraries/oscP5/examples/oscP5broadcaster
parent6a713ba6966eee4cf7bb9fb9e1513918fc94b528 (diff)
downloadprocessing-sketchbook-589e6c881bd2cf11e8615e9c1bf8cb4012293bad.tar.gz
processing-sketchbook-589e6c881bd2cf11e8615e9c1bf8cb4012293bad.tar.bz2
processing-sketchbook-589e6c881bd2cf11e8615e9c1bf8cb4012293bad.tar.xz
processing-sketchbook-589e6c881bd2cf11e8615e9c1bf8cb4012293bad.zip
libraries/oscP5: Adding oscP5 library for OSC capabilities.
Diffstat (limited to 'libraries/oscP5/examples/oscP5broadcaster')
-rw-r--r--libraries/oscP5/examples/oscP5broadcaster/oscP5broadcaster.pde73
1 files changed, 73 insertions, 0 deletions
diff --git a/libraries/oscP5/examples/oscP5broadcaster/oscP5broadcaster.pde b/libraries/oscP5/examples/oscP5broadcaster/oscP5broadcaster.pde
new file mode 100644
index 0000000..1cbd638
--- /dev/null
+++ b/libraries/oscP5/examples/oscP5broadcaster/oscP5broadcaster.pde
@@ -0,0 +1,73 @@
+/**
+ * oscP5broadcaster by andreas schlegel
+ * an osc broadcast server.
+ * osc clients can connect to the server by sending a connect and
+ * disconnect osc message as defined below to the server.
+ * incoming messages at the server will then be broadcasted to
+ * all connected clients.
+ * an example for a client is located in the oscP5broadcastClient exmaple.
+ * oscP5 website at http://www.sojamo.de/oscP5
+ */
+
+import oscP5.*;
+import netP5.*;
+
+OscP5 oscP5;
+NetAddressList myNetAddressList = new NetAddressList();
+/* listeningPort is the port the server is listening for incoming messages */
+int myListeningPort = 32000;
+/* the broadcast port is the port the clients should listen for incoming messages from the server*/
+int myBroadcastPort = 12000;
+
+String myConnectPattern = "/server/connect";
+String myDisconnectPattern = "/server/disconnect";
+
+
+void setup() {
+ oscP5 = new OscP5(this, myListeningPort);
+ frameRate(25);
+}
+
+void draw() {
+ background(0);
+}
+
+void oscEvent(OscMessage theOscMessage) {
+ /* check if the address pattern fits any of our patterns */
+ if (theOscMessage.addrPattern().equals(myConnectPattern)) {
+ connect(theOscMessage.netAddress().address());
+ }
+ else if (theOscMessage.addrPattern().equals(myDisconnectPattern)) {
+ disconnect(theOscMessage.netAddress().address());
+ }
+ /**
+ * if pattern matching was not successful, then broadcast the incoming
+ * message to all addresses in the netAddresList.
+ */
+ else {
+ oscP5.send(theOscMessage, myNetAddressList);
+ }
+}
+
+
+ private void connect(String theIPaddress) {
+ if (!myNetAddressList.contains(theIPaddress, myBroadcastPort)) {
+ myNetAddressList.add(new NetAddress(theIPaddress, myBroadcastPort));
+ println("### adding "+theIPaddress+" to the list.");
+ } else {
+ println("### "+theIPaddress+" is already connected.");
+ }
+ println("### currently there are "+myNetAddressList.list().size()+" remote locations connected.");
+ }
+
+
+
+private void disconnect(String theIPaddress) {
+if (myNetAddressList.contains(theIPaddress, myBroadcastPort)) {
+ myNetAddressList.remove(theIPaddress, myBroadcastPort);
+ println("### removing "+theIPaddress+" from the list.");
+ } else {
+ println("### "+theIPaddress+" is not connected.");
+ }
+ println("### currently there are "+myNetAddressList.list().size());
+ }