问题描述
我正在使用pub/sub套接字,当前服务器订阅字节[0](所有主题)而客户端订阅字节[16]-将特定标头作为主题
I am using pub/Sub Socket and currently the server subscribe byte[0] (all topics)while client subscribe byte[16] - a specific header as topic
但是,我无法停止客户端订阅可以接收所有其他消息的字节[0].
However, I cannot stop client to subscribe byte[0] which can receive all other messages.
我的应用程序就像一个应用程序游戏,它具有一个使用ZMQ作为连接的单个服务器而且许多客户端都有一个ZMQ套接字与服务器通信.
My application is a like a app game which has one single server using ZMQ as connectionand many clients have a ZMQ sockets to talk with server.
在这种情况下,我应该使用哪种模式或插槽?
What pattern or socket I should use in this case?
谢谢
推荐答案
"... 无法停止客户端以订阅字节[0],该字节可以接收所有其他消息. "
" ... cannot stop client to subscribe byte[0] which can receive all other messages."
对于ZMQ PUB
/ SUB
正式通信模式原型, SUB
客户必须提交其订阅请求(通过zmq_setsockopt()
).
For the ZMQ PUB
/SUB
Formal Communication Pattern archetype, the SUB
client has to submit it's subscription request ( via zmq_setsockopt()
).
PUB
-一侧(游戏服务器)没有选择从其一侧进行操作.
PUB
-side ( a Game Server ) has got no option to do that from it's side.
在创建新的SUB
套接字时没有订阅状态,因此是绝对限制性的过滤器,因此不会传递任何消息. (有关以下SUBSCRIBE
/UNSUBSCRIBE
引用方法的详细信息,请参见
There is no-subscription state right on a creation of a new SUB
socket, thus an absolutely restrictive filter, thas no message pass through. ( For furhter details on methods for SUBSCRIBE
/ UNSUBSCRIBE
ref. below )
int zmq_setsockopt ( void *socket,
int option_name,
const void *option_value,
size_t option_len
);
Caution: only ZMQ_SUBSCRIBE
ZMQ_UNSUBSCRIBE
ZMQ_LINGER
take effect immediately,
other options are active only for subsequent socket bind/connects.
ZMQ_SUBSCRIBE
:建立邮件过滤器
ZMQ_SUBSCRIBE
选项应在ZMQ_SUB
套接字上建立一个新的消息过滤器.新创建的ZMQ_SUB
套接字将过滤掉所有传入的消息,因此您应该调用此选项以建立初始消息过滤器.
The ZMQ_SUBSCRIBE
option shall establish a new message filter on a ZMQ_SUB
socket. Newly created ZMQ_SUB
sockets shall filter out all incoming messages, therefore you should call this option to establish an initial message filter.
长度为零的空 option_value
将预订所有传入消息.
An empty option_value
of length zero shall subscribe to all incoming messages.
非空 option_value
必须预订所有带有指定前缀的开始消息.
A non-empty option_value
shall subscribe to all messages beginning with the specified prefix.
可以在单个ZMQ_SUB
套接字上附加多个过滤器,在这种情况下,如果消息与至少一个过滤器匹配,则应接受该消息.
Multiple filters may be attached to a single ZMQ_SUB
socket, in which case a message shall be accepted if it matches at least one filter.
ZMQ_UNSUBSCRIBE
:删除邮件过滤器
ZMQ_UNSUBSCRIBE
选项应删除ZMQ_SUB
套接字上的现有消息过滤器.指定的过滤器必须匹配,该过滤器是先前使用ZMQ_SUBSCRIBE
选项建立的现有过滤器.如果套接字具有连接同一过滤器的多个实例,则ZMQ_UNSUBSCRIBE
选项应仅删除一个实例,其余实例保持原位并起作用.
The ZMQ_UNSUBSCRIBE
option shall remove an existing message filter on a ZMQ_SUB
socket. The filter specified must match an existing filter previously established with the ZMQ_SUBSCRIBE
option. If the socket has several instances of the same filter attached the ZMQ_UNSUBSCRIBE
option shall remove only one instance, leaving the rest in place and functional.
可以通过扩展消息传递层并添加控制模式套接字来实现,该套接字将承载服务器启动的客户端ZMQ_SUB
消息过滤设置.
This is possible via extending the messaging layer and adding a control-mode socket, that will carry server-initiated settings for the client ZMQ_SUB
messages filtering.
ZMQ_SUB
客户端代码在收到服务器指定的新的ZMQ_SUBSCRIBE
/ZMQ_UNSUBSCRIBE
设置后,将简单地处理该请求并相应地添加zmq_setsockopt()
.
Upon receiving a new, the server-dictated, ZMQ_SUBSCRIBE
/ZMQ_UNSUBSCRIBE
setting, the ZMQ_SUB
client side code will simply handle that request and add zmq_setsockopt()
accordingly.
这种方法由FSA驱动的语法还有很多其他的可能性,因此将允许任何Game Server/Game Community顺利地采用这种方式.
FSA-driven grammars for this approach are rich of further possibilites, so will allow any Game Server / Game Community to smoothly go this way.
ZeroMQ是一个乐高风格元素的库,可以组装成更大的图片.
ZeroMQ is rather a library of LEGO-style elements to get assembled into a bigger picture.
期望这样的智能库具有一个可以容纳所有对象的 ninja- ,这看起来更近了 oxymoron .
Expecting such a smart library to have a one-size-fits-all ninja-element is on a closer look an oxymoron.
因此,要避免"永无止境的故事"中添加",尽管这个...还有那个... "
So, to avoid a "Never-ending-story" of adding "although this ... and also that ..."
-
查看所有要求和&端到端可扩展解决方案的 list 功能
Review all requirements and & list features for the end-to-end scaleable solution,
设计消息传递概念& 验证,使其符合列出的所有要求&涵盖[1]
Design a messaging concept & validate it to meet all the listed requirements & cover all features in [1]
实施 [2]
测试 [3]& 正确,它满足1:1的端到端规范[1]
Test [3] & correct it for meeting 1:1 the end-to-end specification [1]
享受它.您已经正确完成了端到端的操作.
Enjoy it. You have done it end-to-end right.
这篇关于ZMQ可以通过pub-sub套接字将消息发布到特定客户端吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!