Skip to content

Instantly share code, notes, and snippets.

@theepicsnail
Created March 18, 2011 00:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save theepicsnail/875412 to your computer and use it in GitHub Desktop.
Save theepicsnail/875412 to your computer and use it in GitHub Desktop.
Server
import socket,threading
from time import sleep
port = 1235
class DMX(threading.Thread):
running = True
life = [0,0,0,0,0,0]
def activate(self,num):
if num < 0 or num > 5:
return
self.life[num]=10
def run(self):
while self.running:
sleep(.5)
self.lightsOn()
sleep(.5)
self.lightsOff()
self.decrement()
def lightsOn(self):
for num,val in enumerate(self.life):
if val:
print "Send %i on"%num
def lightsOff(self):
for num,val in enumerate(self.life):
if val:
print "Send %i off"%num
def decrement(self):
for num,val in enumerate(self.life):
if val:
self.life[num]-=1
if self.life[num]==0:
print "Send %i default"%num
def run():
dmx = DMX()
dmx.start()
ss = socket.socket()
ss.bind(('',1235))
ss.listen(1)
while True:
try:
s,addr = ss.accept()
data = s.recv(1234)
if data == "stop":
break
parts = data.strip().split()
if parts[0]=="activate":
dmx.activate(int(parts[1]))
s.close()
except: pass #any errors fail silently
dmx.running=False
ss.close()
run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment