42 lines
999 B
Python
42 lines
999 B
Python
import zmq
|
|
|
|
|
|
class ZmqPubSubStreamer:
|
|
'''
|
|
Not thread-safe. Always get this inside the thread/process where you intend
|
|
to use it.
|
|
'''
|
|
|
|
def __init__(self, port):
|
|
self._socket = zmq.Context.instance().socket(zmq.PUB)
|
|
print('Starting socket with address: ' + 'tcp://*:' + str(port))
|
|
self._socket.bind("tcp://*:" + str(port))
|
|
|
|
|
|
def send_message(self, message):
|
|
'''
|
|
Args
|
|
----
|
|
message: A message type that has the serialise() method.
|
|
'''
|
|
self.send_message_topic("", message)
|
|
|
|
def send_message_topic(self, topic, message):
|
|
self._socket.send_multipart([bytes(topic), message.serialise()])
|
|
|
|
|
|
class BluetoothStreamer:
|
|
def __init__(self):
|
|
pass
|
|
|
|
def send_message(self, message_bytes):
|
|
pass
|
|
|
|
|
|
def getZmqPubSubStreamer(port):
|
|
'''
|
|
Not thread-safe. Always get this inside the thread/process where you intend
|
|
to use it.
|
|
'''
|
|
return ZmqPubSubStreamer(port)
|