diff options
Diffstat (limited to 'libraries/oscP5/examples/oscP5broadcaster')
-rw-r--r-- | libraries/oscP5/examples/oscP5broadcaster/oscP5broadcaster.pde | 73 |
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()); + } |