From 8a73594aa9660c0eda0b6615247e4abf957cc2bd Mon Sep 17 00:00:00 2001 From: Valentin Gehrke Date: Thu, 23 Jun 2016 15:17:59 +0200 Subject: [PATCH] 0mq message publisher --- 0mq_client.py | 22 ++++++++++++++++++++++ 0mq_server.py | 12 ++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 0mq_client.py create mode 100644 0mq_server.py diff --git a/0mq_client.py b/0mq_client.py new file mode 100644 index 0000000..a8535c6 --- /dev/null +++ b/0mq_client.py @@ -0,0 +1,22 @@ +#!/usr/bin/env python + +from sys import argv + +host = argv[1] if argv[1] else "127.0.0.1" + +serv = "tcp://" + host + ":5555" + +import zmq + +context = zmq.Context() +print("Verbinde zu %s" % serv) +socket = context.socket(zmq.SUB) + +socket.connect(serv) + +socket.setsockopt_string(zmq.SUBSCRIBE, "MSG") + +while True: + line = socket.recv_string() + print("< "+ line) + diff --git a/0mq_server.py b/0mq_server.py new file mode 100644 index 0000000..1003e78 --- /dev/null +++ b/0mq_server.py @@ -0,0 +1,12 @@ +#!/usr/bin/env python + +import zmq + +context = zmq.Context() + +server = context.socket(zmq.PUB) +server.bind("tcp://*:5555") + +while True: + line = input("> ") + server.send_string("MSG %s" % line)