Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Program to see if there is a live connection with earth
- from datetime import datetime, timedelta
- import sys
- import zmq
- context = zmq.Context()
- import infoPack_pb2
- # Set up subscriber connection to receive messages from the receiveBroker
- subscriber = context.socket(zmq.SUB)
- subscriber.connect('tcp://localhost:12345')
- subscriber.setsockopt(zmq.SUBSCRIBE, '')
- # Set up publisher connection to send messages to the sendBroker
- publisher = context.socket(zmq.PUB)
- publisher.bind('tcp://*:54321')
- # Initialise poll set
- poller = zmq.Poller()
- poller.register(subscriber, zmq.POLLIN)
- handshake = False
- print('\nWait for handshake from earth')
- while True:
- events = dict(poller.poll(2000))
- if subscriber in events and events[subscriber] == zmq.POLLIN:
- message = subscriber.recv()
- beat = infoPack_pb2.heartBeat()
- beat.ParseFromString(message)
- if beat.heartBeat == 1:
- publisher.send(message)
- if handshake == False:
- handshake = True
- print('Handshake received from earth')
- sys.stdout.write('.')
- sys.stdout.flush()
- if not events:
- if handshake != False:
- print('The Earth is silent')
Advertisement
Add Comment
Please, Sign In to add comment