diff options
author | David Runge <dave@sleepmap.de> | 2015-12-31 03:34:08 +0100 |
---|---|---|
committer | David Runge <dave@sleepmap.de> | 2015-12-31 03:34:08 +0100 |
commit | 589e6c881bd2cf11e8615e9c1bf8cb4012293bad (patch) | |
tree | 407d617ed861a61d64e64f7d581052f90b10e981 /libraries/oscP5/examples/oscP5tcp | |
parent | 6a713ba6966eee4cf7bb9fb9e1513918fc94b528 (diff) | |
download | processing-sketchbook-589e6c881bd2cf11e8615e9c1bf8cb4012293bad.tar.gz processing-sketchbook-589e6c881bd2cf11e8615e9c1bf8cb4012293bad.tar.bz2 processing-sketchbook-589e6c881bd2cf11e8615e9c1bf8cb4012293bad.tar.xz processing-sketchbook-589e6c881bd2cf11e8615e9c1bf8cb4012293bad.zip |
libraries/oscP5: Adding oscP5 library for OSC capabilities.
Diffstat (limited to 'libraries/oscP5/examples/oscP5tcp')
-rw-r--r-- | libraries/oscP5/examples/oscP5tcp/oscP5tcp.pde | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/libraries/oscP5/examples/oscP5tcp/oscP5tcp.pde b/libraries/oscP5/examples/oscP5tcp/oscP5tcp.pde new file mode 100644 index 0000000..90ee312 --- /dev/null +++ b/libraries/oscP5/examples/oscP5tcp/oscP5tcp.pde @@ -0,0 +1,59 @@ +/** + * oscP5tcp by andreas schlegel + * example shows how to use the TCP protocol with oscP5. + * what is TCP? http://en.wikipedia.org/wiki/Transmission_Control_Protocol + * in this example both, a server and a client are used. typically + * this doesnt make sense as you usually wouldnt communicate with yourself + * over a network. therefore this example is only to make it easier to + * explain the concept of using tcp with oscP5. + * oscP5 website at http://www.sojamo.de/oscP5 + */ + +import oscP5.*; +import netP5.*; + + +OscP5 oscP5tcpServer; + +OscP5 oscP5tcpClient; + +NetAddress myServerAddress; + +void setup() { + /* create an oscP5 instance using TCP listening @ port 11000 */ + oscP5tcpServer = new OscP5(this, 11000, OscP5.TCP); + + /* create an oscP5 instance using TCP. + * the remote address is 127.0.0.1 @ port 11000 = the server from above + */ + oscP5tcpClient = new OscP5(this, "127.0.0.1", 11000, OscP5.TCP); +} + + +void draw() { + background(0); +} + + +void mousePressed() { + /* the tcp client sends a message to the server it is connected to.*/ + oscP5tcpClient.send("/test", new Object[] {new Integer(1)}); +} + + +void keyPressed() { + /* check how many clients are connected to the server. */ + println(oscP5tcpServer.tcpServer().getClients().length); +} + +void oscEvent(OscMessage theMessage) { + /* in this example, both the server and the client share this oscEvent method */ + System.out.println("### got a message " + theMessage); + if(theMessage.checkAddrPattern("/test")) { + /* message was send from the tcp client */ + OscMessage m = new OscMessage("/response"); + m.add("server response: got it"); + /* server responds to the client's message */ + oscP5tcpServer.send(m,theMessage.tcpConnection()); + } +} |