当前位置: 动力学知识库 > 问答 > 编程问答 >

c++ - ZeroMQs router-dealer pattern. How to handle client adress?

问题描述:

I use the router-dealer pattern from 0mq. Now I want to store the clients adress. I know that the first message from the client is the adress, IP + portno i guess. Or rather recv() from the router socket puts the adress in front of a received paket. But how do I handle this adress, e.g. printing out or storing it for further outgoing messages? What type is it?

网友答案:

Here's the Guide explanation on this: http://zguide.zeromq.org/page:all#The-Request-Reply-Mechanisms

The ROUTER manages a set of connections, and keeps an 'identity' for each connection, which is a random number, like a handle. It tells you this identity on each message, as a first frame. It's a binary value, so you can't print it as-is.

The DEALER can override the ROUTER's internal identity by telling it, "use this ID" at connection time. That's what the zmq_setsockopt ZMQ_IDENTITY option does. We use this when nodes have some unique, often string, ID that has some meaning to the application.

网友答案:

the first part of the message is the identity of the sender (dealer) what you can set on the dealer side, with the zmq_setsockopt function (before connecting to the router). it's a maximum 255 char long string. if you don't set it, there will be some random unique thing, starting with #0 char.

so it's not the ip+port of your dealer by default, but you can put there that info if you like.

分享给朋友:
您可能感兴趣的文章:
随机阅读: