首页 > 解决方案 > UDP 协议在 ZeroMQ 中不起作用。应该使用哪种套接字类型?

问题描述

我尝试通过以下方式将我的PUB-client (使用pyzmq版本 19.0.0 )与服务器连接udp://

context = zmq.Context()
socket = context.socket( zmq.PUB )
socket.connect( "udp://127.0.0.1:34567" )

但是代码总是抛出一个错误:zmq.error.ZMQError: The protocol is not compatible with the socket type

我尝试了所有套接字类型,例如:REQ, REP, PUB, SUB, PAIR, DEALER, ROUTER, PULL, PUSH

你知道有什么问题吗?

标签: pythonudpzeromqpyzmq

解决方案


ZeroMQ 确实支持:
和传输UDP://{PGM|EPGM}://

的例子{ PGM | EPGM }

// Connecting to the multicast address 239.192.1.1, port 5555,
// using the first Ethernet network interface on Linux
// and the Encapsulated PGM protocol

rc = zmq_connect( socket,           "epgm://eth0;239.192.1.1:5555" );
assert ( rc == 0 and "ASSERT FAILED: epgm://eth0;239.192.1.1:5555 ............. " );

// Connecting to the multicast address 239.192.1.1, port 5555,
// using the network interface with the address 192.168.1.1
// and the standard PGM protocol

rc = zmq_connect(socket,            "pgm://192.168.1.1;239.192.1.1:5555" );
assert ( rc == 0 and "ASSERT FAILED: pgm://192.168.1.1;239.192.1.1:5555 ........" );

和传输只能与pgm://和套接字类型一起使用。epgm://ZMQ_PUBZMQ_SUB


UDP://transport 只能与ZMQ_RADIOZMQ_DISHsocket 类型一起使用。

UDP .bind(), .connect()-s 的例子类似:

// Unicast - UDP port 5555 on all available interfaces
rc = zmq_bind( dish,                "udp://*:5555" );
assert ( rc == 0 and "ASSERT FAILED: udp://*:5555 ............. " );

// Unicast - UDP port 5555 on the local loop-back interface
rc = zmq_bind( dish,                "udp://127.0.0.1:5555" );
assert ( rc == 0 and "ASSERT FAILED: udp://127.0.0.1:5555 ............. " );

// Unicast - UDP port 5555 on interface eth1
rc = zmq_bind( dish,                "udp://eth1:5555" );
assert ( rc == 0 and "ASSERT FAILED: udp://eth1:5555 ............. " );

// Multicast - UDP port 5555 on a Multicast address
rc = zmq_bind( dish,                "udp://239.0.0.1:5555" );
assert ( rc == 0 and "ASSERT FAILED: udp://239.0.0.1:5555 ............. " );

// Same as above but joining only on interface eth0
rc = zmq_bind( dish,                "udp://eth0;239.0.0.1:5555" );
assert ( rc == 0 and "ASSERT FAILED: udp://eth0;239.0.0.1:5555 ............. " );

// Same as above using IPv6 multicast
rc = zmq_bind( dish,                "udp://eth0;[ff02::1]:5555" );
assert ( rc == 0 and "ASSERT FAILED: udp://eth0;[ff02::1]:5555 ............. " );

最好的下一步:

现在查看本机 API 的实施范围和状态pyzmq-19.0.0(无论是 4.3.2+ 或更早版本)。


推荐阅读