Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import netP5.*;
- import oscP5.*;
- OscP5 oscP5;
- NetAddress TargetLocation;
- NetAddressList clientList = new NetAddressList();
- int listenPort = 15679;
- int broadcastPort = 44000;
- String myConnectPattern = "/server/connect";
- String myDisconnectPattern = "/server/disconnect";
- void setup()
- {
- size(400,400);
- background(0);
- fill(255);
- oscP5 = new OscP5(this, listenPort);
- }
- void draw()
- {
- }
- void oscEvent(OscMessage theOscMessage)
- {
- println("receive pattern:"+theOscMessage.addrPattern()+" ,typetag:"+theOscMessage.typetag());
- println("message 1:" +theOscMessage.arguments()[0]);
- println("message 2:" +theOscMessage.arguments()[1]);
- 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, clientList);
- println(theOscMessage.addrPattern());
- }
- }
- private void connect(String theIPaddress) {
- if (!clientList.contains(theIPaddress, broadcastPort)) {
- clientList.add(new NetAddress(theIPaddress, broadcastPort));
- println("### adding "+theIPaddress+" to the list.");
- } else {
- println("### "+theIPaddress+" is already connected.");
- }
- println("### currently there are " + clientList.list().size()+" remote locations connected.");
- }
- private void disconnect(String theIPaddress) {
- if (clientList.contains(theIPaddress, broadcastPort)) {
- clientList.remove(theIPaddress, broadcastPort);
- println("### removing "+theIPaddress+" from the list.");
- }
- println("### currently there are " + clientList.list().size());
- }
Add Comment
Please, Sign In to add comment