baseimage-tutorial-framework/src/event_handlers/message_sender.py

15 lines
495 B
Python
Raw Normal View History

2018-01-29 15:48:32 +00:00
from server_connector import ServerUplinkConnector
class MessageSender:
def __init__(self, custom_anchor=None):
self.server_connector = ServerUplinkConnector()
if isinstance(custom_anchor, str):
custom_anchor = custom_anchor.encode('utf-8')
self.anchor = custom_anchor or b'message'
def send(self, message):
if isinstance(message, str):
message = message.encode('utf-8')
self.server_connector.send(self.anchor, message)