Skip to content
Snippets Groups Projects
Commit 15919e38 authored by Stefano Borini's avatar Stefano Borini
Browse files

Handle reconnection

parent 8d3cf0b4
No related branches found
No related tags found
1 merge request!79Deliver notification info
from traits.api import Any
from traits.api import Any, List
from force_bdss.api import BaseNotificationListener
import zmq
class UINotification(BaseNotificationListener):
_zmq_context = Any()
_zmq_socket = Any()
_context = Any()
_pub_socket = Any()
_rep_socket = Any()
_msg_cache = List()
def deliver(self, model, message):
self._zmq_socket.send(("ACTION {}".format(message)).encode("utf-8"))
try:
data = self._rep_socket.recv(flags=zmq.NOBLOCK)
except zmq.ZMQError:
pass
else:
self._rep_socket.send_multipart(self._msg_cache)
msg = "ACTION {}".format(message).encode("utf-8")
self._msg_cache.append(msg)
self._pub_socket.send(msg)
def init_persistent_state(self, model):
self._zmq_context = zmq.Context()
self._zmq_socket = self._zmq_context.socket(zmq.PUB)
self._zmq_socket.bind("tcp://*:12345")
self._context = zmq.Context()
self._pub_socket = self._context.socket(zmq.PUB)
self._pub_socket.bind("tcp://*:12345")
self._rep_socket = self._context.socket(zmq.REP)
self._rep_socket.bind("tcp://*:12346")
......@@ -5,9 +5,20 @@ port = "5556"
# Socket to talk to server
context = zmq.Context()
socket = context.socket(zmq.SUB)
socket.connect ("tcp://localhost:12345")
socket.connect("tcp://localhost:12345")
socket.setsockopt(zmq.SUBSCRIBE, "".encode("utf-8"))
send_socket = context.socket(zmq.REQ)
send_socket.connect("tcp://localhost:12346")
send_socket.send("hello".encode("utf-8"))
while True:
try:
data = send_socket.recv_multipart(flags=zmq.NOBLOCK)
except zmq.ZMQError:
pass
else:
print("RECOVERING CACHE", data)
break
while True:
string = socket.recv()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment