From 03d6f587e9ea9dd865d53f75f563e4c43056c181 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A1lint=20Bokros?= Date: Thu, 8 Feb 2018 14:59:43 +0100 Subject: [PATCH] Create initial version of ControllerConnector --- lib/tfw/networking/controller_connector.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 lib/tfw/networking/controller_connector.py diff --git a/lib/tfw/networking/controller_connector.py b/lib/tfw/networking/controller_connector.py new file mode 100644 index 0000000..b539163 --- /dev/null +++ b/lib/tfw/networking/controller_connector.py @@ -0,0 +1,18 @@ +import zmq +from zmq.eventloop import ioloop +from zmq.eventloop.zmqstream import ZMQStream + +from tfw.config import CONTROLLER_PORT +from tfw.util 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(CONTROLLER_PORT)) + self._zmq_rep_stream = ZMQStream(self._zmq_rep_socket) + + self.register_callback = self._zmq_rep_stream.on_recv