mirror of
https://github.com/avatao-content/baseimage-tutorial-framework
synced 2024-11-22 13:51:33 +00:00
Add ability to message another component to ComponentBase
This commit is contained in:
parent
66d684f022
commit
1d5abaaea0
@ -1,3 +1,4 @@
|
|||||||
|
import json
|
||||||
import zmq
|
import zmq
|
||||||
from zmq.eventloop import ioloop
|
from zmq.eventloop import ioloop
|
||||||
from zmq.eventloop.zmqstream import ZMQStream
|
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 = self.zmq_context.socket(zmq.PUSH)
|
||||||
self.zmq_push_socket.connect('tcp://localhost:{}'.format(RECEIVER_PORT))
|
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])
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user