blob: 1cbd638e7c8d8e7458659f5bd7bc5bd4b97f5bc0 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
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());
}
|