Skip to content

Commit b92bbfc

Browse files
author
Joel 'Aaron' Cohen
committed
Add working pyzmq socket support
1 parent 275ce1d commit b92bbfc

File tree

5 files changed

+61
-390
lines changed

5 files changed

+61
-390
lines changed

Diff for: pub.py

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# publisher
2+
3+
import trzmq
4+
import trio
5+
import zmq
6+
7+
async def run():
8+
context = zmq.Context()
9+
socket = context.socket(zmq.PUB)
10+
socket.connect("tcp://0.0.0.0:5556")
11+
12+
s = trzmq.Socket(socket)
13+
i = 1
14+
while True:
15+
topic = b"ZMQ-Test"
16+
message = "Hello, NORM " + str(i) + "..."
17+
await s.send(b"%b %b" % (topic, message.encode()))
18+
print("%s %s" % (topic, message))
19+
i += 1
20+
await trio.sleep(1)
21+
22+
trio.run(run)

Diff for: requirements.txt

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
pyzmq
2+
trio

Diff for: sub.py

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# subscriber
2+
3+
import trio
4+
import trzmq
5+
import zmq
6+
7+
async def run():
8+
context = zmq.Context()
9+
socket = context.socket(zmq.SUB)
10+
socket.bind("tcp://0.0.0.0:5556")
11+
socket.setsockopt_string(zmq.SUBSCRIBE, '')
12+
s = trzmq.Socket(socket)
13+
while True:
14+
string = await s.recv()
15+
print(string)
16+
17+
trio.run(run)

Diff for: trzmq/__init__.py

+3
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,6 @@
55

66
from ._proxy import *
77
__all__ += _proxy.__all__
8+
9+
from ._socket import *
10+
__all__ += _socket.__all__

0 commit comments

Comments
 (0)