-
Notifications
You must be signed in to change notification settings - Fork 5
/
lights_websocket.py
53 lines (37 loc) · 1.16 KB
/
lights_websocket.py
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
from ws4py.client.threadedclient import WebSocketClient
import sys
from simpleOSC import initOSCServer, startOSCServer, closeOSC, setOSCHandler
ip = "127.0.0.1"
port = 9435
class DummyClient(WebSocketClient):
def opened(self):
def data_provider():
for i in range(1, 200, 25):
yield "#" * i
self.send(data_provider())
# for i in range(0, 10):
# print i
self.send("010101")
def closed(self, code, reason=None):
print "Closed down", code, reason
def received_message(self, m):
print m
if len(m) == 175:
self.close(reason='Bye bye')
def bkgrnd(addr, tags, data, source):
print "got collision"
print data[0]
ws.send("010101");
if __name__ == '__main__':
# try:
try:
initOSCServer(ip, port)
setOSCHandler('/background', bkgrnd)
startOSCServer()
print "server is running, listening at " + str(ip) + ":" + str(port)
ws = DummyClient('ws://localhost:9000/', protocols=['nlcp'])
ws.connect()
ws.run_forever()
except KeyboardInterrupt:
ws.close()
closeOSC()