Skip to content

Instantly share code, notes, and snippets.

@hgdeoro
Created February 16, 2012 03:28
Show Gist options
  • Save hgdeoro/1841488 to your computer and use it in GitHub Desktop.
Save hgdeoro/1841488 to your computer and use it in GitHub Desktop.
Server ZeroMQ + pyzmq
# -*- coding: utf-8 -*-
import logging
import zmq
def main():
logging.basicConfig(level=logging.INFO)
# Creamos contexto de ZeroMQ
ctx = zmq.Context()
# Creamos un "socket"
zocket = ctx.socket(zmq.REP)
zocket.bind("tcp://0.0.0.0:12345")
while True:
# Esperamos request (bloquea hasta que recivimos uno)
logging.info("Esperando mensaje...")
# Y obtenemos el mensaje como un objeto Python
msg = zocket.recv_pyobj()
# Hacemos algo con request
logging.info("Msg recibido: %r", msg)
# Y enviamos respuesta
zocket.send_pyobj({'status': 'ok'})
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment