hugvey/test_sub.py
2019-01-17 17:39:52 +01:00

58 lines
1.3 KiB
Python

import zmq
import random
import sys
import time
import asyncio
import hugvey.communication
def main():
if len(sys.argv) > 1:
port = sys.argv[1]
int(port)
context = zmq.Context()
socket = context.socket(zmq.SUB)
socket.bind("tcp://*:5556")
for i in range(0, 25):
socket.setsockopt(zmq.SUBSCRIBE, "hv{}".format(i).encode())
while True:
# a = await hugvey.communication.zmqReceive(socket)
# print(a)
print('received')
r = socket.recv_multipart()
print(r)
main()
# loop = asyncio.get_event_loop()
# loop.run_until_complete(main())
#
#
# import sys
# import zmq
#
# port = "5555"
#
# # Socket to talk to server
# context = zmq.Context()
# socket = context.socket(zmq.SUB)
#
# # print "Collecting updates from weather server..."
# socket.bind ("tcp://*:%s" % port)
#
# # Subscribe to zipcode, default is NYC, 10001
# # topicfilter = "10001"
# for i in range(0, 25):
# socket.setsockopt(zmq.SUBSCRIBE, "hv{}".format(i).encode())
#
# # Process 5 updates
# # total_value = 0
# for update_nbr in range (5):
# string = socket.recv_multipart()
# print(string)
# # topic, messagedata = string.split()
# # total_value += int(messagedata)
# # print topic, messagedata
#
# # print "Average messagedata value for topic '%s' was %dF" % (topicfilter, total_value / update_nbr)