2018-02-08 14:00:16 +00:00
|
|
|
import zmq
|
|
|
|
|
2018-02-09 13:21:17 +00:00
|
|
|
from tfw.config import tfwenv
|
2018-02-13 16:44:48 +00:00
|
|
|
from tfw.networking.zmq_connector_base import ZMQConnectorBase
|
2018-02-08 14:00:16 +00:00
|
|
|
from tfw.networking.serialization import serialize_all, deserialize_all
|
|
|
|
|
|
|
|
|
|
|
|
class SolvableConnector(ZMQConnectorBase):
|
|
|
|
def __init__(self, zmq_context=None):
|
|
|
|
super(SolvableConnector, self).__init__(zmq_context)
|
|
|
|
self._zmq_req_socket = self._zmq_context.socket(zmq.REQ)
|
2018-02-09 13:21:17 +00:00
|
|
|
self._zmq_req_socket.bind('tcp://*:{}'.format(tfwenv.CONTROLLER_PORT))
|
2018-02-08 14:00:16 +00:00
|
|
|
|
|
|
|
def send(self, key, message):
|
|
|
|
self._zmq_req_socket.send_multipart(serialize_all(key, message))
|
|
|
|
|
|
|
|
def recv(self):
|
|
|
|
return deserialize_all(*self._zmq_req_socket.recv_multipart())
|