From 1d5abaaea00ce1291a1229fed9e651600db82634 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A1lint=20Bokros?= Date: Mon, 27 Nov 2017 18:20:54 +0100 Subject: [PATCH] Add ability to message another component to ComponentBase --- src/components/component_base.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/components/component_base.py b/src/components/component_base.py index fa192c5..16626ae 100644 --- a/src/components/component_base.py +++ b/src/components/component_base.py @@ -1,3 +1,4 @@ +import json import zmq from zmq.eventloop import ioloop from zmq.eventloop.zmqstream import ZMQStream @@ -19,3 +20,12 @@ class ComponentBase: self.zmq_push_socket = self.zmq_context.socket(zmq.PUSH) self.zmq_push_socket.connect('tcp://localhost:{}'.format(RECEIVER_PORT)) + def message_other(self, anchor, data): + encoded_anchor = anchor.encode('utf-8') + message = { + 'anchor': anchor, + 'data': data + } + encoded_message = json.dumps(message).encode('utf-8') + self.zmq_push_socket.send_multipart([encoded_anchor, encoded_message]) +