How to use the zmq.REP function in zmq

To help you get started, we’ve selected a few zmq examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github StuntsPT / Radeon-tray / radeontray / radeonpmserver.py View on Github external
#Main function
    init_method, init_profile = power_status_get().split(",")
    #Default values
    def_method, def_profile = ["dynpm", "default"]

    # Apply the last configuration if it differs from default
    if def_method != init_method or def_profile != init_profile:
        power_profile_set(def_profile, CARDS)
        power_method_set(def_method, CARDS)

    if port:
        PORT = port
    int(PORT)

    CONTEXT = zmq.Context()
    SOCKET = CONTEXT.socket(zmq.REP)
    SOCKET.bind("tcp://*:%s" % PORT)

    while True:
        message = SOCKET.recv_string()

        if message == "info":
            SOCKET.send_string(radeon_info_get())
        elif message == "verifier":
            SOCKET.send_string(str(verifier()))
        elif message == "powerstatus":
            SOCKET.send_string(power_status_get())
        elif message.find(":"):
            try:
                command, arg, user_home = message.split(":")
            except ValueError:
                SOCKET.send_string("Command not correct")
github brmson / Personal-Assistant / modules / attentionWord / pocketSphinx / attentionWord.py View on Github external
def runServer(self):
    """
    Runs the ZMQ server.
    Returns:
      None
    """

    # bind the port
    self.socket = self.zmqctx.socket(zmq.REP)
    self.socket.bind('ipc://127.0.0.1:{}'.format(port))
github mthomure / glimpse-project / glimpse / util / zmq_cluster.py View on Github external
def SocketTypeToString(type_):
  """Get a textual representation of a socket type ID."""
  mapping = { zmq.PUSH : 'PUSH', zmq.PULL : 'PULL',
      zmq.PUB : 'PUB', zmq.SUB : 'SUB', zmq.REQ : 'REQ', zmq.REP : 'REP' }
  return mapping[type_]
github opendisplays / yarely / yarely / core / scheduling / contextconstraintsparser.py View on Github external
)
        zmq_subsmanager_reply_socket.bind(
            ZMQ_ADDRESS_LOCALHOST.format(port=ZMQ_SUBSMANAGER_REQ_PORT)
        )

        # Create a reply socket to the sensor manager
        zmq_sensormanager_reply_socket = self.zmq_context.socket(zmq.REP)
        zmq_sensormanager_reply_socket.setsockopt(
            zmq.LINGER, ZMQ_SOCKET_LINGER_MSEC
        )
        zmq_sensormanager_reply_socket.bind(
            ZMQ_ADDRESS_LOCALHOST.format(port=ZMQ_SENSORMANAGER_REQ_PORT)
        )

        # Create termination socket
        zmq_termination_reply_socket = self.zmq_context.socket(zmq.REP)
        zmq_termination_reply_socket.bind(
            ZMQ_ADDRESS_INPROC.format(
                identifier=self.zmq_scheduler_term_identifier
            )
        )

        # Register all sockets
        zmq_poller = zmq.Poller()
        zmq_poller.register(zmq_subsmanager_reply_socket, zmq.POLLIN)
        zmq_poller.register(zmq_sensormanager_reply_socket, zmq.POLLIN)
        zmq_poller.register(zmq_termination_reply_socket, zmq.POLLIN)

        # Provide a method to loop over sockets that have data. It tries to
        # find matching methods for incoming requests/replies with
        # _handle_zmq_msg().
        def _loop_over_sockets():
github SurrealAI / surreal / surreal / distributed / zmq_struct_new.py View on Github external
def socket_type(self):
        if self.mode == zmq.PULL:
            return 'PULL'
        elif self.mode == zmq.PUSH:
            return 'PUSH'
        elif self.mode == zmq.PUB:
            return 'PUB'
        elif self.mode == zmq.SUB:
            return 'SUB'
        elif self.mode == zmq.PAIR:
            return 'PAIR'
        elif self.mode == zmq.REQ:
            return 'REQ'
        elif self.mode == zmq.REP:
            return 'REP'
        elif self.mode == zmq.ROUTER:
            return 'ROUTER'
        elif self.mode == zmq.DEALER:
            return 'DEALER'
github westpa / westpa / src / wemd / work_managers / zeromq.py View on Github external
def dispatch_receive(self):        
        dr_ctl = self.bind_thread_ctl(self.dr_ctl_endpoint)
        
        task_socket = self.context.socket(zmq.REP)
        task_socket.bind(self.upstream_task_endpoint)
        
        poller = zmq.Poller()
        poller.register(dr_ctl, zmq.POLLIN)
        poller.register(task_socket, zmq.POLLIN)
        while not self.shutdown_called:
            poll_results = {fd: _flag for (fd, _flag) in poller.poll()}

            if poll_results.get(dr_ctl) == zmq.POLLIN:
                messages = recvall(dr_ctl)
                for message in messages:
                    if message == 'shutdown':
                        break
                del messages
                    
            if poll_results.get(task_socket) == zmq.POLLIN and not self.shutdown_called:
github intuition-io / intuition / neuronquant / gryd / transport.py View on Github external
def run(self, port=5555, on_recv=None, forever=False):
        self.socket = self.context.socket(zmq.REP)
        self.port = port
        if not on_recv:
            on_recv = self.default_on_recv
        log.info('Server listening on port {}...'.format(port))
        self.socket.bind("tcp://*:%s" % port)
        msg = dict()
        if forever:
            while 'done' not in msg:
                msg = self.receive()
                try:
                    on_recv(msg, id=port)
                    self.send({"{}:statut".format(port): OK_CODE})
                except:
                    log.error('** Processing message received')
                    self.send({"{}:statut".format(port): 1})
            log.info('Termination request, stop listening...')
github Matrixeigs / energy_management_system / local_ems.py View on Github external
# Start the information connection
    context = zmq.Context()
    socket = context.socket(zmq.REQ)
    socket.connect("tcp://localhost:5555")

    socket_upload = context.socket(zmq.REQ)
    socket_upload.connect("tcp://localhost:5556")

    socket_upload_ed = context.socket(zmq.REQ)
    socket_upload_ed.connect("tcp://localhost:5557")

    socket_upload_uc = context.socket(zmq.REQ)
    socket_upload_uc.connect("tcp://localhost:5558")

    socket_download = context.socket(zmq.REP)
    socket_download.connect("tcp://localhost:5559")

    while True:
        socket.send(b"ConnectionRequest")

        message = socket.recv()
        if message == b"Start!":
            logger.info("The connection between the local EMS and universal EMS establishes!")
            break
        else:
            logger.error("Waiting for the connection between the local EMS and universal EMS!")

    information_receive_send.information_send(socket, static_info, 2)

    info_ed = economic_dispatch_info.local_sources()
    info_uc = economic_dispatch_info.local_sources()  # The information model in the
github Kismuz / btgym / btgym / server.py View on Github external
# Runtime Housekeeping:
        cerebro = None
        episode_result = dict()
        episode_sample = None

        # How long to wait for data_master to reset data:
        self.wait_for_data_reset = 300  # seconds

        connect_timeout = 60  # in seconds

        # Set up a comm. channel for server as ZMQ socket
        # to carry both service and data signal
        # !! Reminder: Since we use REQ/REP - messages do go in pairs !!
        self.context = zmq.Context()
        self.socket = self.context.socket(zmq.REP)
        self.socket.setsockopt(zmq.RCVTIMEO, -1)
        self.socket.setsockopt(zmq.SNDTIMEO, connect_timeout * 1000)
        self.socket.bind(self.network_address)

        self.data_context = zmq.Context()
        self.data_socket = self.data_context.socket(zmq.REQ)
        self.data_socket.setsockopt(zmq.RCVTIMEO, connect_timeout * 1000)
        self.data_socket.setsockopt(zmq.SNDTIMEO, connect_timeout * 1000)
        self.data_socket.connect(self.data_network_address)

        # Check connection:
        self.log.debug('Pinging data_server at: {} ...'.format(self.data_network_address))

        data_server_response = self._comm_with_timeout(
            socket=self.data_socket,
            message={'ctrl': 'ping!'}