I’m trying to setup an XPUB/XSUB to proxy traffic from epgm to a tcp loopback and I’m having some issues. For testing I did ifconfig lo 127.0.0.1 netmask 224.0.0.0 up
to allow loopback multicast. I’ve verified this works:
pub.py
import zmq
import time
import sys
c = zmq.Context()
pub = c.socket(zmq.PUB)
pub.connect(sys.argv[1])
for i in range(5):
print(f"Send {i}")
pub.send_multipart([b'test', str(i).encode()])
time.sleep(1)
sub.py
import zmq
import sys
c = zmq.Context()
sub = c.socket(zmq.SUB)
sub.connect(sys.argv[1])
sub.setsockopt(zmq.SUBSCRIBE, b'test')
val = -1
while val < 4:
val = int(sub.recv_multipart()[1])
print(f"Recv: {val}")
no forwarder, epgm
> python pub.py 'epgm://127.0.0.1;224.1.1.0:5555' & python sub.py 'epgm://127.0.0.1;224.1.1.0:5555' Wed 01 May 2024 10:51:13 AM EDT
Warn: Interface lo reports as a loopback device.
Warn: Interface lo reports as a non-multicast capable device.
Send 0
Warn: Interface lo reports as a loopback device.
Warn: Interface lo reports as a non-multicast capable device.
Warn: Interface lo reports as a loopback device.
Warn: Interface lo reports as a non-multicast capable device.
Warn: Interface lo reports as a loopback device.
Warn: Interface lo reports as a non-multicast capable device.
Send 1
Recv: 1
Send 2
Recv: 2
Send 3
Recv: 3
Send 4
Recv: 4
I create a simple forwarder..
forward.py
import zmq
import sys
c = zmq.Context()
frontend = c.socket(zmq.XSUB)
url = sys.argv[1]
frontend.bind(sys.argv[1])
backend = c.socket(zmq.XPUB)
backend.bind(sys.argv[2])
zmq.proxy(frontend, backend)
proxy, tcp sockets only
python forward.py 'tcp://127.0.0.1:5555' 'tcp://127.0.0.1:5556' & python pub.py 'tcp://127.0.0.1:5555' & python sub.py 'tcp://127.0.0.1:5556'
Send 0
Send 1
Recv: 1
Send 2
Recv: 2
Send 3
Recv: 3
Send 4
Recv: 4
Forwarding with epgm on the XSUB/PUB side works.
proxy, epgm -> tcp
python forward.py 'epgm://127.0.0.1;224.0.0.1:5555' 'tcp://127.0.0.1:5556' & python pub.py 'epgm://127.0.0.1;224.0.0.1:5555' & python sub.py 'tcp://127.0.0.1:5556'
Warn: Interface lo reports as a loopback device.
Warn: Interface lo reports as a non-multicast capable device.
Warn: Interface lo reports as a loopback device.
Warn: Interface lo reports as a non-multicast capable device.
Send 0
Warn: Interface lo reports as a loopback device.
Warn: Interface lo reports as a non-multicast capable device.
Warn: Interface lo reports as a loopback device.
Warn: Interface lo reports as a non-multicast capable device.
Send 1
Recv: 1
Send 2
Recv: 2
Send 3
Recv: 3
Send 4
Recv: 4
But the other direction doesn’t work.
proxy tcp -> epgm
python forward.py 'tcp://127.0.0.1:5555' 'epgm://127.0.0.1;224.0.0.1:5556' & python pub.py 'tcp://127.0.0.1:5555' & python sub.py 'epgm://127.0.0.1;224.0.0.1:5556'
Send 0
Warn: Interface lo reports as a loopback device.
Warn: Interface lo reports as a non-multicast capable device.
Warn: Interface lo reports as a loopback device.
Warn: Interface lo reports as a non-multicast capable device.
Warn: Interface lo reports as a loopback device.
Warn: Interface lo reports as a non-multicast capable device.
Warn: Interface lo reports as a loopback device.
Warn: Interface lo reports as a non-multicast capable device.
Send 1
Send 2
Send 3
Send 4
Any idea why this last case isn’t working?