From 589e6c881bd2cf11e8615e9c1bf8cb4012293bad Mon Sep 17 00:00:00 2001 From: David Runge Date: Thu, 31 Dec 2015 03:34:08 +0100 Subject: libraries/oscP5: Adding oscP5 library for OSC capabilities. --- .../examples/oscP5broadcaster/oscP5broadcaster.pde | 73 ++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 libraries/oscP5/examples/oscP5broadcaster/oscP5broadcaster.pde (limited to 'libraries/oscP5/examples/oscP5broadcaster') 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()); + } -- cgit v1.2.3-54-g00ecf