在ZeroMQ中获取TCP地址信息 [英] Get TCP address information in ZeroMQ

查看:116
本文介绍了在ZeroMQ中获取TCP地址信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用ZeroMQ(Java绑定,jzmq)将客户端连接到服务器,但是我非常需要TCP信息,例如客户端请求的TCP/IP地址!问题是,为了能够在网络中宣布服务,我需要获取请求的TCP地址,以便能够将客户端重定向到该服务.在这种情况下,代理是中央服务注册中心".但是,由于双方都具有ZeroMQ服务,因此我看不到检索该信息的选项.

I want to connect clients to a server using ZeroMQ (java bindings, jzmq), but I need the TCP information badly, for example the TCP/IP address of a client request! The problem is, for being able to announce a service in the network I need to grab the TCP address of a request to be able to redirect clients to that service. The broker is a central "service registry" in that case. However, having ZeroMQ services on both sides, I do not see an option to retrieve that information.

我现在要做的是使用到代理的标准套接字建立虚拟连接,建立连接后,我将抓取用于该连接的IP地址,然后再次关闭该连接.现在,已使用随机端口上的ZeroMQ套接字将已检索到的IP地址用于与其绑定.

What I do now, is to establish a dummy connection using a standard socket to the broker, after the connection is established I grab the IP address used for this connection and close the connection again. The IP address which has been retrieved is now being used for binding on it using a ZeroMQ socket on a random port.

我认为此解决方案是有史以来最丑陋的解决方案,因此:什么是解决此问题的更好解决方案?

I think this solution is the ugliest solution ever possible, so: What is a better solution to this problem?

问候.

推荐答案

0MQ由于多种原因未提供对等方的地址.它也不是那么有用,因为您真正想要的是端点在其上接收连接,而不是在其上建立连接的地址.

0MQ doesn't provide the address of peers, for a number of reasons. It's also not that useful since what you really want is the endpoint to receive connections on, not the address the connection was made on.

我通常所做的并且足够优雅的方法是将服务绑定到临时端口,获取完整的连接端点("tcp://ipaddress:port")并以某种方式发送该字符串,或者广播到对等,中央注册表等,以及我的服务名称.然后,想要重新连接的对等方可以获取服务名称,查找以找到我的端点,然后再重新连接到我.

What I usually do, and it's elegant enough, is pass bind a service to an ephemeral port, get a full connection endpoint ("tcp://ipaddress:port") and send that string in some way, either broadcast to peers, to a central registry, etc. along with my service name. Then, peers who want to connect back can take the service name, look up to find my endpoint, and connect back to me.

这篇关于在ZeroMQ中获取TCP地址信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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