UDP 协议在 ZeroMQ 中不起作用。应使用哪种套接字类型?
UDP-protocol doesn't work in ZeroMQ. Which socket type should be used?
我试图通过 [=13 将我的 PUB
-客户端(使用 pyzmq
版本 19.0.0)与服务器连接=]:
context = zmq.Context()
socket = context.socket( zmq.PUB )
socket.connect( "udp://127.0.0.1:34567" )
但代码总是抛出一个错误:zmq.error.ZMQError:协议与套接字类型不兼容
我已经尝试了所有类型的套接字,例如:REQ, REP, PUB, SUB, PAIR, DEALER, ROUTER, PULL, PUSH
你知道问题出在哪里吗?
zmq一般不使用udp套接字,因为它们不可靠,唯一的udp套接字是dish
和radio
但它们是实验性的,你可以阅读更多here
相关引用:
UDP transport can only be used with the ZMQ_RADIO and ZMQ_DISH socket
types.
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_PUB
和 ZMQ_SUB
插座类型。
UDP://
传输只能用于 ZMQ_RADIO
和 ZMQ_DISH
插座类型。
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(4.3.2+ 或更早版本)的 pyzmq-19.0.0
实现的范围和状态。
我试图通过 [=13 将我的 PUB
-客户端(使用 pyzmq
版本 19.0.0)与服务器连接=]:
context = zmq.Context()
socket = context.socket( zmq.PUB )
socket.connect( "udp://127.0.0.1:34567" )
但代码总是抛出一个错误:zmq.error.ZMQError:协议与套接字类型不兼容
我已经尝试了所有类型的套接字,例如:REQ, REP, PUB, SUB, PAIR, DEALER, ROUTER, PULL, PUSH
你知道问题出在哪里吗?
zmq一般不使用udp套接字,因为它们不可靠,唯一的udp套接字是dish
和radio
但它们是实验性的,你可以阅读更多here
相关引用:
UDP transport can only be used with the ZMQ_RADIO and ZMQ_DISH socket types.
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_PUB
和 ZMQ_SUB
插座类型。
UDP://
传输只能用于 ZMQ_RADIO
和 ZMQ_DISH
插座类型。
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(4.3.2+ 或更早版本)的 pyzmq-19.0.0
实现的范围和状态。