0mq message publisher
This commit is contained in:
parent
4e24bd0f63
commit
8a73594aa9
2 changed files with 34 additions and 0 deletions
22
0mq_client.py
Normal file
22
0mq_client.py
Normal file
|
@ -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)
|
||||||
|
|
12
0mq_server.py
Normal file
12
0mq_server.py
Normal file
|
@ -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)
|
Loading…
Reference in a new issue