Mercurial > code > home > repos > light9
annotate light8/ExternalInput.py @ 90:d34a4956417a
rsn has a separate thread that receives rlslider connections from a potserver.py process,
rsn has a separate thread that receives rlslider connections from a potserver.py process,
and they work
author | drewp |
---|---|
date | Sat, 13 Jul 2002 02:57:27 +0000 |
parents | 0969d8a6729d |
children | d6c48d2d3bd6 |
rev | line source |
---|---|
90
d34a4956417a
rsn has a separate thread that receives rlslider connections from a potserver.py process,
drewp
parents:
78
diff
changeset
|
1 import thread, SocketServer, socket |
d34a4956417a
rsn has a separate thread that receives rlslider connections from a potserver.py process,
drewp
parents:
78
diff
changeset
|
2 |
d34a4956417a
rsn has a separate thread that receives rlslider connections from a potserver.py process,
drewp
parents:
78
diff
changeset
|
3 |
d34a4956417a
rsn has a separate thread that receives rlslider connections from a potserver.py process,
drewp
parents:
78
diff
changeset
|
4 currentlevels = [0,0,0,0] |
d34a4956417a
rsn has a separate thread that receives rlslider connections from a potserver.py process,
drewp
parents:
78
diff
changeset
|
5 |
0 | 6 |
7 class NetSliderHandler(SocketServer.StreamRequestHandler): | |
8 def handle(self): | |
9 data = self.rfile.readline(1000) | |
90
d34a4956417a
rsn has a separate thread that receives rlslider connections from a potserver.py process,
drewp
parents:
78
diff
changeset
|
10 currentlevels[:] = [float(x)/255 for x in list(data.split())] |
0 | 11 |
90
d34a4956417a
rsn has a separate thread that receives rlslider connections from a potserver.py process,
drewp
parents:
78
diff
changeset
|
12 def start_server(levelstorage=0): |
0 | 13 server = SocketServer.TCPServer( |
14 ('', socket.getservbyname('rlslider', 'tcp')), | |
15 NetSliderHandler) | |
16 server.serve_forever() | |
17 | |
18 class ExternalSliders: | |
19 def __init__(self, level_storage=[]): | |
20 self.level_storage = level_storage | |
21 self.spawn_server() | |
22 def test(self): | |
23 'Store fake inputs to test operations' | |
24 pass | |
25 def spawn_server(self): | |
26 pass | |
27 # thread.start_new_thread(start_server, (self.update)) | |
28 def update(self, *args): | |
29 self.level_storage[:] = args | |
30 def get_levels(self): | |
90
d34a4956417a
rsn has a separate thread that receives rlslider connections from a potserver.py process,
drewp
parents:
78
diff
changeset
|
31 return currentlevels |
d34a4956417a
rsn has a separate thread that receives rlslider connections from a potserver.py process,
drewp
parents:
78
diff
changeset
|
32 # import math, time |
d34a4956417a
rsn has a separate thread that receives rlslider connections from a potserver.py process,
drewp
parents:
78
diff
changeset
|
33 # return [max(0, math.sin(time.time() + i)) for i in range(4)] # bogus |
0 | 34 |
35 # return self.level_storage |