我可以将 ZeroMQ TCP/UDP 服务器与常规 BSD TCP/UDP 套接字客户端混合使用吗?

Can I mix a ZeroMQ TCP/UDP server with a regular BSD TCP/UDP socket client?

我可以启动 ZeroMQ TCP/UDP 服务器并使用常规 BSD TCP/UDP 套接字客户端与其通信吗?

我有几台机器相互通信,有些依赖于带有低级套接字客户端的库,否则很难迁移到 ZMQ。

Q : "Can I start a ZeroMQ TCP/UDP server and communicate with it using a regular BSD TCP/UDP socket client?"

A : 是的,但是...

好吧,没有什么比一个“TCP/UDP服务器”在 ZeroMQ 中。 ZeroMQ 使用高级行为原型 { PUSH/PULL | PUB/SUB | REQ/REP | ... | PAIR/PAIR },为此可以选择一个或多个(是的,一个 PUB 发送者可以将消息传递给所有 vmci:// and ipc:// and pgm:// and tcp:// SUB-agents at the same "socket"-archetype at once ) transport-classes,这是因为抽象的 transport-class 数据泵是隐藏的,但 "specialised" 处理所有隐藏的组件,底层细节——每一个都有点不同,用于服务每个特定的 transport-class 根据需要使用单独的数据泵' transport-class-具体详情:
{ inproc:// | ipc:// | tipc:// | tcp:// | pgm:// | epgm:// | norm:// | vmci:// }.


然而,有一个 "special" Socket-archetype 可能 "talk" 到非 ZeroMQ 对手方,因此可以满足需求适合你:

ZMQ_STREAM

A socket of type ZMQ_STREAM is used to send and receive TCP data from a non-ØMQ peer, when using the tcp:// transport. A ZMQ_STREAM socket can act as client and/or server, sending and/or receiving TCP data asynchronously.

When receiving TCP data, a ZMQ_STREAM socket shall prepend a message part containing the routing id of the originating peer to the message before passing it to the application. Messages received are fair-queued from among all connected peers.

When sending TCP data, a ZMQ_STREAM socket shall remove the first part of the message and use it to determine the routing id of the peer the message shall be routed to, and unroutable messages shall cause an EHOSTUNREACH or EAGAIN error.

To open a connection to a server, use the zmq_connect call, and then fetch the socket routing id using the zmq_getsockopt() call with the ZMQ_ROUTING_ID option.

To close a specific connection, send the routing id frame followed by a zero-length message.

When a connection is made, a zero-length message will be received by the application. Similarly, when the peer disconnects (or the connection is lost), a zero-length message will be received by the application.

You must send one routing id frame followed by one data frame. The ZMQ_SNDMORE flag is required for routing id frames but is ignored on data frames.

请注意传入方向上所有 ZMQ_STREAM 连接对等点的公平队列处理。

现在ZeroMQ也支持DGRAM。参见此处:zmq_udp.txt。所以除了常规的 TCP 之外还有常规的 UDP。