2
我有以下连接设置,这工作正常。这是侦听(在一个空闲端口)传入消息的更大代码的一部分。我试图做的是发布uri,以便其他客户端可以连接到此。但是我找不出一个方法让endpoint.address()显示为所用接口上的实际IP地址,而不是“localhost”。有任何想法吗?获取公共IP地址而不是本地主机(升压阿西欧)
tcp::resolver::query query(address, "");
tcp:: endpoint endpoint = *resolver.resolve(query);
acc.open(endp.protocol());
acc.set_option(reuse_address(true));
acc.bind(endp);
acc.listen();
tcp::endpoint endpoint = acc.local_endpoint() ;
string uri = "tcp://" + endpoint.address().to_string() + ":" + lexical_cast<string>(endpoint.port()) ;
你的意思是你的PC或路由器的公网地址的LAN地址? – Wutz
你的WAN访问配置是什么样的? – bobah
我无法对如何配置WAN访问进行假设,这必须非常一般。我需要找到一种方法来推断公共地址,通过这个地址,其他主机可以将数据包发送给这个接受者 – user1018513