Created
February 16, 2012 03:29
-
-
Save hgdeoro/1841491 to your computer and use it in GitHub Desktop.
Cliente básico con 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) | |
msg = {'un': 'dict'} | |
context = zmq.Context() | |
zocket = context.socket(zmq.REQ) | |
zocket.connect("tcp://127.0.0.1:12345") | |
# Enviamos msg | |
logging.info("Enviando msg: %r", msg) | |
# Si el servidor está andando y recibe el mensaje, | |
# este método se ejecuta inmediatamente. | |
# Si el servidor NO está andando, este método bloquea hasta | |
# que el servidor recibe el mensaje | |
zocket.send_pyobj(msg) | |
# Esperamos respuesta | |
logging.info("Esperando respuesta...") | |
msg_in = zocket.recv_pyobj() | |
logging.info("Mensaje recivido: %r", msg_in) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment