如何获得提振的IP编辑部地址:: ASIO ::知识产权:: TCP ::插座? [英] How to get IP addresss of boost::asio::ip::tcp::socket?

查看:139
本文介绍了如何获得提振的IP编辑部地址:: ASIO ::知识产权:: TCP ::插座?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写在C ++中使用Boost ASIO库的服务器。我想获得客户端的IP串重新presentation在我的服务器的日志中显示。有谁知道该怎么办呢?

I'm writing a server in C++ using Boost ASIO library. I'd like to get the string representation of client IP to be shown in my server's logs. Does anyone know how to do it?

推荐答案

插座有将检索远程端点的功能。我给的命令这个(长ISH)链中去,他们应该获取字符串重新对端IP地址presentation:

The socket has a function that will retrieve the remote endpoint. I'd give this (long-ish) chain of commands a go, they should retrieve the string representation of the remote end IP address:

asio::ip::tcp::socket socket(io_service);
// Do all your accepting and other stuff here.

asio::ip::tcp::endpoint remote_ep = socket.remote_endpoint();
asio::ip::address remote_ad = remote_ep.address();
std::string s = remote_ad.to_string();

或单行版本:

asio::ip::tcp::socket socket(io_service);
// Do all your accepting and other stuff here.

std::string s = socket.remote_endpoint().address().to_string();

这篇关于如何获得提振的IP编辑部地址:: ASIO ::知识产权:: TCP ::插座?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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