(r"/a/get-all-animations", GetAllAnimationsHandler), ] + SocketIORouter.urls, **settings) if __name__ == "__main__": import sys try: print "trying to connect via port 80" application.listen(80) except: print "... failed. Backing up to 8888" application.listen(8888) # http_server = tornado.httpserver.HTTPServer(application) # http_server.listen(8888) # http_server.bind(8888) # http_server.start(2) # Forks multiple sub-processes ioloopy = tornado.ioloop.IOLoop.instance() DL_COMMUNICATOR.connect('127.0.0.1', 2323) ioloopy.add_handler(DL_COMMUNICATOR.receive_socket.fileno(), notify_clients_on_panel_change, ioloopy.READ | ioloopy.ERROR) # Send one empty frame. This defines the panel so that other components # get frame information and can start running packet = DL_COMMUNICATOR.encode_partial_frame(0, 0, [0, 0, 0]) DL_COMMUNICATOR.send(packet) ioloopy.start()
vars = {'frame_duration': 0.5, 'frame_counter': 0} # will be updated by the visualization algorithms visualization, vars = select_random_visualization() while not done: # get any incoming data from the DL server headers, payload = dlc.check_for_data() # panel is up, but there is nothing happening if not payload and dlc.panel_width: now = time.time() if now - last_packet_received > idle_time: frame, alive, vars = visualization(dlc.panel_width, dlc.panel_height, vars) last_frame = frame dlc.send(dlc.encode_full_frame(frame)) vars['frame_counter'] += 1 # new random visualization if not alive: visualization, vars = select_random_visualization() # it seems the panel is playing something elif payload: s = sum(payload) if last_frame: ss = sum(last_frame) else: ss = -1 # quick checksum to see if the frame changed or was blank if s == ss or s == 0: