Esempio n. 1
0
 def setup_zmq(self):
     zmq_factory = ZmqFactory()
     print("subscribing on: %s" % self.endpoint)
     sub_endpoint = ZmqEndpoint(ZmqEndpointType.connect, self.endpoint)
     sub_connection = ZmqSubConnection(zmq_factory, sub_endpoint)
     sub_connection.gotMessage = self.zmq_message
     sub_connection.subscribe(INVOICE_PAYMENT_TAG)
Esempio n. 2
0
 def _load_setup(self, setup):
     for e, notification_type_names in setup.items():
         endpoint = ZmqEndpoint(ZmqEndpointType.connect, e)
         connection = ZmqSubConnection(self.factory, endpoint)
         for n in notification_type_names:
             tag = n.encode("utf8")
             connection.gotMessage = self._log_message
             connection.subscribe(tag)
Esempio n. 3
0
    def __init__(self):
        self.queue = Queue()

        self.zmq_factory = ZmqFactory()
        endpoint = ZmqEndpoint(ZmqEndpointType.connect, ZMQ_ENDPOINT)
        connection = ZmqSubConnection(self.zmq_factory, endpoint)
        connection.gotMessage = self.set_mode
        connection.subscribe(ZMQ_TAG)
Esempio n. 4
0
 def startService(self):
     self._factory = ZmqFactory()
     endpoints = [
         ZmqEndpoint(ZmqEndpointType.connect, endpoint)
         for endpoint in self.endpoints
     ]
     log.msg("Configuring ZeroMQ subscription socket",
             logLevel=logging.DEBUG)
     for endpoint in endpoints:
         log.msg("Connecting to the {endpoint} ZeroMQ endpoint".format(
             endpoint=endpoint))
         s = ZmqSubConnection(self._factory, endpoint)
         s.subscribe(b"")
         s.gotMessage = self.on_message
     log.msg("ZeroMQ consumer is ready")
Esempio n. 5
0
    def setup_zmq(self):
        zmq_factory = ZmqFactory()
        print("subscribing on: %s" % self.endpoint)
        sub_endpoint = ZmqEndpoint(ZmqEndpointType.connect, self.endpoint)
        sub_connection = ZmqSubConnection(zmq_factory, sub_endpoint)
        sub_connection.gotMessage = self.zmq_message
        sub_connection.subscribe(FORWARD_EVENT_TAG)
        sub_connection.subscribe(HTLC_ACCEPTED_TAG)

        print("subscribing on: %s" % self.mock_endpoint)
        sub_mock_endpoint = ZmqEndpoint(ZmqEndpointType.connect,
                                        self.mock_endpoint)
        sub_mock_connection = ZmqSubConnection(zmq_factory, sub_mock_endpoint)
        sub_mock_connection.gotMessage = self.zmq_message
        sub_mock_connection.subscribe(FORWARD_EVENT_TAG)
        sub_mock_connection.subscribe(HTLC_ACCEPTED_TAG)
Esempio n. 6
0
    def __init__(self, reactor, screen_ui, audio_player, first_block_hash):
        f = ZmqFactory()
        f.reactor = reactor
        e = ZmqEndpoint("connect", "tcp://127.0.0.1:28332")
        s = ZmqSubConnection(f, e)
        s.subscribe("hashblock".encode("utf-8"))
        s.messageReceived = self.listener
        self.screen_ui = screen_ui
        self.new_block_queue = []
        self.queue_running = False
        self.audio_player = audio_player

        new_block = NewBlock(self, first_block_hash, self.screen_ui,
                             audio_player)
        self.new_block_queue.append(new_block)
        self._try_next()
Esempio n. 7
0
class VideoServer:
    def __init__(self, zmq_port):
        server_port = str(8001)
        self.resource = ImageResource()
        self.site = server.Site(self.resource)
        self.zmqFactory = ZmqFactory()
        self.zmqEndpoint = ZmqEndpoint('connect',
                                       'tcp://127.0.0.1:' + zmq_port)
        self.zmqSubscriber = ZmqSubConnection(self.zmqFactory,
                                              self.zmqEndpoint)
        self.zmqSubscriber.subscribe("")
        self.zmqSubscriber.gotMessage = self.resource.imageReceived
        self.resourceEndpoint = reactor.listenTCP(int(server_port), self.site)

    def disconnect(self):
        self.resourceEndpoint.stopListening()
        self.resource.cancelTimer()
Esempio n. 8
0
    def on_msg(self, callBack, time_out = None):
        """
            A messy callback handler for when a new message pops up.
            :param callBack: expected def callBack(stringMessage)
            :param time_out: TODO a timeout value in seconds
        """

        """
            This is a tad not production sane as its going to open a new ZMQ
            socket for every single message sent.  Its fine when it's just 1-2
            people chatting for a short-demo duration but a better approach might
            be to bind the client ZMQ socket to a HTTP session with a timeout.

            So say someone leaves, the HTTP session would timeout after some T duration
            and this socket would be cleaned up.  Additionally this would prevent
            some amount of thrash of instantiating and destroying sockets.
        """
        client = ZmqSubConnection(self.zf, self.client)
        client.subscribe("")
        self.clients.append(client)
        print len(self.clients), " waiting clients"

        def cleanup():
            """
                Our message is done, clean up!
            """
            c_index = self.clients.index(client)
            self.clients.pop(c_index)
            client.shutdown()


        def on_msg(*args, **kwargs):
            try:
                callBack("".join(args[:-1]))
            finally:
                cleanup()

        """
            Blink and you might miss it, this does the actual binding
            to the client socket.

            Initially I thought "Man this would be some much better using a deferred"
            EXCEPT what happens after that first deferred fires?
        """
        client.gotMessage = on_msg
Esempio n. 9
0
def main():
    parser = OptionParser("")
    parser.add_option("-m", "--method", dest="method",
                      help="0MQ socket connection: bind|connect")
    parser.add_option("-e", "--endpoint", dest="endpoint", help="0MQ Endpoint")
    parser.set_defaults(method="connect", endpoint="tcp://localhost:5555")

    (options, args) = parser.parse_args()

    zf = ZmqFactory()
    e = ZmqEndpoint(options.method, options.endpoint)

    s = ZmqSubConnection(zf, e)

    s.subscribe("")

    def doPrint(*args):
        print "message received: %r" % (args, )

    s.gotMessage = doPrint

    reactor.run()
Esempio n. 10
0
def main():
    parser = OptionParser("")
    parser.add_option("-m",
                      "--method",
                      dest="method",
                      help="0MQ socket connection: bind|connect")
    parser.add_option("-e", "--endpoint", dest="endpoint", help="0MQ Endpoint")
    parser.set_defaults(method="connect", endpoint="tcp://localhost:5555")

    (options, args) = parser.parse_args()

    zf = ZmqFactory()
    e = ZmqEndpoint(options.method, options.endpoint)

    s = ZmqSubConnection(zf, e)

    s.subscribe("")

    def doPrint(*args):
        print "message received: %r" % (args, )

    s.gotMessage = doPrint

    reactor.run()
Esempio n. 11
0
def main():
    global _CONFIG

    with open('config.yml') as f:
        _CONFIG = yaml.load(f.read())

    log.startLogging(sys.stderr)

    ircf = IrcFactory()
    reactor.connectTCP(_CONFIG['host'], _CONFIG['port'], ircf)

    zf = ZmqFactory()
    e = ZmqEndpoint(_CONFIG['method'], _CONFIG['endpoint'])

    s = ZmqSubConnection(zf, e)
    s.subscribe("")

    def do_forward(*args):
        if _IRC_PROTOCOL:
            _IRC_PROTOCOL.forward(json.loads(args[0]))

    s.gotMessage = do_forward

    reactor.run()
Esempio n. 12
0
class SubModel():
    '''
    zmq 订阅者模型
    '''
    def __init__(self, endpoint, callBack=None):
        try:
            if endpoint:
                logger.debug("开始运行 SUB 客户端 , 连接的服务器地址为:{}...".format(endpoint))
                self._sub = ZmqSubConnection(ZmqFactory(),
                                             ZmqEndpoint("connect", endpoint))
                if callBack:
                    self.setCallback(callBack)
                else:
                    self.setCallback(self.doDataReceived)
        except Exception as e:
            logger.error(e)

    def subscribe(self, topics=None):
        if self._sub:
            self._sub.unsubscribe(b"")
            if isinstance(topics, List):
                for topic in topics:
                    self._subscribe(topic)
            else:
                self._subscribe(topics)
        else:
            logger.error("设置过滤器之前请初始化 SUB 端口")

    def _subscribe(self, topic=None):
        if topic:
            if isinstance(topic, bytes):
                self._sub.subscribe(topic)
            elif isinstance(topic, str):
                self._sub.subscribe(topic.encode())

    def subscribeAll(self):
        self._sub.subscribe(b'')

    def setCallback(self, callBack):
        if self._sub:
            self._sub.gotMessage = callBack
        else:
            logger.error("绑定回调前请初始化 SUB 端口")

    def doDataReceived(self, *args):
        '''
        当接收到广播数据时,会触发该函数
        :param data:
        :return:
        '''
        logger.debug(f"rcev zmq msg : {args}")

    def shutdown(self):
        self._sub.shutdown()
Esempio n. 13
0
class EventManager(object):
    def __init__(self, controller):
        self.controller = controller
        self.event_handlers = []
        self.event_interfaces = {}

        try:
            config = self.controller.config_file.items('router')
        except NoSectionError:
            config = {}
        zmq_factory = ZmqFactory()
        pub_endpoint = ZmqEndpoint('connect', config.get('pub-endpoint', DEFAULT_PUB_ENDPOINT))
        self.zmq_sub = ZmqSubConnection(zmq_factory, pub_endpoint)
        self.zmq_sub.subscribe('')
        self.zmq_sub.gotMessage = self.process_message

    def register_event_handler(self, handler):
        for event_interface in zope.interface.providedBy(handler):
            if event_interface.extends(IAutomatronEventHandler):
                event_interface_name = event_interface.getName()
                if event_interface_name in self.event_interfaces:
                    if self.event_interfaces[event_interface_name] is not event_interface:
                        log.msg('Warning: Duplicate event handler interface name: %s' % event_interface_name)
                else:
                    self.event_interfaces[event_interface_name] = event_interface

                try:
                    zope.interface.verify.verifyObject(event_interface, handler)
                except (zope.interface.verify.BrokenImplementation,
                        zope.interface.verify.BrokenMethodImplementation) as e:
                    log.err(e, 'Event handler %s is broken' % handler.name)
                    break
        else:
            self.event_handlers.append(handler)
            log.msg('Loaded event handler %s' % handler.name)

    @defer.inlineCallbacks
    def dispatch_event(self, interface_event_name, *args):
        interface_name, event_name = interface_event_name.split('.', 1)
        if not interface_name in self.event_interfaces:
            return

        event_interface = self.event_interfaces[interface_name]
        event = event_interface[event_name]

        if not event_interface.extends(IAutomatronEventHandler):
            log.msg('Emitted event %s\'s interface (%s) does not extend IAutomatronEventHandler' %
                    (event_name, interface_event_name))
            return

        if len(args) < len(event.required):
            log.msg('Emitted event %s\'s declaration requires at least %d arguments, only %d were '
                    'provided.' % (interface_event_name, len(event.required), len(args)))
            return

        if len(args) > len(event.positional):
            log.msg('Emitted event %s\'s declaration requires at most %d arguments, %d were '
                    'provided.' % (interface_event_name, len(event.positional), len(args)))
            return

        event_handlers = sorted(self.event_handlers, key=lambda i: i.priority)
        for plugin in event_handlers:
            try:
                event_handler_adapter = event_interface(plugin)
            except TypeError:
                continue

            f = getattr(event_handler_adapter, event.getName())
            if (yield defer.maybeDeferred(f, *args)) is STOP:
                defer.returnValue(STOP)

    def process_message(self, message, tag):
        args = cPickle.loads(message)
        self.dispatch_event(tag, *args)
Esempio n. 14
0
def sockjs_server(**options):
    configure = options.get('configure', False)
    port = options.get('port', 8888)

    sockjs_options = {
        'websocket': True,
        'cookie_needed': False,
        'heartbeat': 25,
        'timeout': 5,
        'streaming_limit': 128 * 1024,
        'encoding': 'cp1252',  # Latin1
        'sockjs_url': 'https://d1fxtkz8shb9d2.cloudfront.net/sockjs-0.3.js'
    }

    zf = ZmqFactory()
    endpoint = '%s://localhost:%d' % (settings.FORWARDER_PUB_TRANSPORT,
                                      settings.FORWARDER_PUB_PORT)
    e = ZmqEndpoint("connect", endpoint)
    subscription = ZmqSubConnection(zf, e)
    # Subscripción a todos los mensajes
    subscription.subscribe("")

    class SockJSProtocol(protocol.Protocol):

        DIRECT_FORWARD_MESSAGE_TYPES = ('echo', )

        instances = []

        def __init__(self, *largs, **kwargs):
            print "SockJS"
            #protocol.Protocol.__init__(*largs, **kwargs)
            SockJSProtocol.instances.append(self)

        def dataReceived(self, data_string):
            try:
                data = json.loads(data_string)
                msgtype = data.get('type', None)
                if msgtype in self.DIRECT_FORWARD_MESSAGE_TYPES:
                    self.send_json(data, timestamp=repr(datetime.now()))
            except ValueError as e:
                print e
                self.send_json({'data': data_string, 'type': 'unknown'})

        def send_json(self, data=None, **opts):
            '''Envia una respuesta en JSON por el websocket'''
            if data:
                if isinstance(data, dict):
                    data_safe = copy(data)
                    data_safe.update(opts)
                elif isinstance(data, basestring):
                    try:
                        data_safe = json.loads(data)
                    except ValueError:
                        raise ValueError("Can't convert %s to json" % data)
            else:
                data_safe = opts
            self.transport.write(json.dumps(data_safe))

        def connectionLost(self, reason):
            print "Cerrando Socket"

            self.instances.remove(self)
            protocol.Protocol.connectionLost(self, reason)

        @classmethod
        def broadcast(cls, data, *largs, **kwargs):
            print "Received from forwarder %s" % data
            for conn in cls.instances:
                try:
                    conn.send_json(data)
                except Exception as e:
                    print e

    subscription.gotMessage = SockJSProtocol.broadcast

    factory = protocol.ServerFactory()
    factory.protocol = SockJSProtocol
    reactor.listenTCP(port, SockJSFactory(factory, sockjs_options))
    print "SocketServer running on %d" % port
    if not configure:
        try:
            reactor.run()
        except error.ReactorNotRunning:
            print "Closing bridge"
Esempio n. 15
0
class RadClientWorker(object):

    def __init__(self, gdata):
        self.gdata = gdata
        self.config = gdata.config
        self.que = deque() 
        self.cache = gdata.cache
        self.db_engine = gdata.db_engine
        self.metadata = models.get_metadata(self.db_engine)
        self.ops = {
            'radstart':self.start_session,
            'radstop':self.stop_session
        }
        self.radstart = ZmqPullConnection(ZmqFactory(), ZmqEndpoint('connect', self.config.mqproxy.radstart_connect))
        self.radstop = ZmqSubConnection(ZmqFactory(), ZmqEndpoint('connect',self.config.mqproxy.radstop_connect))
        self.radresp = ZmqPushConnection(ZmqFactory(), ZmqEndpoint('connect', self.config.mqproxy.radresp_connect))
        self.radstop.subscribe('radstop')
        self.radstop.gotMessage = self.subdataReceived
        self.radstart.onPull = self.dataReceived
        self.process_poll()
        logger.info("Start radstart %s" % self.radstart)
        logger.info("Start radstop %s" % self.radstop)
        logger.info("Start radresp %s" % self.radresp)


    def subdataReceived(self, request,tag):
        try:
            message = msgpack.unpackb(request)
            if self.config.system.debug:
                logger.debug(u"received radius start request:"+utils.safeunicode(message))
            self.que.appendleft(message)
        except:
            traceback.print_exc()

    def dataReceived(self, request):
        try:
            message = msgpack.unpackb(request[0])
            if self.config.system.debug:
                logger.debug(u"received radius start request:"+utils.safeunicode(message))
            self.que.appendleft(message)
        except:
            traceback.print_exc()

    def start_session(self,userdata):
        username = userdata['username']
        password = userdata['password']
        radius_ipaddr = userdata['radius_ipaddr']
        num = userdata.get("num",1)
        isresp = int(userdata.get("isresp",0))
        sendresp = lambda r : self.radresp.push(msgpack.packb(['radstart_resp',r])) if isresp else None
        senderror = lambda e: self.radresp.push(msgpack.packb(['radstart_error',dict(code=1,msg=repr(e))])) if isresp else None 
        for i in range(num):
            rad_session = RadiusSession(self.config,self.db_engine,
                statcache=self.gdata.statcache,radius_ipaddr=radius_ipaddr)
            rad_session.start(username,password).addCallbacks(sendresp,senderror)

    def stop_session(self,userdata):
        ipaddr = userdata.get('ipaddr','')
        session_id = userdata.get('session_id','')
        username = userdata.get('username','')
        RadiusSession.stop_session(ipaddr=ipaddr,session_id=session_id,username=username)
        self.radresp.push(msgpack.packb(['radstop_resp',dict(code=0,msg="session(%s,%s,%s) stop done"%(ipaddr,session_id,username))]))

    def process_poll(self):
        try:
            action, objdata = self.que.pop()
        except Exception as err:
            # logger.exception(err)
            reactor.callLater(1,self.process_poll)
        else:
            try:
                opfunc = self.ops.get(action)
                if opfunc:
                    opfunc(objdata)
                else:
                    logger.error('action %s not support'%action)
            except Exception as err:
                self.radresp.push(msgpack.packb(['%s_error'%action,dict(code=1,msg=repr(err))]))
                logger.exception(err)
            finally:
                reactor.callLater(0.001,self.process_poll)
Esempio n. 16
0
class ProxyFactory(Factory):
    protocol = ProxyProtocol

def main():
    o = ServiceOptions()
    try:
        o.parseOptions()
    except usage.UsageError, msg:
        print "%s: %s" % (sys.argv[0], msg)
        print "%s: use --help for usage details" % (sys.argv[0],)
        raise SystemExit, 1

    zf = ZmqFactory()
    sub = ZmqSubConnection(zf, ZmqEndpoint("connect", 
                                  "tcp://%s" % o.opts['subsocket']))
    sub.subscribe("")

    ws = listen("tcp:%s" % o.opts['websocket'], WebSocketFactory(ProxyFactory()))

    def forwardToWs(msg):
        for c in connections:
            c.transport.write(msg)

    sub.gotMessage = forwardToWs
    reactor.run()

if __name__ == '__main__':
    main()

Esempio n. 17
0
class ZMQfactory():
	
	def __init__(self):
		self.pub_ = None
		self.sub_ = None
		self.req_ = None
		self.rep_ = None
		self.push_ = None
		self.pull_ = None
		self.timeout = 0.95
	
	def set_timeout(self, timeout):
		self.timeout = timeout
	
	# pub sub 相关
	def add_pub(self, endpoint):
		if endpoint:
			logger.debug("开始运行 PUB 服务器,服务地址为:{}...".format(endpoint))
			self.pub_ = ZmqPubConnection(ZmqFactory(), ZmqEndpoint("bind", endpoint))
	
	def add_sub(self, endpoint):
		if endpoint:
			logger.debug("开始运行 SUB 客户端 , 连接的服务器地址为:{}...".format(endpoint))
			self.sub_ = ZmqSubConnection(ZmqFactory(), ZmqEndpoint("connect", endpoint))
			self.set_callback()
	
	def set_filter(self, filter_=None):
		'''
		请输入需要接受的主题(必须调用该函数,否则无法收到任何数据)
		:param filter_:  type str_list
		:return:
		'''
		if self.sub_:
			if filter_:
				for item in filter_:
					self.sub_.subscribe(item.encode())
			else:
				self.sub_.subscribe(b'')
		else:
			logger.error("请初始化SUB端口")
	
	def set_callback(self):
		if self.sub_:
			self.sub_.gotMessage = self.subscribeReceived
		else:
			logger.error("请初始化SUB端口")
	
	def subscribeReceived(self, *args):
		'''
		当接收到广播数据时,会触发该函数
		:param data:
		:return:
		'''
	
	def publishData(self, tag, data):
		'''
		从push服务器向外推送数据
		:param tag:
		:param data:
		:return:
		'''
	
	# req-rep 相关
	def add_req(self, endpoint):
		'''
		设置 req 对象
		:param endpoint:
		:return:
		'''
		if endpoint:
			logger.debug("开始运行 REQ 服务器,连接地址为:{}...".format(endpoint))
			self.req_ = ZmqREQConnection(ZmqFactory(), ZmqEndpoint('connect', endpoint))
	
	def add_rep(self, endpoint, callBack=onPrint):
		'''
		设置 rep 对象
		:param endpoint:
		:param callBack:
		:return:
		'''
		if endpoint:
			logger.debug("开始运行 REP 服务器,监听地址为:{}...".format(endpoint))
			self.rep_ = ZmqREPConnection(ZmqFactory(), ZmqEndpoint('bind', endpoint))
			self.rep_.gotMessage = callBack
	
	def sendReq(self, data, callBack=onPrint, errBack=onTimeout):
		'''
		发送 req 信息
		:param data:
		:param callBack:
		:param errBack:
		:return:
		'''
		try:
			d = self.req_.sendMsg(data, timeout=self.timeout)
			d.addCallback(callBack).addErrback(errBack)
		except Exception as e:
			logger.error(e)
	
	# push pull 相关
	def add_push(self, endpoint):
		'''

		:param endpoint:
		:return:
		'''
		if endpoint:
			logger.debug("开始运行 PUSH 服务器,监听地址为:{}...".format(endpoint))
			self.push_ = ZmqPushConnection(ZmqFactory(), ZmqEndpoint('connect', endpoint))
	
	def add_pull(self, endpoint, callBack=onPrint):
		'''

		:param endpoint:
		:param callBack:
		:return:
		'''
		if endpoint:
			logger.debug("开始运行 PULL 服务器,连接地址为:{}...".format(endpoint))
			self.pull_ = ZmqPullConnection(ZmqFactory(), ZmqEndpoint('bind', endpoint))
			self.pull_.onPull = callBack
	
	def pushData(self, data):
		'''

		:param data:
		:return:
		'''
		try:
			self.push_.push(data)
		except zmq.error.Again:
			logger.error("Skipping, no pull consumers...")
Esempio n. 18
0
def sockjs_server(**options):
    configure = options.get('configure', False)
    port = options.get('port', 8888)

    sockjs_options = {
        'websocket': True,
        'cookie_needed': False,
        'heartbeat': 25,
        'timeout': 5,
        'streaming_limit': 128 * 1024,
        'encoding': 'cp1252',  # Latin1
        'sockjs_url': 'https://d1fxtkz8shb9d2.cloudfront.net/sockjs-0.3.js'
    }

    zf = ZmqFactory()
    endpoint = '%s://localhost:%d' % (settings.FORWARDER_PUB_TRANSPORT,
                                      settings.FORWARDER_PUB_PORT)
    e = ZmqEndpoint("connect", endpoint)
    subscription = ZmqSubConnection(zf, e)
    # Subscripción a todos los mensajes
    subscription.subscribe("")

    class SockJSProtocol(protocol.Protocol):

        DIRECT_FORWARD_MESSAGE_TYPES = ('echo', )

        instances = []

        def __init__(self, *largs, **kwargs):
            print "SockJS"
            #protocol.Protocol.__init__(*largs, **kwargs)
            SockJSProtocol.instances.append(self)

        def dataReceived(self, data_string):
            try:
                data = json.loads(data_string)
                msgtype = data.get('type', None)
                if msgtype in self.DIRECT_FORWARD_MESSAGE_TYPES:
                    self.send_json(data, timestamp=repr(datetime.now()))
            except ValueError as e:
                print e
                self.send_json({'data': data_string, 'type': 'unknown'})

        def send_json(self, data=None, **opts):
            '''Envia una respuesta en JSON por el websocket'''
            if data:
                if isinstance(data, dict):
                    data_safe = copy(data)
                    data_safe.update(opts)
                elif isinstance(data, basestring):
                    try:
                        data_safe = json.loads(data)
                    except ValueError:
                        raise ValueError("Can't convert %s to json" % data)
            else:
                data_safe = opts
            self.transport.write(json.dumps(data_safe))

        def connectionLost(self, reason):
            print "Cerrando Socket"

            self.instances.remove(self)
            protocol.Protocol.connectionLost(self, reason)

        @classmethod
        def broadcast(cls, data, *largs, **kwargs):
            print "Received from forwarder %s" % data
            for conn in cls.instances:
                try:
                    conn.send_json(data)
                except Exception as e:
                    print e

    subscription.gotMessage = SockJSProtocol.broadcast

    factory = protocol.ServerFactory()
    factory.protocol = SockJSProtocol
    reactor.listenTCP(port, SockJSFactory(factory, sockjs_options))
    print "SocketServer running on %d" % port
    if not configure:
        try:
            reactor.run()
        except error.ReactorNotRunning:
            print "Closing bridge"