python - 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
你知道有什么问题吗?
解决方案
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://
transport 只能与ZMQ_RADIO
和ZMQ_DISH
socket 类型一起使用。
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+ 或更早版本)。
推荐阅读
- javascript - 如何快速将剪贴板的内容粘贴到 Chrome 开发控制台中的变量中?
- listview - Firemonkey Listview 动态外观图片 LoadFromFile
- cakephp - Cakephp 4.0 中的validationDefault 声明
- migration - 是否可以编写一个删除一列的 Sqitch 更改,而不会使 sqitch verify 永远失败?
- java - 从 JSON 字符串中删除元素
- python-3.x - 使用动态整数进行循环分页
- javascript - 几秒钟后手风琴项目消失
- mysql - MySQL 检查数据是否存在
- php - 尝试执行 PHP 请求时出现 Google Webmaster Tool API 错误
- python - 运行更新时的Python Sqlite3 OperationalError