multi-user/client.py
2019-02-11 16:25:08 +01:00

60 lines
1.1 KiB
Python

"""
Clone Client Model One
Author: Min RK <benjaminrk@gmail.com>
"""
import random
import time
import msgpack
import zmq
from libs import kvsimple
def main():
# Prepare our context and publisher socket
ctx = zmq.Context()
# Update socket binding
updates = ctx.socket(zmq.SUB)
updates.linger = 0
updates.connect("tcp://localhost:5555")
updates.setsockopt_string(zmq.SUBSCRIBE, '')
state_request = ctx.socket(zmq.DEALER)
state_request.setsockopt(zmq.IDENTITY, b"PEER2")
state_request.linger = 0
state_request.connect("tcp://localhost:5556")
# poller for socket aggregation
poller = zmq.Poller()
poller.register(updates, zmq.POLLIN)
while True:
try:
socks = dict(poller.poll(10))
except KeyboardInterrupt:
break
if updates in socks:
message = updates.recv_multipart(zmq.NOBLOCK)
print(message)
# Send update
new_state= b"test"
state_request.send(new_state)
print("Sending {}".format(new_state))
time.sleep(1)
if __name__ == '__main__':
main()