Mercurial > hg > beaglert
comparison resources/osc/node_modules/osc-min/examples/oscbundle_heartbeat.coffee @ 271:fb9c28a4676b prerelease
Added osc example project and node script for testing
author | Liam Donovan <l.b.donovan@qmul.ac.uk> |
---|---|
date | Tue, 17 May 2016 16:01:06 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
270:de37582ce6f3 | 271:fb9c28a4676b |
---|---|
1 # Same thing as the oscheartbeat example but with oscbundles. | |
2 | |
3 osc = require 'osc-min' | |
4 dgram = require "dgram" | |
5 | |
6 udp = dgram.createSocket "udp4" | |
7 | |
8 if process.argv[2]? | |
9 outport = parseInt process.argv[2] | |
10 else | |
11 outport = 41234 | |
12 | |
13 # Get the unix timestamp in seconds | |
14 now = -> (new Date()).getTime() / 1000; | |
15 | |
16 sendHeartbeat = () -> | |
17 buf = osc.toBuffer( | |
18 timetag : now() + 0.05 # 0.05 seconds from now | |
19 elements : [ | |
20 { | |
21 address : "/p1" | |
22 args : new Buffer "beat" | |
23 } | |
24 { | |
25 address : "/p2" | |
26 args : "string" | |
27 } | |
28 { | |
29 timetag: now() + 1 # 1 second from now | |
30 elements : [ | |
31 { | |
32 address : "/p3" | |
33 args : 12 | |
34 } | |
35 ] | |
36 } | |
37 ] | |
38 ) | |
39 | |
40 udp.send buf, 0, buf.length, outport, "localhost" | |
41 | |
42 setInterval sendHeartbeat, 2000 | |
43 | |
44 console.log "sending heartbeat messages to http://localhost:" + outport |