feat: implement negotiation
By implementing SocketBase and adding the socket to the state, the negotiation will automatically give the right endpoints. ref: N25B-168
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import logging
|
||||
logging.basicConfig(level=logging.DEBUG)
|
||||
import time
|
||||
|
||||
import zmq
|
||||
@@ -25,6 +26,8 @@ def main_loop(context):
|
||||
for receiver in receivers:
|
||||
poller.register(receiver.socket, zmq.POLLIN)
|
||||
|
||||
logging.debug("Starting main loop.")
|
||||
|
||||
while True:
|
||||
if state.exit_event.is_set(): break
|
||||
socks = dict(poller.poll(100))
|
||||
@@ -36,7 +39,8 @@ def main_loop(context):
|
||||
|
||||
message = receiver.socket.recv_json()
|
||||
response = receiver.handle_message(message)
|
||||
receiver.socket.send_json(response)
|
||||
if receiver.socket.getsockopt(zmq.TYPE) == zmq.REP:
|
||||
receiver.socket.send_json(response)
|
||||
|
||||
time_spent_ms = (time.time() - start_time) * 1000
|
||||
if time_spent_ms > 50:
|
||||
@@ -51,7 +55,7 @@ def main():
|
||||
try:
|
||||
main_loop(context)
|
||||
except KeyboardInterrupt:
|
||||
print("User interrupted.")
|
||||
logging.info("User interrupted.")
|
||||
finally:
|
||||
state.deinitialize()
|
||||
context.term()
|
||||
|
||||
Reference in New Issue
Block a user