Created
May 25, 2023 11:08
-
-
Save minrk/f4160936c5b644261a7684558f34a78a to your computer and use it in GitHub Desktop.
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
FROM python:3.10 | |
# install libzmq with drafts enabled | |
ENV ZMQ_VERSION=4.3.4 \ | |
PREFIX=/usr/local \ | |
CPU_COUNT=4 | |
RUN wget https://github.com/zeromq/libzmq/releases/download/v${ZMQ_VERSION}/zeromq-${ZMQ_VERSION}.tar.gz -O libzmq.tar.gz \ | |
&& tar -xzf libzmq.tar.gz \ | |
&& cd zeromq-${ZMQ_VERSION} \ | |
&& ./configure --prefix=${PREFIX} --enable-drafts \ | |
&& make -j${CPU_COUNT} \ | |
&& make install | |
# install pyzmq with drafts enabled | |
ENV ZMQ_PREFIX=${PREFIX} \ | |
ZMQ_DRAFT_API=1 | |
RUN pip install -v --no-binary pyzmq --pre pyzmq | |
# add test script | |
COPY test.py /tmp/test.py |
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
import time | |
import zmq | |
ctx = zmq.Context.instance() | |
radio = ctx.socket(zmq.RADIO) | |
dish = ctx.socket(zmq.DISH) | |
dish.rcvtimeo = 1_000 # 1 second timeout | |
dish.bind('udp://*:64067') | |
dish.join('1') | |
radio.connect('udp://127.0.0.1:64067') | |
for i in range(10): | |
time.sleep(0.1) | |
radio.send(f'{i:03}'.encode('ascii'), group='1') | |
msg = dish.recv_string() | |
print("received", msg) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment