BingoXuan
2018-07-04 16:51:54 +08:00
贴一下服务器的部分代码
class ZPub(Pub):
def __init__(self, identity):
super().__init__(identity)
ctx = zmq.Context()
self.pub_socket = ctx.socket(zmq.PUB)
self.pub_socket.setsockopt_string(zmq.IDENTITY, self.identity)
self.pub_socket.bind('tcp://127.0.0.1:8099')
self.lock = threading.Lock()
def _send(self, ts, msg, id_str):
self.lock.acquire()
self.pub_socket.send_multipart([bytes(m, encoding='ascii') for m in [ts, msg, id_str]])
self.lock.release()