0MQ - 获取消息ip [英] 0MQ - get message ip

查看:32
本文介绍了0MQ - 获取消息ip的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先,我要感谢这个惊人的库!我喜欢它.客户端将自己连接到服务器.服务器应该保存 IP 并稍后对其进行处理(我真的需要 IP).我找到了答案:http://lists.zeromq.org/pipermail/zeromq-dev/2010-September/006381.html 但我不明白如何从消息中获取 IP(XREP)...我想我只能读取 ID,但IP由0MQ内部管理.他的第二个解决方案建议将 IP 作为消息的一部分发送,但我不明白如何获取公共"-IP.我找到了那个帖子:在 ZeroMQ 中获取 TCP 地址信息

First, I want to give thanks for that amazing lib! I love it. A client is connecting himself to a server. The server should save the IP and do stuff with it later on (I really need the IP). I found that answer: http://lists.zeromq.org/pipermail/zeromq-dev/2010-September/006381.html but I don't understand how I get the IP out of the message (a XREP)... I think I am only able to read the ID, but the IP is managed internally by 0MQ. His second solution suggests to send the IP as part of the message, but I don't understand how to get the "public"-IP. I found that post: Get TCP address information in ZeroMQ

 is pass bind a service to an ephemeral port, get a full connection endpoint ("tcp://ipaddress:port")

我不明白这是如何工作的.他的意思是像网络服务吗?在我看来,最好从 0MQ 中获取 IP(它已经有了 IP).我什至会为此调整 0MQ,如果有人可以指出保存 IP 的地方,找不到它.目前,套接字类型并不那么重要.我更喜欢 REQ-REP 之类的.谢谢!

I don't get how this works. Does he mean something like a web-service? In my opinion, it would be best to get the IP out of 0MQ (it has the IP already). I would even adjust 0MQ for that, if somebody could point to the place where the IP is saved, couldn't find it. The socket types are not that important, at the moment. I would prefer smth REQ-REP like. Thank you!

推荐答案

总结:

TL;DR 对您的问题的回答是:您无法使用 ZeroMQ API 获取发送消息的对等方的 IP 地址.

TL;DR answer to your question is: you can't get IP address of the peer that sent a message, using ZeroMQ API.

说明:

ZeroMQ 不公开对等 IP 地址,因为它与 ZeroMQ 设计用于基于消息的通信无关.当 ZeroMQ 可以获取连接到 服务器客户端 的 IP 地址时(在示例中使用描述的方法 这里),没用.这里更详细的解释是它如何在 ZeroMQ 和任何其他服务器实现中工作.

ZeroMQ does not expose peer IP address because it is irrelevant for the message based communication that ZeroMQ is designed for. When it is possible for ZeroMQ to get IP address of client that is connecting to server (in example using method described here), it is useless. For a longer explanation here is how it works inside ZeroMQ and any other server implementation.

服务器端不通过将 IP 映射到客户端的哈希表来处理连接的客户端,而是通过跟踪连接的套接字"(socket描述符) - 当服务器接受(使用 accept())连接时,它从操作系统套接字接收描述符以用于与连接的对等方进行通信.服务器所要做的就是保留该描述符以便从该客户端读取()和向该客户端写入().连接到服务器的另一个客户端接收另一个套接字描述符.

Server side of the connection does not handle connected clients by the means of the hashtable that maps IP to client, but by keeping track of connected "sockets" (socket descriptors) - when a server accepts (using accept()) a connection, it receives from operating system socket descriptor to use to communicate with connected peer. All server has to do is keep that descriptor around to read() from and write() to that client. Another client that connects to server receives another socket descriptor.

总结:即使ZeroMQ能够为您提供连接对等点的IP,您也不应该依赖它.ZeroMQ 对您的连接管理隐藏,因此您可以专注于消息传递.连接管理包括重新连接,这可能会导致 IP 发生变化,而不会更改另一端实际连接的 ZeroMQ 套接字.

To summarize: even if ZeroMQ would be able to provide you with IP of connected peer, you should not depend on it. ZeroMQ hides from you connection management so you can focus on messaging. Connection management includes reconnections, which may result in a change of IP without changing the actual ZeroMQ socket connected on the other side.

这篇关于0MQ - 获取消息ip的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆