from flask import Flask, jsonify, request from helpers import (make_random_name, make_context, make_address, make_control_str, InvalidUsage) import threading import json import zmq app = Flask(__name__) app.config.from_object('settings') # TODO: context and sockets are never closed. Need to determine the best place # TODO: these should actually be initialized on a per-request basis. question # is whether the context can be shared. context = make_context() lobby_sock = context.socket(zmq.REQ) lobby_sock.connect( make_address(app.config.get('SPACERACE_SERVER'), app.config.get('SPACERACE_LOBBY_PORT'))) control_sock = context.socket(zmq.PUSH) control_sock.connect( make_address(app.config.get('SPACERACE_SERVER'), app.config.get('SPACERACE_CONTROL_PORT'))) state_sock = context.socket(zmq.SUB) state_sock.setsockopt_string(zmq.SUBSCRIBE, '') state_sock.connect( make_address(app.config.get('SPACERACE_SERVER'), app.config.get('SPACERACE_STATE_PORT')))
from flask.ext.cors import CORS from pprint import pformat import threading import json import zmq app = Flask(__name__) CORS(app) app.config.from_object('settings') # TODO: context and sockets are never closed. Need to determine the best place # TODO: these should actually be initialized on a per-request basis. question # is whether the context can be shared. context = make_context() lobby_sock = context.socket(zmq.REQ) addr = make_address(app.config.get('SPACERACE_SERVER'), app.config.get('SPACERACE_LOBBY_PORT')) app.logger.info('Connecting to lobby "{}"...'.format(addr)) lobby_sock.connect(addr) control_sock = context.socket(zmq.PUSH) addr = make_address(app.config.get('SPACERACE_SERVER'), app.config.get('SPACERACE_CONTROL_PORT')) app.logger.info('Connecting to control "{}"...'.format(addr)) control_sock.connect(addr) state_sock = context.socket(zmq.SUB) state_sock.setsockopt_string(zmq.SUBSCRIBE, '')