import zmq

class Request():
    def __init__(self):
        self._context = None
        self._fd = None

    def open(self):
        self._context = zmq.Context()
        self._fd = self._context.socket(zmq.REQ)
        self._fd.connect("tcp://localhost:5558")
        
    def close(self):
        self._fd.close()
        
    def send(self,request):
        self._fd.send_string(request)
        return self._fd.recv_string()

class Reply():
    def __init__(self):
        self._context = None
        self._fd = None

    def open(self):
        self._context = zmq.Context()
        self._fd = self._context.socket(zmq.REP)
        self._fd.bind("tcp://*:5558")
        
    def close(self):
        self._fd.close()
        self._context.term()
        
    def wait_for_request(self):
        request = self._fd.recv_string()
        self._fd.send_string("received")
        return request
