mirror of
				https://github.com/avatao-content/baseimage-tutorial-framework
				synced 2025-11-04 11:52:54 +00:00 
			
		
		
		
	Add ability to message another component to ComponentBase
This commit is contained in:
		@@ -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])
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user