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

Made small protocol

parent 15919e38
No related branches found
No related tags found
1 merge request!79Deliver notification info
import errno
import logging
from traits.api import Any, List from traits.api import Any, List
from force_bdss.api import BaseNotificationListener from force_bdss.api import BaseNotificationListener
...@@ -5,17 +7,30 @@ import zmq ...@@ -5,17 +7,30 @@ import zmq
class UINotification(BaseNotificationListener): class UINotification(BaseNotificationListener):
#: The ZMQ context.
_context = Any() _context = Any()
#: The pubsub socket.
_pub_socket = Any() _pub_socket = Any()
#: The synchronization socket to recover already sent information at a
#: later stage
_rep_socket = Any() _rep_socket = Any()
#: The cache of messages as they are sent out.
_msg_cache = List() _msg_cache = List()
def deliver(self, model, message): def deliver(self, model, message):
try: try:
data = self._rep_socket.recv(flags=zmq.NOBLOCK) data = self._rep_socket.recv(flags=zmq.NOBLOCK)
except zmq.ZMQError: except zmq.ZMQError as e:
pass if e.errno == errno.EAGAIN:
else: data = None
else:
logging.error("Error while receiving data from "
"reply socket: {}".format(str(e)))
if data and data[0:4] == "SYNC".encode("utf-8"):
self._rep_socket.send_multipart(self._msg_cache) self._rep_socket.send_multipart(self._msg_cache)
msg = "ACTION {}".format(message).encode("utf-8") msg = "ACTION {}".format(message).encode("utf-8")
......
...@@ -9,16 +9,12 @@ socket.connect("tcp://localhost:12345") ...@@ -9,16 +9,12 @@ socket.connect("tcp://localhost:12345")
socket.setsockopt(zmq.SUBSCRIBE, "".encode("utf-8")) socket.setsockopt(zmq.SUBSCRIBE, "".encode("utf-8"))
send_socket = context.socket(zmq.REQ) send_socket = context.socket(zmq.REQ)
send_socket.connect("tcp://localhost:12346") 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
send_socket.send("SYNC".encode("utf-8"))
data = send_socket.recv_multipart()
for d in data:
topic, messagedata = d.split()
print("SYNCED ", topic, messagedata)
while True: while True:
string = socket.recv() 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