Guest User

Untitled

a guest
Nov 18th, 2017
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.82 KB | None | 0 0
  1. import netP5.*;
  2. import oscP5.*;
  3.  
  4. OscP5 oscP5;
  5. NetAddress TargetLocation;
  6. NetAddressList clientList = new NetAddressList();
  7.  
  8. int listenPort = 15679;
  9. int broadcastPort = 44000;
  10.  
  11. String myConnectPattern = "/server/connect";
  12. String myDisconnectPattern = "/server/disconnect";
  13.  
  14. void setup()
  15. {
  16. size(400,400);
  17. background(0);
  18. fill(255);
  19. oscP5 = new OscP5(this, listenPort);
  20. }
  21.  
  22. void draw()
  23. {
  24.  
  25.  
  26. }
  27.  
  28. void oscEvent(OscMessage theOscMessage)
  29. {
  30.  
  31. println("receive pattern:"+theOscMessage.addrPattern()+" ,typetag:"+theOscMessage.typetag());
  32. println("message 1:" +theOscMessage.arguments()[0]);
  33. println("message 2:" +theOscMessage.arguments()[1]);
  34.  
  35. if (theOscMessage.addrPattern().equals(myConnectPattern)) {
  36. connect(theOscMessage.netAddress().address());
  37. }
  38. else if (theOscMessage.addrPattern().equals(myDisconnectPattern)) {
  39. disconnect(theOscMessage.netAddress().address());
  40. }
  41. /**
  42. * if pattern matching was not successful, then broadcast the incoming
  43. * message to all addresses in the netAddresList.
  44. */
  45. else {
  46. oscP5.send(theOscMessage, clientList);
  47. println(theOscMessage.addrPattern());
  48. }
  49. }
  50.  
  51.  
  52. private void connect(String theIPaddress) {
  53. if (!clientList.contains(theIPaddress, broadcastPort)) {
  54. clientList.add(new NetAddress(theIPaddress, broadcastPort));
  55. println("### adding "+theIPaddress+" to the list.");
  56. } else {
  57. println("### "+theIPaddress+" is already connected.");
  58. }
  59. println("### currently there are " + clientList.list().size()+" remote locations connected.");
  60. }
  61.  
  62.  
  63. private void disconnect(String theIPaddress) {
  64. if (clientList.contains(theIPaddress, broadcastPort)) {
  65. clientList.remove(theIPaddress, broadcastPort);
  66. println("### removing "+theIPaddress+" from the list.");
  67. }
  68. println("### currently there are " + clientList.list().size());
  69. }
Add Comment
Please, Sign In to add comment