baseimage-tutorial-framework/lib/tfw/networking/controller_connector.py
2018-02-13 17:44:48 +01:00

19 lines
642 B
Python

import zmq
from zmq.eventloop import ioloop
from zmq.eventloop.zmqstream import ZMQStream
from tfw.config import tfwenv
from tfw.networking.zmq_connector_base import ZMQConnectorBase
ioloop.install()
class ControllerConnector(ZMQConnectorBase):
def __init__(self, zmq_context=None):
super(ControllerConnector, self).__init__(zmq_context)
self._zmq_rep_socket = self._zmq_context.socket(zmq.REP)
self._zmq_rep_socket.connect('tcp://localhost:{}'.format(tfwenv.CONTROLLER_PORT))
self._zmq_rep_stream = ZMQStream(self._zmq_rep_socket)
self.register_callback = self._zmq_rep_stream.on_recv_stream