Created
February 16, 2012 03:28
-
-
Save hgdeoro/1841488 to your computer and use it in GitHub Desktop.
Server ZeroMQ + pyzmq
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- 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